Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit 23850c6

Browse files
committed
Use enum for json serialization as well
1 parent b392f4b commit 23850c6

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

sendrecv/gst-rust/src/main.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ extern crate rand;
99
extern crate serde;
1010
#[macro_use]
1111
extern crate serde_derive;
12-
#[macro_use]
1312
extern crate serde_json;
1413
extern crate websocket;
1514
#[macro_use]
@@ -152,12 +151,10 @@ fn send_sdp_offer(app_control: &AppControl, offer: gst_webrtc::WebRTCSessionDesc
152151
) {
153152
return;
154153
}
155-
let message = json!({
156-
"sdp": {
157-
"type": "offer",
158-
"sdp": offer.get_sdp().as_text(),
159-
}
160-
});
154+
let message = serde_json::to_string(&JsonMsg::Sdp {
155+
type_: "offer".to_string(),
156+
sdp: offer.get_sdp().as_text().unwrap(),
157+
}).unwrap();
161158
app_control.send_text_msg(message.to_string());
162159
}
163160

@@ -297,16 +294,13 @@ fn send_ice_candidate_message(app_control: &AppControl, values: &[glib::Value])
297294
if !app_control.app_state_lt(AppState::PeerCallNegotiating, "Can't send ICE, not in call") {
298295
return;
299296
}
300-
301297
let _webrtc = values[0].get::<gst::Element>().expect("Invalid argument");
302298
let mlineindex = values[1].get::<u32>().expect("Invalid argument");
303299
let candidate = values[2].get::<String>().expect("Invalid argument");
304-
let message = json!({
305-
"ice": {
306-
"candidate": candidate,
307-
"sdpMLineIndex": mlineindex,
308-
}
309-
});
300+
let message = serde_json::to_string(&JsonMsg::Ice {
301+
candidate: candidate,
302+
sdp_mline_index: mlineindex,
303+
}).unwrap();
310304
app_control.send_text_msg(message.to_string());
311305
}
312306

0 commit comments

Comments
 (0)