@@ -33,7 +33,15 @@ impl From<SfuPublishRequest> for proto::PublishDataTrackRequest {
3333 fn from ( event : SfuPublishRequest ) -> Self {
3434 use proto:: encryption:: Type ;
3535 let encryption = if event. uses_e2ee { Type :: Gcm } else { Type :: None } . into ( ) ;
36- Self { pub_handle : event. handle . into ( ) , name : event. name , encryption }
36+ let schema = event. schema . map ( Into :: into) ;
37+ let frame_encoding = event. frame_encoding . map ( Into :: into) ;
38+ Self {
39+ pub_handle : event. handle . into ( ) ,
40+ name : event. name ,
41+ encryption,
42+ schema,
43+ frame_encoding,
44+ }
3745 }
3846}
3947
@@ -74,8 +82,18 @@ impl TryFrom<proto::DataTrackInfo> for DataTrackInfo {
7482 proto:: encryption:: Type :: Gcm => true ,
7583 other => Err ( anyhow ! ( "Unsupported E2EE type: {:?}" , other) ) ?,
7684 } ;
85+ let frame_encoding = msg. frame_encoding . map ( Into :: into) ;
7786 let sid: DataTrackSid = msg. sid . try_into ( ) . map_err ( anyhow:: Error :: from) ?;
78- Ok ( Self { pub_handle : handle, sid : RwLock :: new ( sid) . into ( ) , name : msg. name , uses_e2ee } )
87+ let schema = msg. schema . map ( |schema| schema. into ( ) ) ;
88+
89+ Ok ( Self {
90+ pub_handle : handle,
91+ sid : RwLock :: new ( sid) . into ( ) ,
92+ name : msg. name ,
93+ uses_e2ee,
94+ schema,
95+ frame_encoding,
96+ } )
7997 }
8098}
8199
@@ -106,12 +124,17 @@ impl From<DataTrackInfo> for proto::DataTrackInfo {
106124 proto:: encryption:: Type :: Gcm
107125 } else {
108126 proto:: encryption:: Type :: None
109- } ;
127+ } as i32 ;
128+ let sid = info. sid ( ) . to_string ( ) ;
129+ let schema = info. schema . map ( |schema| schema. into ( ) ) ;
130+ let frame_encoding = info. frame_encoding . map ( Into :: into) ;
110131 Self {
111132 pub_handle : info. pub_handle . into ( ) ,
112- sid : info . sid ( ) . to_string ( ) ,
133+ sid,
113134 name : info. name ,
114- encryption : encryption as i32 ,
135+ encryption,
136+ schema,
137+ frame_encoding,
115138 }
116139 }
117140}
@@ -128,6 +151,8 @@ pub fn publish_responses_for_sync_state(
128151
129152#[ cfg( test) ]
130153mod tests {
154+ use crate :: schema:: { DataTrackFrameEncoding , DataTrackSchemaEncoding , DataTrackSchemaId } ;
155+
131156 use super :: * ;
132157 use fake:: { Fake , Faker } ;
133158
@@ -137,6 +162,8 @@ mod tests {
137162 handle : 1u32 . try_into ( ) . unwrap ( ) ,
138163 name : "track" . into ( ) ,
139164 uses_e2ee : true ,
165+ schema : None ,
166+ frame_encoding : None ,
140167 } ;
141168 let request: proto:: PublishDataTrackRequest = event. into ( ) ;
142169 assert_eq ! ( request. pub_handle, 1 ) ;
@@ -159,6 +186,12 @@ mod tests {
159186 sid : "DTR_1234" . into ( ) ,
160187 name : "track" . into ( ) ,
161188 encryption : proto:: encryption:: Type :: Gcm . into ( ) ,
189+ schema : proto:: DataTrackSchemaId {
190+ name : "schema" . into ( ) ,
191+ encoding : Some ( DataTrackSchemaEncoding :: JsonSchema . into ( ) ) ,
192+ }
193+ . into ( ) ,
194+ frame_encoding : Some ( DataTrackFrameEncoding :: Json . into ( ) ) ,
162195 }
163196 . into ( ) ,
164197 } ;
@@ -169,9 +202,43 @@ mod tests {
169202 assert_eq ! ( info. pub_handle, 1u32 . try_into( ) . unwrap( ) ) ;
170203 assert_eq ! ( * info. sid. read( ) . unwrap( ) , "DTR_1234" . to_string( ) . try_into( ) . unwrap( ) ) ;
171204 assert_eq ! ( info. name, "track" ) ;
205+ assert_eq ! (
206+ info. schema,
207+ Some ( DataTrackSchemaId :: new( "schema" , DataTrackSchemaEncoding :: JsonSchema ) )
208+ ) ;
209+ assert_eq ! ( info. frame_encoding, Some ( DataTrackFrameEncoding :: Json ) ) ;
172210 assert ! ( info. uses_e2ee) ;
173211 }
174212
213+ #[ test]
214+ fn test_frame_encoding_mapping ( ) {
215+ let base = proto:: DataTrackInfo {
216+ pub_handle : 1 ,
217+ sid : "DTR_1234" . into ( ) ,
218+ name : "track" . into ( ) ,
219+ encryption : proto:: encryption:: Type :: None . into ( ) ,
220+ schema : None ,
221+ frame_encoding : None ,
222+ } ;
223+
224+ let info: DataTrackInfo = base. clone ( ) . try_into ( ) . unwrap ( ) ;
225+ assert_eq ! ( info. frame_encoding, None ) ;
226+
227+ let unspecified = proto:: DataTrackInfo {
228+ frame_encoding : Some ( DataTrackFrameEncoding :: Other . into ( ) ) ,
229+ ..base. clone ( )
230+ } ;
231+ let info: DataTrackInfo = unspecified. try_into ( ) . unwrap ( ) ;
232+ assert_eq ! ( info. frame_encoding, Some ( DataTrackFrameEncoding :: Other ) ) ;
233+
234+ let custom = proto:: DataTrackInfo {
235+ frame_encoding : Some ( DataTrackFrameEncoding :: Custom ( "my_encoding" . into ( ) ) . into ( ) ) ,
236+ ..base
237+ } ;
238+ let info: DataTrackInfo = custom. try_into ( ) . unwrap ( ) ;
239+ assert_eq ! ( info. frame_encoding, Some ( DataTrackFrameEncoding :: Custom ( "my_encoding" . into( ) ) ) ) ;
240+ }
241+
175242 #[ test]
176243 fn test_from_request_response ( ) {
177244 use proto:: request_response:: { Reason , Request } ;
0 commit comments