public void SendMsg_text() { if (sendText != null) { localDataChannel.Send(sendText.text); } }
public void SendDataChannelData(string msg) { if (dataChannel != null) { dataChannel.Send(msg); } }
void EncodeAndSendBytes(byte[] data, int length) { if (isConnected) { buffer = EncodeLength(data, length); dataChannel.Send(buffer); } }
public void HandleSendMessageViaDataChannel(string message) { if (_dataChannel == null) { Debug.WriteLine("Attempting to send data where no data channel exists"); return; } _dataChannel.Send(message); }
public void OnNext(InputRemoting.Message value) { if (_channel.ReadyState != RTCDataChannelState.Open) { return; } byte[] bytes = MessageSerializer.Serialize(ref value); _channel.Send(bytes); }
public void OnNext(InputRemoting.Message value) { if (!_isOpen) { return; } byte[] bytes = MessageSerializer.Serialize(ref value); _channel.Send(bytes); }
public bool SendPeerDataChannelMessage(string msg) { if (_isDataChannelOpen) { _peerSendDataChannel.Send(new StringDataChannelMessage(msg)); return(true); } return(false); }
private void uxSend_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(Message)) { return; } AppendConversation(Message, true); _dataChannel.Send(Message); Message = string.Empty; }
public IEnumerator SendThrowsExceptionAfterClose() { var test = new MonoBehaviourTest <SignalingPeers>(); yield return(test); RTCDataChannel channel = test.component.CreateDataChannel(0, "test"); byte[] message1 = { 1, 2, 3 }; string message2 = "123"; Assert.DoesNotThrow(() => channel.Send(message1)); Assert.DoesNotThrow(() => channel.Send(message2)); channel.Close(); Assert.Throws <InvalidOperationException>(() => channel.Send(message1)); Assert.Throws <InvalidOperationException>(() => channel.Send(message2)); test.component.Dispose(); yield return(0); }
public IEnumerator SendThrowsExceptionAfterClose() { var test = new MonoBehaviourTest <SignalingPeers>(); RTCDataChannel channel = test.component.CreateDataChannel(0, "test"); yield return(test); byte[] message1 = { 1, 2, 3 }; string message2 = "123"; var op1 = new WaitUntilWithTimeout(() => channel.ReadyState == RTCDataChannelState.Open, 5000); yield return(op1); Assert.That(op1.IsCompleted, Is.True); Assert.That(() => channel.Send(message1), Throws.Nothing); Assert.That(() => channel.Send(message2), Throws.Nothing); channel.Close(); Assert.That(() => channel.Send(message1), Throws.TypeOf <InvalidOperationException>()); Assert.That(() => channel.Send(message2), Throws.TypeOf <InvalidOperationException>()); test.component.Dispose(); Object.DestroyImmediate(test.gameObject); }
void OnDataChannel(RTCPeerConnection pc, RTCDataChannel channel) { if (!m_mapPeerAndChannelDictionary.TryGetValue(pc, out var channels)) { channels = new DataChannelDictionary(); m_mapPeerAndChannelDictionary.Add(pc, channels); } channels.Add(channel.Id, channel); if (channel.Label != "data") { return; } RemoteInput input = RemoteInputReceiver.Create(); input.ActionButtonClick = OnButtonClick; // device.current must be changed after creating devices m_defaultInput.MakeCurrent(); m_mapChannelAndRemoteInput.Add(channel, input); channel.OnMessage = bytes => m_mapChannelAndRemoteInput[channel].ProcessInput(bytes); channel.OnClose = () => OnCloseChannel(channel); // Instantiate prefab and create controller GameObject gameObject = Instantiate(StreamingManager.Instance.playerPrefab, Vector3.zero, Quaternion.identity); SimpleCameraController controller = gameObject.GetComponentInChildren <SimpleCameraController>(); if (controller != null) { print("SETTING INPUT FOR NEW CONTROLLER"); controller.enabled = true; m_listController.Add(controller); controller.SetInput(input); m_remoteInputAndCameraController.Add(input, controller); byte index = (byte)m_listController.IndexOf(controller); byte[] bytes = { (byte)UnityEventType.SwitchVideo, index }; channel.Send(bytes); } }
void OnDataChannel(RTCPeerConnection pc, RTCDataChannel channel) { if (!m_mapPeerAndChannelDictionary.TryGetValue(pc, out var channels)) { channels = new DataChannelDictionary(); m_mapPeerAndChannelDictionary.Add(pc, channels); } channels.Add(channel.Id, channel); if (channel.Label != "data") { return; } RemoteInput input = RemoteInputReceiver.Create(); input.ActionButtonClick = OnButtonClick; // device.current must be changed after creating devices m_defaultInput.MakeCurrent(); m_mapChannelAndRemoteInput.Add(channel, input); channel.OnMessage = bytes => m_mapChannelAndRemoteInput[channel].ProcessInput(bytes); channel.OnClose = () => OnCloseChannel(channel); // find controller that not assigned remote input SimpleCameraController controller = m_listController .FirstOrDefault(_controller => !m_remoteInputAndCameraController.ContainsValue(_controller)); if (controller != null) { controller.SetInput(input); m_remoteInputAndCameraController.Add(input, controller); byte index = (byte)m_listController.IndexOf(controller); byte[] bytes = { (byte)UnityEventType.SwitchVideo, index }; channel.Send(bytes); } }
private void OnAdminUIMessage(object reference, AdminUIMessageArgs args) { dataChannel.Send(JsonConvert.SerializeObject(args.message)); }
public void SendMsg() { dataChannel.Send(textSend.text); }
public void SendPeerDataChannelMessage(string msg) { _peerSendDataChannel.Send(new StringDataChannelMessage(msg)); }
public IEnumerator SendAndReceiveMessageWithExecuteTasks() { var test = new MonoBehaviourTest <SignalingPeers>(); var label = "test"; RTCDataChannel channel1 = test.component.CreateDataChannel(0, label); Assert.That(channel1, Is.Not.Null); yield return(test); var op1 = new WaitUntilWithTimeout(() => test.component.GetDataChannelList(1).Count > 0, 5000); yield return(op1); RTCDataChannel channel2 = test.component.GetDataChannelList(1)[0]; Assert.That(channel2, Is.Not.Null); Assert.That(channel1.ReadyState, Is.EqualTo(RTCDataChannelState.Open)); Assert.That(channel2.ReadyState, Is.EqualTo(RTCDataChannelState.Open)); Assert.That(channel1.Label, Is.EqualTo(channel2.Label)); Assert.That(channel1.Id, Is.EqualTo(channel2.Id)); // send string const int millisecondTimeout = 5000; const string message1 = "hello"; string message2 = null; channel2.OnMessage = bytes => { message2 = System.Text.Encoding.UTF8.GetString(bytes); }; channel1.Send(message1); ExecutePendingTasksWithTimeout(ref message2, millisecondTimeout); Assert.That(message1, Is.EqualTo(message2)); // send byte array byte[] message3 = { 1, 2, 3 }; byte[] message4 = null; channel2.OnMessage = bytes => { message4 = bytes; }; channel1.Send(message3); ExecutePendingTasksWithTimeout(ref message4, millisecondTimeout); Assert.That(message3, Is.EqualTo(message4)); // Native Collections Tests Vector3[] structData = { Vector3.one, Vector3.zero, Vector3.up, Vector3.down }; using (var nativeArray = new NativeArray <Vector3>(structData, Allocator.Temp)) { var nativeArrayTestMessageReceiver = default(byte[]); channel2.OnMessage = bytes => { nativeArrayTestMessageReceiver = bytes; }; // Native Array var message5 = nativeArray; Assert.That(message5.IsCreated, Is.True); nativeArrayTestMessageReceiver = null; channel1.Send(message5); ExecutePendingTasksWithTimeout(ref nativeArrayTestMessageReceiver, millisecondTimeout); Assert.That(NativeArrayMemCmp(message5, nativeArrayTestMessageReceiver), Is.True, "Elements of the received message are not the same as the original message."); // Native Slice var message6 = nativeArray.Slice(); nativeArrayTestMessageReceiver = null; channel1.Send(message6); ExecutePendingTasksWithTimeout(ref nativeArrayTestMessageReceiver, millisecondTimeout); Assert.That(NativeArrayMemCmp(message6, nativeArrayTestMessageReceiver), Is.True, "Elements of the received message are not the same as the original message."); #if UNITY_2021_1_OR_NEWER // NativeArray.ReadOnly var message7 = nativeArray.AsReadOnly(); nativeArrayTestMessageReceiver = null; channel1.Send(message7); ExecutePendingTasksWithTimeout(ref nativeArrayTestMessageReceiver, millisecondTimeout); Assert.That(NativeArrayMemCmp(message7, nativeArrayTestMessageReceiver), Is.True, "Elements of the received message are not the same as the original message."); #endif // UNITY_2021_1_OR_NEWER } test.component.Dispose(); Object.DestroyImmediate(test.gameObject); }
public IEnumerator SendAndReceiveMessage() { var test = new MonoBehaviourTest <SignalingPeers>(); var label = "test"; RTCDataChannel channel1 = test.component.CreateDataChannel(0, label); Assert.That(channel1, Is.Not.Null); yield return(test); var op1 = new WaitUntilWithTimeout(() => test.component.GetDataChannelList(1).Count > 0, 5000); yield return(op1); RTCDataChannel channel2 = test.component.GetDataChannelList(1)[0]; Assert.That(channel2, Is.Not.Null); Assert.That(channel1.ReadyState, Is.EqualTo(RTCDataChannelState.Open)); Assert.That(channel2.ReadyState, Is.EqualTo(RTCDataChannelState.Open)); Assert.That(channel1.Label, Is.EqualTo(channel2.Label)); Assert.That(channel1.Id, Is.EqualTo(channel2.Id)); // send string const string message1 = "hello"; string message2 = null; channel2.OnMessage = bytes => { message2 = System.Text.Encoding.UTF8.GetString(bytes); }; channel1.Send(message1); var op10 = new WaitUntilWithTimeout(() => !string.IsNullOrEmpty(message2), 5000); yield return(op10); Assert.That(op10.IsCompleted, Is.True); Assert.That(message1, Is.EqualTo(message2)); // send byte array byte[] message3 = { 1, 2, 3 }; byte[] message4 = null; channel2.OnMessage = bytes => { message4 = bytes; }; channel1.Send(message3); var op11 = new WaitUntilWithTimeout(() => message4 != null, 5000); yield return(op11); Assert.That(op11.IsCompleted, Is.True); Assert.That(message3, Is.EqualTo(message4)); // Native Array // Native Arrays that are declared in tests that use IEnumerator seem to have some oddities about them // they tend to dispose themselves on yields so we recreate the array as needed. byte[] comparisonBuffer = { 1, 2, 3 }; var nativeArrayTestMessageReceiver = default(byte[]); using (var message5 = new NativeArray <byte>(comparisonBuffer, Allocator.Temp)) { Assert.That(message5.IsCreated, Is.True); // Only needs to be set once as it will be reused. channel2.OnMessage = bytes => { nativeArrayTestMessageReceiver = bytes; }; channel1.Send(message5); } var op12 = new WaitUntilWithTimeout(() => nativeArrayTestMessageReceiver != null, 5000); yield return(op12); Assert.That(op12.IsCompleted, Is.True); Assert.That(comparisonBuffer, Is.EqualTo(nativeArrayTestMessageReceiver)); // Native Slice using (var nativeArray = new NativeArray <byte>(comparisonBuffer, Allocator.Temp)) { Assert.That(nativeArray.IsCreated, Is.True); var message6 = nativeArray.Slice(); nativeArrayTestMessageReceiver = null; channel1.Send(message6); } var op13 = new WaitUntilWithTimeout(() => nativeArrayTestMessageReceiver != null, 5000); yield return(op13); Assert.That(op13.IsCompleted, Is.True); Assert.That(comparisonBuffer, Is.EqualTo(nativeArrayTestMessageReceiver)); #if UNITY_2021_1_OR_NEWER // NativeArray.ReadOnly using (var nativeArray = new NativeArray <byte>(comparisonBuffer, Allocator.Temp)) { Assert.That(nativeArray.IsCreated, Is.True); var message7 = nativeArray.AsReadOnly(); nativeArrayTestMessageReceiver = null; channel1.Send(message7); } var op14 = new WaitUntilWithTimeout(() => nativeArrayTestMessageReceiver != null, 5000); yield return(op14); Assert.That(op14.IsCompleted, Is.True); Assert.That(comparisonBuffer, Is.EqualTo(nativeArrayTestMessageReceiver)); #endif // UNITY_2020_1_OR_NEWER test.component.Dispose(); Object.DestroyImmediate(test.gameObject); }
public bool SendPeerDataChannelMessage(string msg) { _peerSendDataChannel?.Send(new StringDataChannelMessage(msg)); return(_peerReceiveDataChannel != null); }
public IEnumerator DataChannel_EventsAreSentToOther() { RTCConfiguration config = default; config.iceServers = new RTCIceServer[] { new RTCIceServer { urls = new string[] { "stun:stun.l.google.com:19302" } } }; var peer1 = new RTCPeerConnection(ref config); var peer2 = new RTCPeerConnection(ref config); RTCDataChannel channel1 = null, channel2 = null; peer1.OnIceCandidate = new DelegateOnIceCandidate(candidate => { peer2.AddIceCandidate(ref candidate); }); peer2.OnIceCandidate = new DelegateOnIceCandidate(candidate => { peer1.AddIceCandidate(ref candidate); }); peer2.OnDataChannel = new DelegateOnDataChannel(channel => { channel2 = channel; }); var conf = new RTCDataChannelInit(true); channel1 = peer1.CreateDataChannel("data", ref conf); RTCOfferOptions options1 = default; RTCAnswerOptions options2 = default; var op1 = peer1.CreateOffer(ref options1); yield return(op1); var op2 = peer1.SetLocalDescription(ref op1.desc); yield return(op2); var op3 = peer2.SetRemoteDescription(ref op1.desc); yield return(op3); var op4 = peer2.CreateAnswer(ref options2); yield return(op4); var op5 = peer2.SetLocalDescription(ref op4.desc); yield return(op5); var op6 = peer1.SetRemoteDescription(ref op4.desc); yield return(op6); yield return(new WaitUntil(() => peer1.IceConnectionState == RTCIceConnectionState.Connected || peer1.IceConnectionState == RTCIceConnectionState.Completed)); yield return(new WaitUntil(() => peer2.IceConnectionState == RTCIceConnectionState.Connected || peer2.IceConnectionState == RTCIceConnectionState.Completed)); yield return(new WaitUntil(() => channel2 != null)); Assert.AreEqual(channel1.Label, channel2.Label); Assert.AreEqual(channel1.Id, channel2.Id); string message1 = "hello"; string message2 = null; channel2.OnMessage = new DelegateOnMessage(bytes => { message2 = System.Text.Encoding.UTF8.GetString(bytes); }); channel1.Send(message1); yield return(new WaitUntil(() => !string.IsNullOrEmpty(message2))); Assert.AreEqual(message1, message2); byte[] message3 = { 1, 2, 3 }; byte[] message4 = null; channel2.OnMessage = new DelegateOnMessage(bytes => { message4 = bytes; }); channel1.Send(message3); yield return(new WaitUntil(() => message4 != null)); Assert.AreEqual(message3, message4); peer1.Close(); peer2.Close(); }
public void SendMessage(byte[] datas) { mSendDataChannel.Send(datas); }