Ejemplo n.º 1
0
        /// <summary>
        /// Keep updating the network and handle all events.
        /// </summary>
        void Update()
        {
            if (mMediaNetwork == null)
            {
                return;
            }
            mMediaNetwork.Update();

            //This is the event handler via polling.
            //This needs to be called or the memory will fill up with unhanded events!
            NetworkEvent evt;

            while (mMediaNetwork != null && mMediaNetwork.Dequeue(out evt))
            {
                HandleNetworkEvent(evt);
            }
            //polls for video updates
            HandleMediaEvents();

            //Flush will resync changes done in unity to the native implementation
            //(and possibly drop events that aren't handled in the future)
            if (mMediaNetwork != null)
            {
                mMediaNetwork.Flush();
            }
        }
Ejemplo n.º 2
0
        private void UpdateReceiver()
        {
            //STEP3: Updating the receiver. Will be called ever frame
            //IMediaNetwork uses polling instead of events
            receiver.Update();

            //check if the configuration state changed
            if (receiver.GetConfigurationState() == MediaConfigurationState.Failed)
            {
                //did configuration fail? error
                Debug.Log("receiver configuration failed " + receiver.GetConfigurationError());
                receiver.ResetConfiguration();
            }
            else if (receiver.GetConfigurationState() == MediaConfigurationState.Successful &&
                     mReceiverConfigured == false)
            {
                //configuration successful.
                mReceiverConfigured = true;
                //StartServer corresponds to ICall.Listen
                receiver.StartServer(address);
            }

            //Dequeue network events
            NetworkEvent evt;

            while (receiver.Dequeue(out evt))
            {
                if (evt.Type == NetEventType.ServerInitialized)
                {
                    //triggered if StartServer completed
                    Debug.Log("receiver: server initialized.");
                    //receiver is ready -> create sender
                    SenderSetup();
                }
                else if (evt.Type == NetEventType.ServerInitFailed)
                {
                    //either network problem or address in use
                    Debug.LogError("receiver: server init failed");
                }
                else if (evt.Type == NetEventType.NewConnection)
                {
                    //triggered if a new connection is established
                    Debug.Log("receiver: New connection with id " + evt.ConnectionId);
                }
            }
            receiver.Flush();
        }
Ejemplo n.º 3
0
        private void UpdateSender()
        {
            //STEP5: Sender update loop. Same as receiver but is calling Connect
            //once configure completed.
            sender.Update();

            NetworkEvent evt;

            if (sender.GetConfigurationState() == MediaConfigurationState.Failed)
            {
                //did configuration fail? error
                Debug.Log("sender configuration failed " + sender.GetConfigurationError());
                sender.ResetConfiguration();
            }
            else if (sender.GetConfigurationState() == MediaConfigurationState.Successful &&
                     mSenderConfigured == false)
            {
                mSenderConfigured = true;

                //connecting to to the receiver
                sender.Connect(address);
            }

            while (sender.Dequeue(out evt))
            {
                if (evt.Type == NetEventType.NewConnection)
                {
                    Debug.Log("sender: New connection with id " + evt.ConnectionId);
                }
                else if (evt.Type == NetEventType.ConnectionFailed)
                {
                    Debug.LogError("sender: connection failed");
                }
            }
            sender.Flush();
        }