public static MyMsrpSession TakeIncomingSession(MySipStack sipStack, MsrpSession session, SipMessage message) { MyMsrpSession msrpSession = null; MediaType mediaType; SdpMessage sdp = message.getSdpMessage(); String fromUri = message.getSipHeaderValue("f"); if (String.IsNullOrEmpty(fromUri)) { LOG.Error("Invalid fromUri"); return(null); } if (sdp == null) { LOG.Error("Invalid Sdp content"); return(null); } String fileSelector = sdp.getSdpHeaderAValue("message", "file-selector"); mediaType = String.IsNullOrEmpty(fileSelector) ? MediaType.Chat : MediaType.FileTransfer; if (mediaType == MediaType.Chat) { msrpSession = MyMsrpSession.CreateIncomingSession(sipStack, session, mediaType, fromUri); } else { String name = null; String type = null; String[] attributes = fileSelector.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (String attribute in attributes) { String[] avp = attribute.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (avp.Length >= 2) { if (String.Equals(avp[0], "name", StringComparison.InvariantCultureIgnoreCase) && avp[1] != null) { name = avp[1].Replace("\"", String.Empty); } if (String.Equals(avp[0], "type", StringComparison.InvariantCultureIgnoreCase) && avp[1] != null) { type = avp[1]; } } } if (name == null) { LOG.Error("Invalid file name"); return(null); } msrpSession = MyMsrpSession.CreateIncomingSession(sipStack, session, mediaType, fromUri); msrpSession.filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), String.Format("{0}/{1}", MyMsrpSession.DESTINATION_FOLDER, name)); msrpSession.fileType = type; } return(msrpSession); }
public async Task SdpMessageSendConfigurationWebRtc(string userName, SdpMessage message) { string connectionId = _sessionService.GetConnectionIdByUserName(userName); string userNameCurrent = _sessionService.GetUserNameByConnectionId(Context.ConnectionId); await Clients.Client(connectionId).SdpMessageReceivedConfigurationWebRtc(userNameCurrent, message); }
public async Task SetRemoteDescription_Invalid() { const string kDummyMessage = "v=0\r\n" + "o=- 496134922022744986 2 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + "t=0 0\r\n" + "a=group:BUNDLE 0\r\n" + "a=msid-semantic: WMS\r\n" + "m=application 9 DTLS/SCTP 5000\r\n" + "c=IN IP4 0.0.0.0\r\n" + "a=setup:actpass\r\n" + "a=mid:0\r\n" + "a=sctpmap:5000 webrtc-datachannel 1024\r\n"; using (var pc = new PeerConnection()) { await pc.InitializeAsync(); // Set answer without offer; SRD task enqueued, but fails when executing var message = new SdpMessage { Type = SdpMessageType.Answer, Content = kDummyMessage }; Assert.CatchAsync <InvalidOperationException>(async() => await pc.SetRemoteDescriptionAsync(message)); } }
private void PeerConnection_LocalSdpReadytoSend(SdpMessage message) { // See ProcessIncomingMessages() for the message format string typeStr = SdpMessage.TypeToString(message.Type); SendMessage($"sdp\n{typeStr}\n{message.Content}\n\n"); }
/// <summary> /// Entry point for the reading task which read incoming messages from the /// receiving pipe and dispatch them through events to the WebRTC peer. /// </summary> private void ProcessIncomingMessages() { // ReadLine() will block while waiting for a new line string line; while ((line = _recvStream.ReadLine()) != null) { Console.WriteLine($"[<-] {line}"); if (line == "ice") { string sdpMid = _recvStream.ReadLine(); int sdpMlineindex = int.Parse(_recvStream.ReadLine()); // The ICE candidate is a multi-line field, ends with an empty line string candidate = ""; while ((line = _recvStream.ReadLine()) != null) { if (line.Length == 0) { break; } candidate += line; candidate += "\n"; } Console.WriteLine($"[<-] ICE candidate: {sdpMid} {sdpMlineindex} {candidate}"); var iceCandidate = new IceCandidate { SdpMid = sdpMid, SdpMlineIndex = sdpMlineindex, Content = candidate }; IceCandidateReceived?.Invoke(iceCandidate); } else if (line == "sdp") { string type = _recvStream.ReadLine(); // The SDP message content is a multi-line field, ends with an empty line string sdp = ""; while ((line = _recvStream.ReadLine()) != null) { if (line.Length == 0) { break; } sdp += line; sdp += "\n"; } Console.WriteLine($"[<-] SDP message: {type} {sdp}"); var message = new SdpMessage { Type = SdpMessage.StringToType(type), Content = sdp }; SdpMessageReceived?.Invoke(message); } } Console.WriteLine("Finished processing messages"); }
/// <summary> /// Apply a remote SDP answer message to the peer connection. /// </summary> /// <param name="content">The SDP answer message content.</param> public async Task ApplyRemoteAnswerAsync(string content) { var message = new SdpMessage { Type = SdpMessageType.Answer, Content = content }; await _peerConnection.SetRemoteDescriptionAsync(message); ExchangeNegotiationState(NegotiationState.HaveLocalOffer, NegotiationState.Stable); }
public override Task SendMessageAsync(SdpMessage message) { JSONObject payload = new JSONObject(); string type = message.Type.ToString().ToLower(); payload.AddField("type", type); payload.AddField("sdp", message.Content.Replace("\r\n", "\\r\\n")); return(SendIOMessage(type, payload)); }
/// <summary> /// Create a node-dss message from an existing SDP offer or answer message. /// </summary> /// <param name="message">The SDP message to serialize.</param> /// <returns>The newly create node-dss message containing the serialized SDP message. public static Message FromSdpMessage(SdpMessage message) { return(new Message { MessageType = TypeFromSdpMessageType(message.Type), Data = message.Content, IceDataSeparator = "|" }); }
/// <summary> /// Helper to split SDP offer and answer messages and dispatch to the appropriate handler. /// </summary> /// <param name="message">The SDP message ready to be sent to the remote peer.</param> private void OnLocalSdpReadyToSend_Listener(SdpMessage message) { if (message.Type == SdpMessageType.Offer) { _mainThreadWorkQueue.Enqueue(() => OnSdpOfferReadyToSend(message)); } else if (message.Type == SdpMessageType.Answer) { _mainThreadWorkQueue.Enqueue(() => OnSdpAnswerReadyToSend(message)); } }
/// <summary> /// Apply a remote SDP offer message to the peer connection. /// </summary> /// <param name="content">The SDP offer message content.</param> public async Task ApplyRemoteOfferAsync(string content) { // Change state first to prevent user from initiating a new negotiation // while the remote peer is known to have already initiated one. // This slightly deviates from the WebRTC standard which says that the // HaveRemoteOffer state is after the remote offer was applied, not before. ExchangeNegotiationState(NegotiationState.Stable, NegotiationState.HaveRemoteOffer); var message = new SdpMessage { Type = SdpMessageType.Offer, Content = content }; await _peerConnection.SetRemoteDescriptionAsync(message); }
private void LocalSdpReadytoSend(SdpMessage message) { Dictionary <string, string> outMessage = new Dictionary <string, string> { { "type", SdpMessage.TypeToString(message.Type) }, { "sdp", message.Content } }; string serializedMessage = JsonConvert.SerializeObject(outMessage); SendMessage(serializedMessage); }
private IEnumerator SdpAnswer() { yield return(new WaitForSeconds(1f)); _mainThreadWorkQueue.Enqueue(() => { PeerConnection.HandleConnectionMessageAsync(sdpAnswerReceiveVideo).ContinueWith(_ => { _nativePeer.CreateAnswer(); sdpAnswerReceiveVideo = null; }, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.RunContinuationsAsynchronously); }); }
public void Execute(StringTokenizer reader, SdpMessage message) { var time = new SdpTimings(); time.AddFieldValue(GetFieldValuePair(reader)); while (reader.Length > 0) { var type = reader.ReadPeekChar(); if (type == 't') time.AddFieldValue(GetFieldValuePair(reader)); else if (type == 'z') time.AddFieldValue(GetFieldValuePair(reader)); else break; } message.Times.Add(time); }
public SdpMessage Parse(string message) { var sdpMessage = new SdpMessage(); var stringTokenizer = new StringTokenizer(message); while(stringTokenizer.Length > 0) { ISdpParseCommand command; if (commands.TryGetValue(stringTokenizer.ReadPeekChar(), out command)) command.Execute(stringTokenizer, sdpMessage); } return sdpMessage; }
public async Task SetRemoteDescription_Null() { using (var pc = new PeerConnection()) { await pc.InitializeAsync(); // Invalid arguments; SRD not even enqueued, fails immediately while validating arguments var message = new SdpMessage { Type = SdpMessageType.Offer, Content = null }; Assert.ThrowsAsync <ArgumentException>(async() => await pc.SetRemoteDescriptionAsync(message)); message.Content = ""; Assert.ThrowsAsync <ArgumentException>(async() => await pc.SetRemoteDescriptionAsync(message)); } }
private void OnMessage(SocketIOEvent ev) { string from = GetString(ev.data, "from"); remotePeerId = from; string type = GetString(ev.data, "type"); //Debug.Log($"socket received {type} from {from}"); JSONObject payload = null; if (type != "init") { payload = ev.data["payload"]; } Debug.Log(ev.data); switch (type) { case "init": _ = PeerConnection.StartConnection(); break; case "offer": var sdpOffer = new SdpMessage { Type = SdpMessageType.Offer, Content = GetString(payload, "sdp").Replace("\\r\\n", "\r\n") }; PeerConnection.HandleConnectionMessageAsync(sdpOffer).ContinueWith(_ => { _nativePeer.CreateAnswer(); }, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.RunContinuationsAsynchronously); break; case "answer": var sdpAnswer = new SdpMessage { Type = SdpMessageType.Answer, Content = GetString(payload, "sdp").Replace("\\r\\n", "\r\n") }; _ = PeerConnection.HandleConnectionMessageAsync(sdpAnswer); break; case "candidate": _nativePeer.AddIceCandidate(new IceCandidate() { SdpMid = GetString(payload, "id"), SdpMlineIndex = GetInt(payload, "label"), Content = GetString(payload, "candidate") }); break; } }
private async void OnLocalSdpReady2(SdpMessage message) { Assert.IsTrue(exchangePending_); await pc1_.SetRemoteDescriptionAsync(message); remoteDescAppliedEvent1_.Set(); if (message.Type == SdpMessageType.Offer) { pc1_.CreateAnswer(); } else { exchangePending_ = false; exchangeCompleted_.Set(); } }
public void Execute(StringTokenizer reader, SdpMessage message) { var media = new SdpMediaDescriptions(); media.AddFieldValue(GetFieldValuePair(reader)); while (reader.Length > 0) { var type = reader.ReadPeekChar(); if (type == 'i') media.AddFieldValue(GetFieldValuePair(reader)); else if (type == 'c') media.AddFieldValue(GetFieldValuePair(reader)); else if (type == 'b') media.AddFieldValue(GetFieldValuePair(reader)); else if (type == 'k') media.AddFieldValue(GetFieldValuePair(reader)); else if (type == 'a') media.AddFieldValue(GetFieldValuePair(reader)); else break; } message.Medias.Add(media); }
private void OnLocalSdpReadyToSend(SdpMessage message) { Logger.Log($"Local {message.Type} ready to be sent to remote peer."); if (message.Type == SdpMessageType.Offer) { NotifyLocalOfferApplied(); } if (message.Type == SdpMessageType.Answer) { NotifyLocalAnswerApplied(); } var dssMessage = NodeDssSignaler.Message.FromSdpMessage(message); NodeDssSignaler.SendMessageAsync(dssMessage); //RunOnMainThread(() => negotiationStatusText.Text = (type == "offer" ? "Sending local offer" : "Idle (answer sent)")); }
public void SdpMessageConstrutorTest() { List <string> singleMessageEntries = new List <string>(); singleMessageEntries = testLine2.Split(new[] { "\r\n" }, StringSplitOptions.None).ToList(); SdpMessage message = new SdpMessage(singleMessageEntries); Assert.AreEqual(message.VEntry, singleMessageEntries.First(x => x[0] == 'v').Substring(2)); Assert.AreEqual(message.IpAddress1, singleMessageEntries.First(x => x[0] == 'o').Substring(2)); Assert.AreEqual(message.SessionType, singleMessageEntries.First(x => x[0] == 's').Substring(2)); Assert.AreEqual(message.IpAddress2, singleMessageEntries.First(x => x[0] == 'c').Substring(2)); Assert.AreEqual(message.Port, singleMessageEntries.First(x => x[0] == 'b').Substring(2)); Assert.AreEqual(message.AudioId, singleMessageEntries.First(x => x[0] == 'm').Substring(2)); Assert.AreEqual(message.Codecs.Count, singleMessageEntries.Where(x => x[0] == 'a').Count()); }
/// <inheritdoc/> public override Task SendMessageAsync(SdpMessage message) { Debug.Log("<color=cyan>SdpMessage</color>: " + message.Content); if (message.Type == SdpMessageType.Offer) { lastOffer = message; } long i = idMessage++; var rpcMessage = "{\"jsonrpc\": \"2.0\"," + "\"method\": \"publishVideo\", " + "\"params\": { " + "\"sdpOffer\": \"" + message.Content + "\"," + "\"doLoopback\": false," + "\"hasAudio\": false," + "\"hasVideo\": true," + "\"audioActive\": false," + "\"videoActive\": true," + "\"typeOfVideo\": \"CAMERA\"," + "\"frameRate\": 30," + "\"videoDimensions\": \"{\\\"width\\\":640,\\\"height\\\":480}\"" + //TODO setup video dimensions according to capabilites "}, \"id\": " + i + " }"; Debug.Log("SdpMessage: " + rpcMessage); webSocket.SendText(rpcMessage); messages.Add(i, OpenViduType.PublishVideo); var tcs = new TaskCompletionSource <bool>(); tcs.SetResult(true); return(tcs.Task); //return SendMessageImplAsync(new OpenViduMessage(message)); }
public async Task NotifyPeerConnection(object sender, Type message_type, string message) { try { // Check if connection was created if (Connection != null) { (string header, string correct_message) = message.DivideHeaderAndOriginalJSON(); Console.WriteLine("Called NotifyPeerConnection with header: {0}", header); if (header == "{\"data\":{\"getRemoteMedia\":" && correct_message == "true") { Connection.CreateOffer(); // Console.WriteLine("GetMedia call after await ended in thread {0}", Thread.CurrentThread.ManagedThreadId); } if (header.IndexOf("candidate") != -1 && correct_message != "null") { Connection.AddIceCandidate( JsonSerializer.Deserialize <ICEJavaScriptNotation>(correct_message). ToMRNetCoreNotation()); } if (header.IndexOf("description") != -1) { SdpMessage sdp = JsonSerializer.Deserialize <SDPJavaScriptNotation>(correct_message). ToMRNetCoreNotation(); await Connection.SetRemoteDescriptionAsync(sdp); if (sdp.Type == SdpMessageType.Offer) { Connection.CreateAnswer(); } } } } catch (Exception ex) { Console.WriteLine("In NotifyPeerConnection caused exception: {0}", ex.Message); } }
/// <summary> /// Pass the given SDP description received from the remote peer via signaling to the /// underlying WebRTC implementation, which will parse and use it. /// /// This must be called by the signaler when receiving a message. Once this operation /// has completed, it is safe to call <see xref="WebRTC.PeerConnection.CreateAnswer"/>. /// /// <div class="IMPORTANT alert alert-important"> /// <h5>IMPORTANT</h5> /// <p> /// This method is very similar to the <c>SetRemoteDescriptionAsync()</c> method available in the /// underlying C# library, and actually calls it. However it also performs additional work in order /// to pair the transceivers of the local and remote peer. Therefore Unity applications must call /// this method instead of the C# library one to ensure transceiver pairing works as intended. /// </p> /// </div> /// </summary> /// <param name="message">The SDP message to handle.</param> /// <returns>A task which completes once the remote description has been applied and transceivers /// have been updated.</returns> /// <exception xref="InvalidOperationException">The peer connection is not intialized.</exception> /// <remarks> /// This method can only be called from the main Unity application thread, where Unity objects can /// be safely accessed. /// </remarks> public async Task HandleConnectionMessageAsync(SdpMessage message) { // MediaLine manipulates some MonoBehaviour objects when managing senders and receivers EnsureIsMainAppThread(); // First apply the remote description await Peer.SetRemoteDescriptionAsync(message); // Sort associated transceiver by media line index. The media line index is not the index of // the transceiver, but they are both monotonically increasing, so sorting by one or the other // yields the same ordered collection, which allows pairing transceivers and media lines. // TODO - Ensure PeerConnection.Transceivers is already sorted var transceivers = new List <Transceiver>(_nativePeer.AssociatedTransceivers); transceivers.Sort((tr1, tr2) => (tr1.MlineIndex - tr2.MlineIndex)); int numAssociatedTransceivers = transceivers.Count; int numMatching = Math.Min(numAssociatedTransceivers, _mediaLines.Count); // Once applied, try to pair transceivers and remote tracks with the Unity receiver components if (message.Type == SdpMessageType.Offer) { // Match transceivers with media line, in order for (int i = 0; i < numMatching; ++i) { var tr = transceivers[i]; var mediaLine = _mediaLines[i]; // Associate the transceiver with the media line, if not already done, and associate // the track components of the media line to the tracks of the transceiver. try { mediaLine.UpdateOnReceiveOffer(tr); } catch (Exception ex) { LogErrorOnMediaLineException(ex, mediaLine, tr); } // Check if the remote peer was planning to send something to this peer, but cannot. bool wantsRecv = (mediaLine.Receiver != null); if (!wantsRecv) { var desDir = tr.DesiredDirection; if (Transceiver.HasRecv(desDir)) { string peerName = name; int idx = i; InvokeOnAppThread(() => LogWarningOnMissingReceiver(peerName, idx)); } } } // Ignore extra transceivers without a registered component to attach if (numMatching < numAssociatedTransceivers) { string peerName = name; InvokeOnAppThread(() => { for (int i = numMatching; i < numAssociatedTransceivers; ++i) { LogWarningOnIgnoredTransceiver(peerName, i); } }); } } else if (message.Type == SdpMessageType.Answer) { // Associate registered media senders/receivers with existing transceivers for (int i = 0; i < numMatching; ++i) { Transceiver tr = transceivers[i]; var mediaLine = _mediaLines[i]; Debug.Assert(mediaLine.Transceiver == transceivers[i]); mediaLine.UpdateOnReceiveAnswer(); } // Ignore extra transceivers without a registered component to attach if (numMatching < numAssociatedTransceivers) { string peerName = name; InvokeOnAppThread(() => { for (int i = numMatching; i < numAssociatedTransceivers; ++i) { LogWarningOnIgnoredTransceiver(peerName, i); } }); } } }
/// <summary> /// JSON format serialization for /// communication with Artem Baskal /// frontend /// </summary> public static string ToABJson(this SdpMessage SDP) { return("{\"data\":{\"description\":" + ToJson(SDP) + "}}"); }
/// <summary> /// Standard JSON serialization for session /// description protocol /// </summary> public static string ToJson(this SdpMessage SDP) { return("{\"type\":\"" + SdpMessage.TypeToString(SDP.Type) + "\",\"sdp\":\"" + HttpUtility.JavaScriptStringEncode(SDP.Content) + "\"}"); }
public void Execute(StringTokenizer reader, SdpMessage message) { message.Uri = new SdpFieldUri(GetFieldValue(reader)); }
/// <summary> /// Callback invoked when a local SDP answer has been generated and is ready to /// be sent to the remote peer by the signaling object. /// </summary> /// <param name="answer">The SDP answer message to send.</param> protected virtual void OnSdpAnswerReadyToSend(string answer) { var message = new SdpMessage("answer", answer); SendMessageAsync(message); }
public static MyMsrpSession TakeIncomingSession(MySipStack sipStack, MsrpSession session, SipMessage message) { SdpMessage sdp = message.getSdpMessage(); string fromUri = message.getSipHeaderValue("f"); MyMsrpSession result; if (string.IsNullOrEmpty(fromUri)) { MyMsrpSession.LOG.Error("Invalid fromUri"); result = null; } else if (sdp == null) { MyMsrpSession.LOG.Error("Invalid Sdp content"); result = null; } else { string fileSelector = sdp.getSdpHeaderAValue("message", "file-selector"); MediaType mediaType = string.IsNullOrEmpty(fileSelector) ? MediaType.Chat : MediaType.FileTransfer; MyMsrpSession msrpSession; if (mediaType == MediaType.Chat) { msrpSession = MyMsrpSession.CreateIncomingSession(sipStack, session, mediaType, fromUri); } else { string type = null; int nameIndexStart = fileSelector.IndexOf("name:\""); if (nameIndexStart == -1) { MyMsrpSession.LOG.Error("No name attribute"); result = null; return(result); } int nameIndexEnd = fileSelector.IndexOf("\"", nameIndexStart + 6); if (nameIndexEnd == -1) { MyMsrpSession.LOG.Error("Invalid name attribute"); result = null; return(result); } string name = fileSelector.Substring(nameIndexStart + 6, nameIndexEnd - nameIndexStart - 6).Trim(); fileSelector = fileSelector.Substring(0, nameIndexStart) + fileSelector.Substring(nameIndexEnd + 1, fileSelector.Length - nameIndexEnd - 1); string[] attributes = fileSelector.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); string[] array = attributes; for (int i = 0; i < array.Length; i++) { string attribute = array[i]; string[] avp = attribute.Split(":".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); if (avp.Length >= 2) { if (string.Equals(avp[0], "type", System.StringComparison.InvariantCultureIgnoreCase) && avp[1] != null) { type = avp[1]; } } } msrpSession = MyMsrpSession.CreateIncomingSession(sipStack, session, mediaType, fromUri); msrpSession.mFilePath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), string.Format("{0}/{1}", "Doubango\\SharedContent", name)); msrpSession.mFileType = type; } result = msrpSession; } return(result); }
public override int OnInviteEvent(InviteEvent e) { tsip_invite_event_type_t type = e.getType(); InviteSession session = e.getSession(); SipMessage message = e.getSipMessage(); switch (type) { case tsip_invite_event_type_t.tsip_i_newcall: SdpMessage sdp = message.getSdpMessage(); if (session != null) { Console.WriteLine("ERRRRRRRRRRRORRRR"); return(0); } else { switch (e.getMediaType()) { case twrap_media_type_t.twrap_media_audio: case twrap_media_type_t.twrap_media_video: case twrap_media_type_t.twrap_media_audiovideo: session = e.takeCallSessionOwnership(); break; case twrap_media_type_t.twrap_media_msrp: if ((session = e.takeMsrpSessionOwnership()) != null) { (session as MsrpSession).setCallback(Program.msrpCallback); } break; } if (session != null) { ActionConfig actionConfig = new ActionConfig(); session.accept(actionConfig); actionConfig.Dispose(); } } /*else if ((session = e.takeSessionOwnership()) != null) * { * SdpMessage sdp = message.getSdpMessage(); * if (sdp != null) * { * String fileSelector = sdp.getSdpHeaderAValue("message", "file-selector"); * Console.WriteLine("file-selector={0}", fileSelector); * } * * ActionConfig actionConfig = new ActionConfig(); * //actionConfig.setMediaInt(twrap_media_type_t.twrap_media_audiovideo, "bandwidth-level", (int)tmedia_bandwidth_level_t.tmedia_bl_low); * actionConfig.setMediaString(twrap_media_type_t.twrap_media_file, "file-path", "C:\\tmp\\myfile"); * session.accept(actionConfig); * actionConfig.Dispose(); * }*/ break; case tsip_invite_event_type_t.tsip_i_request: break; case tsip_invite_event_type_t.tsip_ao_request: break; case tsip_invite_event_type_t.tsip_o_ect_ok: break; case tsip_invite_event_type_t.tsip_o_ect_nok: break; case tsip_invite_event_type_t.tsip_i_ect: break; case tsip_invite_event_type_t.tsip_m_local_hold_ok: Console.WriteLine("Local Hold OK"); break; case tsip_invite_event_type_t.tsip_m_local_hold_nok: Console.WriteLine("Local Hold NOK"); break; case tsip_invite_event_type_t.tsip_m_local_resume_ok: Console.WriteLine("Local Resume OK"); break; case tsip_invite_event_type_t.tsip_m_local_resume_nok: Console.WriteLine("Local Resume NOK"); break; case tsip_invite_event_type_t.tsip_m_remote_hold: Console.WriteLine("Remote Hold"); break; case tsip_invite_event_type_t.tsip_m_remote_resume: Console.WriteLine("Remote Resume"); break; } return(0); }
public void Execute(StringTokenizer reader, SdpMessage message) { message.Origin = new SdpFieldOrigin(GetFieldValue(reader)); }
public async Task SetRemoteDescriptionAsync(SdpMessage message) { await Connection.SetRemoteDescriptionAsync(message); }
public NodeDssMessage(SdpMessage message) { MessageType = MessageTypeFromSdpMessageType(message.Type); Data = message.Content; IceDataSeparator = string.Empty; }
public void Execute(StringTokenizer reader, SdpMessage message) { message.SessionInformation = new SdpFieldSessionInformation(GetFieldValue(reader)); }
/// <inheritdoc/> public override Task SendMessageAsync(SdpMessage message) { return(SendMessageImplAsync(new NodeDssMessage(message))); }
public void Execute(StringTokenizer reader, SdpMessage message) { message.Attributes.Add(new SdpFieldAttribute(GetFieldValue(reader))); }
public void Execute(StringTokenizer reader, SdpMessage message) { message.Email = new SdpFieldEmailAddress(GetFieldValue(reader)); }
public void Execute(StringTokenizer reader, SdpMessage message) { message.EncryptionKey = new SdpFieldEncryptionKey(GetFieldValue(reader)); }
static private async Task StartStend() { var autoEvent = new AutoResetEvent(false); bool video_translator = true; bool file_created = false; FileStream file = null; Quartus quartus = Quartus.GetInstance(); Microcontroller arduino = Microcontroller.Create(); if (video_translator) { // Asynchronously retrieve a list of available video capture devices (webcams). var deviceList = await DeviceVideoTrackSource.GetCaptureDevicesAsync(); // For example, print them to the standard output foreach (var device in deviceList) { Console.WriteLine($"Found webcam {device.name} (id: {device.id})"); } } // Create a new peer connection automatically disposed at the end of the program var pc = new PeerConnection(); // Initialize the connection with a STUN server to allow remote access var config = SystemConfiguration.PeerConnectionSettings; await pc.InitializeAsync(config); Console.WriteLine("Peer connection initialized."); //var chen = await pc.AddDataChannelAsync("sendDataChannel", true, true, cancellationToken: default); Console.WriteLine("Opening local webcam..."); // pc - PeerConnection object Transceiver videoTransceiver = null; VideoTrackSource videoTrackSource = null; LocalVideoTrack localVideoTrack = null; LocalVideoDeviceInitConfig c = new LocalVideoDeviceInitConfig(); await VideoDeviceSelection(); videoTrackSource = await Camera.CreateAsync(SystemConfiguration.VideoDeviceSettings); WebSocketSharp.WebSocket signaling = new WebSocketSharp.WebSocket(CreateSignalingServerUrl(), "id_token", "alpine"); pc.LocalSdpReadytoSend += (SdpMessage message) => { //Console.WriteLine(SdpMessage.TypeToString(message.Type)); Console.WriteLine(message.Content); //Console.WriteLine(HttpUtility.JavaScriptStringEncode(message.Content)); Console.WriteLine("Sdp offer to send: {\"data\":{\"description\":{\"type\":\"" + SdpMessage.TypeToString(message.Type) + "\",\"sdp\":\"" + HttpUtility.JavaScriptStringEncode(message.Content) + "\"}}}"); signaling.Send(message.ToABJson()); }; pc.RenegotiationNeeded += () => { Console.WriteLine("Regotiation needed"); bool OfferCreated = pc.CreateOffer(); Console.WriteLine("OfferCreated? {0}", OfferCreated); }; pc.DataChannelAdded += (DataChannel channel) => { Console.WriteLine("Added data channel ID: {0}, Label: {1}; Reliable: {2}, Ordered: {3}", channel.ID, channel.Label, channel.Reliable, channel.Ordered); if (channel.Label == "sendDataChannel") { channel.MessageReceived += (byte[] mess) => { try { CTP_packet command = JsonSerializer.Deserialize <CTP_packet>(mess); Console.WriteLine(arduino.SendCTP_Command(command)); } catch (Exception e) { Console.WriteLine(e.Message); } }; } else { if (file_created == false) { file = new FileStream(channel.Label, FileMode.Append); file_created = true; } channel.MessageReceived += async(byte[] mess) => { // Console.WriteLine(System.Text.Encoding.Default.GetString(mess)); if (mess.Length == 3 && System.Text.Encoding.Default.GetString(mess) == "EOF") { string file_name = file.Name; file.Close(); string t = await quartus.RunQuartusCommandAsync($"quartus_pgm -m jtag –o \"p;{file_name}@1\""); File.Delete(file_name); file_created = false; } else { WriteFileSegment(mess, file); } }; } channel.StateChanged += () => { Console.WriteLine("State change: {0}", channel.State); }; }; pc.IceCandidateReadytoSend += (IceCandidate candidate) => { //Console.WriteLine("Content: {0}, SdpMid: {1}, SdpMlineIndex: {2}", candidate.Content, candidate.SdpMid, candidate.SdpMlineIndex); try { Console.WriteLine("Candidate to send: Content: {0}, SdpMid: {1}, SdpMlineIndex: {2}", candidate.Content, candidate.SdpMid, candidate.SdpMlineIndex); signaling.Send(candidate.ToABJson()); } catch (Exception e) { Console.WriteLine("Error to send local ice candidate"); } }; //videoTrackSource.I420AVideoFrameReady += (frame) => //{ // Console.WriteLine("Argb32 frame ready. {0} : {1}", frame.width, frame.height); // Console.WriteLine("DataA: {0}, DataU: {1}, DataV: {2}, DataY: {3}", Marshal.SizeOf(frame.dataA), // Marshal.SizeOf(frame.dataU), // Marshal.SizeOf(frame.dataV), // Marshal.SizeOf(frame.dataY)); //}; signaling.OnMessage += async(sender, message) => { (string header, string correct_message) = message.Data.DivideHeaderAndOriginalJSON(); Console.WriteLine("Correct message: {0}", correct_message); Console.WriteLine("Header: {0}", header); if (header == "{\"data\":{\"getRemoteMedia\":" && correct_message == "true") { Console.WriteLine("Create local video track..."); var trackSettings = new LocalVideoTrackInitConfig { trackName = "webcam_track" }; localVideoTrack = LocalVideoTrack.CreateFromSource(videoTrackSource, new LocalVideoTrackInitConfig { trackName = "webcam_track" }); Console.WriteLine("Create video transceiver and add webcam track..."); TransceiverInitSettings option = new TransceiverInitSettings(); option.Name = "webcam_track"; option.StreamIDs = new List <string> { "webcam_name" }; videoTransceiver = pc.AddTransceiver(MediaKind.Video, option); videoTransceiver.DesiredDirection = Transceiver.Direction.SendOnly; videoTransceiver.LocalVideoTrack = localVideoTrack; bool OfferCreated = pc.CreateOffer(); Console.WriteLine("OfferCreated? {0}", OfferCreated); } //Console.WriteLine(message.Data); if (header.IndexOf("candidate") != -1 && correct_message != "null") { try { var candidate = JsonSerializer.Deserialize <ICEJavaScriptNotation>(correct_message); Console.WriteLine("Content of ice: {0}, SdpMid: {1}, SdpMLineIndex: {2}", candidate.candidate, candidate.sdpMid, candidate.sdpMLineIndex); pc.AddIceCandidate(candidate.ToMRNetCoreNotation()); Console.WriteLine("Deserialized by ice_candidate"); //return; } catch (Exception) { Console.WriteLine("Could not deserialize as ice candidate"); } } if (header.IndexOf("description") != -1) { try { SdpMessage received_description = JsonSerializer.Deserialize <SDPJavaScriptNotation>(correct_message).ToMRNetCoreNotation(); await pc.SetRemoteDescriptionAsync(received_description); if (received_description.Type == SdpMessageType.Offer) { bool res = pc.CreateAnswer(); Console.WriteLine("Answer created? {0}", res); } Console.WriteLine("Deserialized by sdp_message"); } catch (Exception) { Console.WriteLine("Could not deserialize as sdp message"); } } }; pc.Connected += () => { Console.WriteLine("Connected"); }; pc.IceStateChanged += (IceConnectionState newState) => { if (newState == IceConnectionState.Disconnected) { Console.WriteLine("Disconected"); } }; signaling.Connect(); if (!video_translator) { signaling.Send("{\"data\":{\"getRemoteMedia\":true}}"); } //Console.WriteLine("Press a key to terminate the application..."); Console.ReadKey(true); Console.WriteLine("Program termined."); file?.Close(); pc?.Close(); signaling?.Close(); //arduino?.Close(); //(var a, var b) = ConvertString("{\"data\":{\"candidate\":null}}"); //Console.WriteLine("{0}, {1}", a, b); }
public void Execute(StringTokenizer reader, SdpMessage message) { message.Phone = new SdpFieldPhoneNumber(GetFieldValue(reader)); }
/// <summary> /// Callback invoked when a local SDP offer has been generated and is ready to /// be sent to the remote peer by the signaling object. /// </summary> /// <param name="offer">The SDP offer message to send.</param> protected virtual void OnSdpOfferReadyToSend(string offer) { var message = new SdpMessage("offer", offer); SendMessageAsync(message); }