public async Task Answer(MockSignaling owner, DescData data) { await Task.Delay(MillisecondsDelay); foreach (var signaling in list.Where(e => e != owner)) { signaling.OnAnswer?.Invoke(signaling, data); } }
public void SendOffer(string connectionId, RTCSessionDescription offer) { DescData data = new DescData(); data.connectionId = connectionId; data.sdp = offer.sdp; data.type = "offer"; HTTPPost("signaling/offer", data); }
public void SendAnswer(string connectionId, RTCSessionDescription answer) { DescData data = new DescData(); data.connectionId = connectionId; data.sdp = answer.sdp; data.type = "answer"; FurioosRoutedMessage <DescData> routedMessage = new FurioosRoutedMessage <DescData>(); routedMessage.to = connectionId; routedMessage.message = data; WSSend(routedMessage); }
public void SendAnswer(string connectionId, RTCSessionDescription answer) { if (string.IsNullOrEmpty(connectionId)) { throw new ArgumentException("connectionId is null or empty."); } DescData data = new DescData { connectionId = connectionId, type = "answer", sdp = answer.sdp }; manager.Answer(this, data); }
public void SendOffer(string connectionId, RTCSessionDescription offer) { DescData data = new DescData(); data.connectionId = connectionId; data.sdp = offer.sdp; data.type = "offer"; RoutedMessage <DescData> routedMessage = new RoutedMessage <DescData>(); routedMessage.from = connectionId; routedMessage.data = data; routedMessage.type = "offer"; WSSend(routedMessage); }
public async Task Answer(MockSignaling owner, DescData data) { await Task.Delay(MillisecondsDelay); var list = FindList(owner, data.connectionId); if (list == null) { Debug.LogError($"{data.connectionId} This connection id is not ready other session."); return; } foreach (var signaling in list) { signaling.OnAnswer?.Invoke(signaling, data); } }
public void SendAnswer(string connectionId, RTCSessionDescription answer) { DescData data = new DescData(); data.connectionId = connectionId; data.sdp = answer.sdp; data.type = "answer"; RoutedMessage <DescData> routedMessage = new RoutedMessage <DescData>(); routedMessage.from = connectionId; routedMessage.data = data; routedMessage.type = "answer"; Send(0, routedMessage); }
public async Task Offer(MockSignaling owner, DescData data) { await Task.Delay(MillisecondsDelay); var list = FindList(owner, data.connectionId); if (list == null) { Debug.LogWarning($"{data.connectionId} This connection id is not ready other session."); return; } data.polite = true; foreach (var signaling in list.Where(x => x != owner)) { signaling.OnOffer?.Invoke(signaling, data); } }
/////<summary>注册可用项,注:已不使用,改为自动获取</summary> //public void regCanCreateItem(Type type, string dbopkey) //{ // pLayer tmplayer = new pLayer(null); // DNDesc dn = new DNDesc() { type = type }; // PowerBasicObject o = dn.CreateByType(tmplayer); // DescData dd = o.busiDesc as DescData; // dn.sort = dd.objCategory.ToString(); // dn.name = type.Name; // dn.dbopkey = dbopkey; // dn.icon = dd.icon; // dn.info = string.Format("{0}({1})", dbopkey, dn.name); // dndescs.Add(dn); //} void reg(string fulltypename, string dbopkey) { pLayer tmplayer = new pLayer(null); DNDesc dn = new DNDesc() { typefullname = fulltypename }; PowerBasicObject o = dn.CreateByTypeName(tmplayer); DescData dd = o.busiDesc as DescData; dn.sort = dd.objCategory.ToString(); dn.type = o.GetType(); dn.name = dbopkey; //dn.type.Name; dn.dbopkey = dbopkey; dn.icon = dd.icon; dn.info = string.Format("{0}({1})", dbopkey, dn.type.Name);//dn.name); dndescs.Add(dn); }
private void WSProcessMessage(object sender, MessageEventArgs e) { var content = Encoding.UTF8.GetString(e.RawData); Debug.Log($"Signaling: Receiving message: {content}"); try { var routedMessage = JsonUtility.FromJson <FurioosRoutedMessage <SignalingMessage> >(content); SignalingMessage msg; if (!string.IsNullOrEmpty(routedMessage.from)) { msg = routedMessage.message; } else { msg = JsonUtility.FromJson <SignalingMessage>(content); } if (!string.IsNullOrEmpty(msg.type)) { if (msg.type == "signIn") { if (msg.status == "SUCCESS") { Debug.Log("Signaling: Slot signed in."); this.WSSend("{\"type\":\"furioos\",\"task\":\"enableStreaming\",\"streamTypes\":\"WebRTC\",\"controlType\":\"RenderStreaming\"}"); OnSignedIn?.Invoke(this); } else { Debug.LogError("Signaling: Sign-in error : " + msg.message); } } else if (msg.type == "reconnect") { if (msg.status == "SUCCESS") { Debug.Log("Signaling: Slot reconnected."); } else { Debug.LogError("Signaling: Reconnect error : " + msg.message); } } if (msg.type == "offer") { if (!string.IsNullOrEmpty(routedMessage.from)) { DescData offer = new DescData(); offer.connectionId = routedMessage.from; offer.sdp = msg.sdp; OnOffer?.Invoke(this, offer); } else { Debug.LogError("Signaling: Received message from unknown peer"); } } } else if (!string.IsNullOrEmpty(msg.candidate)) { if (!string.IsNullOrEmpty(routedMessage.from)) { CandidateData candidate = new CandidateData(); candidate.connectionId = routedMessage.from; candidate.candidate = msg.candidate; candidate.sdpMLineIndex = msg.sdpMLineIndex; candidate.sdpMid = msg.sdpMid; OnIceCandidate?.Invoke(this, candidate); } else { Debug.LogError("Signaling: Received message from unknown peer"); } } } catch (Exception ex) { Debug.LogError("Signaling: Failed to parse message: " + ex); } }
private void WSProcessMessage(object sender, MessageEventArgs e) { var content = Encoding.UTF8.GetString(e.RawData); Debug.Log($"Signaling: Receiving message: {content}"); try { var routedMessage = JsonUtility.FromJson <RoutedMessage <SignalingMessage> >(content); SignalingMessage msg; if (!string.IsNullOrEmpty(routedMessage.type)) { msg = routedMessage.data; } else { msg = JsonUtility.FromJson <SignalingMessage>(content); } if (!string.IsNullOrEmpty(routedMessage.type)) { if (routedMessage.type == "connect") { string connectionId = JsonUtility.FromJson <SignalingMessage>(content).connectionId; OnCreateConnection?.Invoke(this, connectionId); } else if (routedMessage.type == "offer") { if (!string.IsNullOrEmpty(routedMessage.from)) { DescData offer = new DescData(); offer.connectionId = routedMessage.from; offer.sdp = msg.sdp; OnOffer?.Invoke(this, offer); } else { Debug.LogError("Signaling: Received message from unknown peer"); } } else if (routedMessage.type == "answer") { if (!string.IsNullOrEmpty(routedMessage.from)) { DescData answer = new DescData { connectionId = routedMessage.from, sdp = msg.sdp }; OnAnswer?.Invoke(this, answer); } else { Debug.LogError("Signaling: Received message from unknown peer"); } } else if (routedMessage.type == "candidate") { if (!string.IsNullOrEmpty(routedMessage.from)) { CandidateData candidate = new CandidateData { connectionId = routedMessage.@from, candidate = msg.candidate, sdpMLineIndex = msg.sdpMLineIndex, sdpMid = msg.sdpMid }; OnIceCandidate?.Invoke(this, candidate); } else { Debug.LogError("Signaling: Received message from unknown peer"); } } } } catch (Exception ex) { Debug.LogError("Signaling: Failed to parse message: " + ex); } }
private void WSProcessMessage(object sender, MessageEventArgs e) { var content = Encoding.UTF8.GetString(e.RawData); Debug.Log($"Signaling: Receiving message: {content}"); try { var message = JsonUtility.FromJson <Message>(content); string type = message.type; switch (type) { case "accept": { AcceptMessage acceptMessage = JsonUtility.FromJson <AcceptMessage>(content); this.m_acceptMessage = acceptMessage; this.OnAccept?.Invoke(this); break; } case "offer": { OfferMessage offerMessage = JsonUtility.FromJson <OfferMessage>(content); DescData descData = new DescData(); descData.connectionId = this.m_acceptMessage.connectionId; descData.sdp = offerMessage.sdp; this.OnOffer?.Invoke(this, descData); break; } case "answer": { AnswerMessage answerMessage = JsonUtility.FromJson <AnswerMessage>(content); DescData descData = new DescData(); descData.connectionId = this.m_acceptMessage.connectionId; descData.sdp = answerMessage.sdp; this.OnAnswer?.Invoke(this, descData); break; } case "candidate": { CandidateMessage candidateMessage = JsonUtility.FromJson <CandidateMessage>(content); CandidateData candidateData = new CandidateData(); candidateData.connectionId = this.m_acceptMessage.connectionId; candidateData.candidate = candidateMessage.ice.candidate; candidateData.sdpMLineIndex = candidateMessage.ice.sdpMLineIndex; candidateData.sdpMid = candidateMessage.ice.sdpMid; this.OnIceCandidate?.Invoke(this, candidateData); break; } case "ping": { PongMessage pongMessage = new PongMessage(); this.WSSend(JsonUtility.ToJson(pongMessage)); break; } case "bye": { // TODO: break; } default: { Debug.LogError("Signaling: Received message from unknown peer"); break; } } } catch (Exception ex) { Debug.LogError("Signaling: Failed to parse message: " + ex); } }
//private void ProcessMessage(byte[] data) private void ProcessMessage(string content) { //var content = Encoding.UTF8.GetString(data); Debug.Log($"Signaling: Receiving message: {content}"); try { var routedMessage = JsonUtility.FromJson <RoutedMessage <SignalingMessage> >(content); SignalingMessage msg; if (!string.IsNullOrEmpty(routedMessage.type)) { msg = routedMessage.data; } else { msg = JsonUtility.FromJson <SignalingMessage>(content); } if (!string.IsNullOrEmpty(routedMessage.type)) { if (routedMessage.type == "connect") { msg = JsonUtility.FromJson <SignalingMessage>(content); m_mainThreadContext.Post(d => OnCreateConnection?.Invoke(this, msg.connectionId, msg.peerExists), null); } else if (routedMessage.type == "disconnect") { msg = JsonUtility.FromJson <SignalingMessage>(content); m_mainThreadContext.Post(d => OnDestroyConnection?.Invoke(this, msg.connectionId), null); } else if (routedMessage.type == "offer") { DescData offer = new DescData(); offer.connectionId = routedMessage.from; offer.sdp = msg.sdp; m_mainThreadContext.Post(d => OnOffer?.Invoke(this, offer), null); } else if (routedMessage.type == "answer") { DescData answer = new DescData { connectionId = routedMessage.from, sdp = msg.sdp }; m_mainThreadContext.Post(d => OnAnswer?.Invoke(this, answer), null); } else if (routedMessage.type == "candidate") { CandidateData candidate = new CandidateData { connectionId = routedMessage.@from, candidate = msg.candidate, sdpMLineIndex = msg.sdpMLineIndex, sdpMid = msg.sdpMid }; m_mainThreadContext.Post(d => OnIceCandidate?.Invoke(this, candidate), null); } else if (routedMessage.type == "error") { msg = JsonUtility.FromJson <SignalingMessage>(content); Debug.LogError(msg.message); } } } catch (Exception ex) { Debug.LogError("Signaling: Failed to parse message: " + ex); } }