void OnCloseChannel(RTCDataChannel channel) { RemoteInput input = m_mapChannelAndRemoteInput[channel]; RemoteInputReceiver.Delete(input); // device.current must be changed after removing devices m_defaultInput.MakeCurrent(); // reassign remote input to controller if (m_remoteInputAndCameraController.TryGetValue(input, out var controller)) { RemoteInput newInput = FindPrioritizedInput(); if (newInput == null) { controller.SetInput(m_defaultInput); } else { controller.SetInput(newInput); m_remoteInputAndCameraController.Add(newInput, controller); } } m_remoteInputAndCameraController.Remove(input); m_mapChannelAndRemoteInput.Remove(channel); }
/// <summary> /// /// </summary> /// <param name="track"></param> public override void SetChannel(string connectionId, RTCDataChannel channel) { if (channel == null) { if (remoteInput != null) { onDeviceChange.Invoke(remoteInput.RemoteGamepad, InputDeviceChange.Removed); onDeviceChange.Invoke(remoteInput.RemoteKeyboard, InputDeviceChange.Removed); onDeviceChange.Invoke(remoteInput.RemoteMouse, InputDeviceChange.Removed); onDeviceChange.Invoke(remoteInput.RemoteTouchscreen, InputDeviceChange.Removed); remoteInput.Dispose(); remoteInput = null; } } else { remoteInput = RemoteInputReceiver.Create(); remoteInput.ActionButtonClick = OnButtonClick; channel.OnMessage += remoteInput.ProcessInput; onDeviceChange.Invoke(remoteInput.RemoteGamepad, InputDeviceChange.Added); onDeviceChange.Invoke(remoteInput.RemoteKeyboard, InputDeviceChange.Added); onDeviceChange.Invoke(remoteInput.RemoteMouse, InputDeviceChange.Added); onDeviceChange.Invoke(remoteInput.RemoteTouchscreen, InputDeviceChange.Added); } base.SetChannel(connectionId, channel); }
RemoteInput FindPrioritizedInput() { var list = RemoteInputReceiver.All(); // filter here // return null if not found the input return(list.Except(m_remoteInputAndCameraController.Keys).FirstOrDefault()); }
public void OnDestroy() { Instance = null; EnhancedTouchSupport.Disable(); WebRTC.WebRTC.Dispose(); RemoteInputReceiver.Dispose(); Unity.WebRTC.Audio.Stop(); }
public void Dispose() { if (this.disposed) { return; } RemoteInputReceiver.Delete(this); this.disposed = true; GC.SuppressFinalize(this); }
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); } }