public async Task <JanusJsonObject> SendCandidate(string sdpMid, int sdpMlineIndex, string sdp) { JanusJsonObject retVal = null; try { var jsonObject = new JanusJsonObject() { janus = Commands.TrickleCommand, transaction = Guid.NewGuid().ToString(), candidate = new Dictionary <string, object> { { "candidate", sdp }, { "sdpMLineIndex", sdpMlineIndex }, { "sdpMid", sdpMid } } }; using (var httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5000) }) { var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, MediaType); var result = await httpClient.PostAsync(JanusHostSessionHandleEndPoint, content); if (result.StatusCode == System.Net.HttpStatusCode.OK) { var body = await result.Content.ReadAsStringAsync(); retVal = JsonConvert.DeserializeObject <JanusJsonObject>(body.ToString()); } } } catch (Exception) { } return(retVal); }
///<summary> ///Starting point of destroying session ///</summary> public async Task <JanusJsonObject> DestroySession() { JanusJsonObject retVal = null; try { var jsonObject = new JanusJsonObject() { janus = Commands.DestroyCommand, transaction = Guid.NewGuid().ToString(), }; using (var httpClient = new HttpClient()) { var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, MediaType); var result = await httpClient.PostAsync(JanusHost, content); if (result.StatusCode == System.Net.HttpStatusCode.OK) { var body = await result.Content.ReadAsStringAsync(); retVal = JsonConvert.DeserializeObject <JanusJsonObject>(body.ToString()); } } return(retVal); }catch (Exception) { return(retVal); } }
public async Task <JanusJsonObject> PollingEventMessage() { JanusJsonObject retVal = null; try { var jsonObject = new JanusJsonObject() { janus = Commands.MessageCommand, sender = SessionId, transaction = Guid.NewGuid().ToString() }; using (var httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5000) }) { var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, MediaType); var result = await httpClient.GetAsync(string.Format("{0}{1}", JanusHost, SessionId)); if (result.StatusCode == System.Net.HttpStatusCode.OK) { var body = await result.Content.ReadAsStringAsync(); retVal = JsonConvert.DeserializeObject <JanusJsonObject>(body.ToString()); } } } catch (Exception ex) { Console.WriteLine(ex); } return(retVal); }
public async Task <JanusJsonObject> RegisterRoom() { JanusJsonObject retVal = null; try { var jsonObject = new JanusJsonObject() { janus = Commands.MessageCommand, transaction = Guid.NewGuid().ToString(), body = new Dictionary <string, object> { { "request", "join" }, { "room", RoomId }, { "ptype", "publisher" }, { "display", RoomUserName } } }; using (var httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5000) }) { var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, MediaType); var result = await httpClient.PostAsync(JanusHostSessionHandleEndPoint, content); if (result.StatusCode == System.Net.HttpStatusCode.OK) { var body = await result.Content.ReadAsStringAsync(); retVal = JsonConvert.DeserializeObject <JanusJsonObject>(body.ToString()); } } } catch (Exception) { } return(retVal); }
///<summary> ///Starting point of Attaching session ///</summary> public async Task <JanusJsonObject> AttachSession() { JanusJsonObject retVal = null; try { var jsonObject = new JanusJsonObject() { janus = Commands.AttachCommand, transaction = Guid.NewGuid().ToString(), plugin = PluginName, //opaqueId = OpaqueId }; using (var httpClient = new HttpClient()) { var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, MediaType); var result = await httpClient.PostAsync(JanusHostSessionEndPoint, content); if (result.StatusCode == System.Net.HttpStatusCode.OK) { var body = await result.Content.ReadAsStringAsync(); retVal = JsonConvert.DeserializeObject <JanusJsonObject>(body.ToString()); long.TryParse(retVal.data["id"], out HandleId); } } return(retVal); }catch (Exception) { return(retVal); } }
/// <summary> /// start the session /// </summary> public async Task <JanusJsonObject> CreateSession() { JanusJsonObject retVal = null; try { var jsonObject = new JanusJsonObject() { janus = Commands.CreateCommand, transaction = Guid.NewGuid().ToString() }; using (var httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5000) }) { var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, MediaType); var result = await httpClient.PostAsync(JanusHost, content); if (result.StatusCode == System.Net.HttpStatusCode.OK) { var body = await result.Content.ReadAsStringAsync(); retVal = JsonConvert.DeserializeObject <JanusJsonObject>(body.ToString()); long.TryParse(retVal.data["id"], out SessionId); } } }catch (Exception ex) { Console.WriteLine(ex); } return(retVal); }
private void _pollingWorker_DoWork(object sender, DoWorkEventArgs e) { // WebRTCServer webrtcserver=new WebRTCServer(); while (!_pollingWorker.CancellationPending) { try { if (SessionId != long.MinValue) { JanusJsonObject jsonObj = null; var task = PollingEventMessage(); task.Wait(6000); jsonObj = task.Result; if (jsonObj != null) { if (jsonObj.janus == Commands.KeepAliveCommand) { Console.WriteLine("Keep alive"); } else { try { OnPollingMessageReceived(jsonObj); } catch (Exception ex) { Console.WriteLine(ex); } } } } Thread.Sleep(100); } catch (Exception ex) { } } }
public async Task <JanusJsonObject> CreateOffer(string sdp, audioDevice aud, videoDevice vid) { JanusJsonObject retVal = null; //Dictionary<string,object> video = new Dictionary<string,object > { { "width",resolution },{"height",resolution } }; try { var jsonObject = new JanusJsonObject() { janus = Commands.MessageCommand, transaction = Guid.NewGuid().ToString(), body = new Dictionary <string, object> { { "request", "configure" }, { "audio", aud.audio }, { "video", vid.video }, { "deviceId", vid.deviceId } }, jsep = new Dictionary <string, string> { { "type", "offer" }, { "sdp", sdp.ToString() } } }; using (var httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5000) }) { var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, MediaType); var result = await httpClient.PostAsync(JanusHostSessionHandleEndPoint, content); if (result.StatusCode == System.Net.HttpStatusCode.OK) { var body = await result.Content.ReadAsStringAsync(); retVal = JsonConvert.DeserializeObject <JanusJsonObject>(body.ToString()); } } } catch (Exception) { } return(retVal); }
public async Task <JanusJsonObject> CreateAnswer(bool audioSend, bool videoSend) { JanusJsonObject retVal = null; try { var jsonObject = new JanusJsonObject() { janus = Commands.MessageCommand, transaction = Guid.NewGuid().ToString(), body = new Dictionary <string, object> { { "request", "start" }, { "room", RoomId } }, jsep = new Dictionary <string, string> { { "type", "answer" } } // Resolution = resolution }; using (var httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5000) }) { var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, MediaType); var result = await httpClient.PostAsync(JanusHostSessionHandleEndPoint, content); if (result.StatusCode == System.Net.HttpStatusCode.OK) { var body = await result.Content.ReadAsStringAsync(); retVal = JsonConvert.DeserializeObject <JanusJsonObject>(body.ToString()); } } } catch (Exception) { } return(retVal); }