Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 /// <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);
 }
        public void Awake()
        {
            var encoderType = hardwareEncoderSupport ? EncoderType.Hardware : EncoderType.Software;

            WebRTC.WebRTC.Initialize(encoderType);
            RemoteInput.Initialize();
            RemoteInput.ActionButtonClick = OnButtonClick;
        }
Esempio n. 4
0
        public static void Delete(RemoteInput remoteInput)
        {
            uint      userId        = s_mapRemoteInputAndInputUserId[remoteInput];
            InputUser user          = InputUser.all.First(_user => _user.id == userId);
            var       arrayDeviceId = user.pairedDevices.Select(device => device.deviceId).ToArray();

            user.UnpairDevicesAndRemoveUser();
            foreach (var deviceId in arrayDeviceId)
            {
                InputSystem.RemoveDevice(InputSystem.GetDeviceById(deviceId));
            }
            s_mapRemoteInputAndInputUserId.Remove(remoteInput);
            s_listRemoteInput.Remove(remoteInput);
        }
Esempio n. 5
0
        public static RemoteInput Create()
        {
            InputUser user = InputUser.CreateUserWithoutPairedDevices();

            user = InputUser.PerformPairingWithDevice(InputSystem.AddDevice <Mouse>(), user);
            user = InputUser.PerformPairingWithDevice(InputSystem.AddDevice <Keyboard>(), user);
            user = InputUser.PerformPairingWithDevice(InputSystem.AddDevice <Gamepad>(), user);
            user = InputUser.PerformPairingWithDevice(InputSystem.AddDevice <Touchscreen>(), user);
            RemoteInput remoteInput = new RemoteInput(ref user);

            s_mapRemoteInputAndInputUserId.Add(remoteInput, user.id);
            s_listRemoteInput.Add(remoteInput);

            return(remoteInput);
        }
        void OnDataChannel(RTCPeerConnection pc, RTCDataChannel channel)
        {
            Dictionary <int, RTCDataChannel> channels;

            if (!mapChannels.TryGetValue(pc, out channels))
            {
                channels = new Dictionary <int, RTCDataChannel>();
                mapChannels.Add(pc, channels);
            }
            channels.Add(channel.Id, channel);

            if (channel.Label == "data")
            {
                channel.OnMessage = new DelegateOnMessage(bytes => { RemoteInput.ProcessInput(bytes); });
                channel.OnClose   = new DelegateOnClose(() => { RemoteInput.Reset(); });
            }
        }
        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);
            }
        }
Esempio n. 8
0
        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);
            }
        }
        internal static void Delete(RemoteInput remoteInput)
        {
            if (remoteInput == null)
            {
                throw new ArgumentException("The instance of argument is null");
            }
            bool found = s_mapRemoteInputAndInputUserId.TryGetValue(remoteInput, out uint userId);

            if (!found)
            {
                throw new ArgumentException("The instance of argument is not found");
            }
            InputUser user          = InputUser.all.First(_user => _user.id == userId);
            var       arrayDeviceId = user.pairedDevices.Select(device => device.deviceId).ToArray();

            user.UnpairDevicesAndRemoveUser();
            foreach (var deviceId in arrayDeviceId)
            {
                InputSystem.RemoveDevice(InputSystem.GetDeviceById(deviceId));
            }
            s_mapRemoteInputAndInputUserId.Remove(remoteInput);
            s_listRemoteInput.Remove(remoteInput);
        }
 public void OnDestroy()
 {
     WebRTC.WebRTC.Finalize();
     RemoteInput.Destroy();
     Unity.WebRTC.Audio.Stop();
 }
 public void OnDestroy()
 {
     WebRTC.WebRTC.Dispose();
     RemoteInput.Destroy();
     Unity.WebRTC.Audio.Stop();
 }
 public void Awake()
 {
     WebRTC.WebRTC.Initialize();
     RemoteInput.Initialize();
     RemoteInput.ActionButtonClick = OnButtonClick;
 }
Esempio n. 13
0
 public void OnDestroy()
 {
     WebRTC.WebRTC.Finalize();
     RemoteInput.Destroy();
 }