/// <summary>
        /// Handler of call events.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Call_CallEvent(object sender, CallEventArgs e)
        {
            switch (e.Type)
            {
            case CallEventType.CallAccepted:
                //Outgoing call was successful or an incoming call arrived
                Append("Connection established");
                OnNewCall(e as CallAcceptedEventArgs);
                break;

            case CallEventType.CallEnded:
                OnCallEnded(e as CallEndedEventArgs);
                break;

            case CallEventType.ListeningFailed:
                Append("Failed to listen for incoming calls! Server might be down!");
                ResetCall();
                break;

            case CallEventType.ConnectionFailed:
            {
                //this should be impossible to happen in conference mode!
                Byn.Media.ErrorEventArgs args = e as Byn.Media.ErrorEventArgs;
                Append("Error: " + args.ErrorMessage);
                Debug.LogError(args.ErrorMessage);
                ResetCall();
            }
            break;

            case CallEventType.FrameUpdate:
                //new frame received from webrtc (either from local camera or network)
                FrameUpdateEventArgs frameargs = e as FrameUpdateEventArgs;
                UpdateFrame(frameargs.ConnectionId, frameargs.Frame);
                break;

            case CallEventType.Message:
            {
                //text message received
                MessageEventArgs args = e as MessageEventArgs;
                Append(args.Content);
                break;
            }

            case CallEventType.WaitForIncomingCall:
            {
                //the chat app will wait for another app to connect via the same string
                WaitForIncomingCallEventArgs args = e as WaitForIncomingCallEventArgs;
                Append("Waiting for incoming call address: " + args.Address);
                break;
            }
            }
        }
Exemple #2
0
    private void HandleCallEvent(object sender, CallEventArgs e)
    {
        switch (e.Type)
        {
        case CallEventType.CallAccepted: {
            ConnectionId connID = ((CallAcceptedEventArgs)e).ConnectionId;
            DebugLog.AddEntry("CallAccepted: " + connID);
            Globals.therapistOnlyTesting = false;
            // send intial state when clients are accepted
            // note that this even is received when clients
            // are connected to the server so we need to filter
            // out CallAccepted events which are the server
            if (Globals.role == Role.Therapist)
            {
                SendMessage(new SystemMessage(0, AppActions.Login), false);
                SendInitialState();
            }
            SetStatusMessageText("");
            break;
        }

        case CallEventType.CallEnded: {
            ConnectionId connID = ((CallEndedEventArgs)e).ConnectionId;
            DebugLog.AddEntry("CallEnded: " + connID);
            if (currentApp != null)
            {
                currentApp.Disconnect();
                if (Globals.role == Role.Patient)
                {
                    CloseCurrentApp();
                }
            }
            remoteVideo.GetComponent <UITexture>().mainTexture = null;
            Disconnect();
            Connect();
            break;
        }

        case CallEventType.ListeningFailed: {
            ErrorEventArgs args = e as ErrorEventArgs;
            // TODO: when do we get this? if the network is down show an error
            DebugLog.AddEntry("ListeningFailed");
            // Globals.FatalError("Listening failed. Is another server running?");
            SetStatusMessageText("Listening failed (" + args.ErrorMessage + ")");
            break;
        }

        case CallEventType.ConnectionFailed: {
            ErrorEventArgs args = e as ErrorEventArgs;
            DebugLog.AddEntry("Connection failed error: " + args.ErrorMessage);
            SetStatusMessageText("Connection failed (" + args.ErrorMessage + ")");
            if (Globals.role == Role.Patient)
            {
                Invoke("Reconnect", CLIENT_RETRY_DELAY);
            }
            else
            {
                // does this ever happen to the server?
                Globals.FatalError("ConnectionFailed!");
            }
            break;
        }

        case CallEventType.ConfigurationFailed: {
            ErrorEventArgs args = e as ErrorEventArgs;
            DebugLog.AddEntry("Configuration failed error: " + args.ErrorMessage);
            Disconnect();
            break;
        }

        case CallEventType.FrameUpdate: {
            if (e is FrameUpdateEventArgs)
            {
                UpdateFrame((FrameUpdateEventArgs)e);
            }
            break;
        }

        case CallEventType.DataMessage: {
            var args = e as DataMessageEventArgs;
            HandleMessage(args.Content);
            break;
        }

        // case CallEventType.Message: {
        //   MessageEventArgs args = e as MessageEventArgs;
        //   HandleSystemMessage(args.Content);
        //   break;
        // }

        case CallEventType.WaitForIncomingCall: {
            WaitForIncomingCallEventArgs args = e as WaitForIncomingCallEventArgs;
            // the server is connected so present the gui
            SetGUIVisible(true);
            // if there is an app already open the pass the new caller
            if (currentApp != null)
            {
                currentApp.Reconnect(caller);
            }
            break;
        }
        }
    }
Exemple #3
0
    /// <summary>
    /// Handler of call events.
    ///
    /// Can be customized in via subclasses.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected virtual void Call_CallEvent(object sender, CallEventArgs e)
    {
        switch (e.Type)
        {
        case CallEventType.CallAccepted:
            //Outgoing call was successful or an incoming call arrived
            Append("Connection established");
            mRemoteUserId = ((CallAcceptedEventArgs)e).ConnectionId;
            Debug.Log("New connection with id: " + mRemoteUserId
                      + " audio:" + mCall.HasAudioTrack(mRemoteUserId)
                      + " video:" + mCall.HasVideoTrack(mRemoteUserId));
            break;

        case CallEventType.CallEnded:
            //Call was ended / one of the users hung up -> reset the app
            Append("Call ended");
            InternalResetCall();
            break;

        case CallEventType.ListeningFailed:
            //listening for incoming connections failed
            //this usually means a user is using the string / room name already to wait for incoming calls
            //try to connect to this user
            //(note might also mean the server is down or the name is invalid in which case call will fail as well)
            mCall.Call(mUseAddress);
            break;

        case CallEventType.ConnectionFailed:
        {
            Byn.Media.ErrorEventArgs args = e as Byn.Media.ErrorEventArgs;
            Append("Connection failed error: " + args.ErrorMessage);
            InternalResetCall();
        }
        break;

        case CallEventType.ConfigurationFailed:
        {
            Byn.Media.ErrorEventArgs args = e as Byn.Media.ErrorEventArgs;
            Append("Configuration failed error: " + args.ErrorMessage);
            InternalResetCall();
        }
        break;

        case CallEventType.FrameUpdate:
        {
            //new frame received from webrtc (either from local camera or network)
            if (e is FrameUpdateEventArgs)
            {
                UpdateFrame((FrameUpdateEventArgs)e);
            }
            break;
        }

        case CallEventType.Message:
        {
            //text message received
            MessageEventArgs args = e as MessageEventArgs;
            Append(args.Content);
            break;
        }

        case CallEventType.WaitForIncomingCall:
        {
            //the chat app will wait for another app to connect via the same string
            WaitForIncomingCallEventArgs args = e as WaitForIncomingCallEventArgs;
            Append("Waiting for incoming call address: " + args.Address);
            break;
        }
        }
    }
    /// <summary>
    /// Handler of call events.
    ///
    /// Can be customized in via subclasses.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected virtual void Call_CallEvent(object sender, CallEventArgs e)
    {
        switch (e.Type)
        {
        case CallEventType.CallAccepted:
            //Outgoing call was successful or an incoming call arrived
            Append("Connection established");
            mRemoteUserId = ((CallAcceptedEventArgs)e).ConnectionId;
            Debug.Log("New connection with id: " + mRemoteUserId
                      + " audio:" + mCall.HasAudioTrack(mRemoteUserId)
                      + " video:" + mCall.HasVideoTrack(mRemoteUserId));
            break;

        case CallEventType.CallEnded:
            //Call was ended / one of the users hung up -> reset the app
            Append("Call ended");
            InternalResetCall();
            break;

        case CallEventType.ListeningFailed:
            //listening for incoming connections failed
            //this usually means a user is using the string / room name already to wait for incoming calls
            //try to connect to this user
            //(note might also mean the server is down or the name is invalid in which case call will fail as well)
            mCall.Call(mUseAddress);
            break;

        case CallEventType.ConnectionFailed:
        {
            Byn.Media.ErrorEventArgs args = e as Byn.Media.ErrorEventArgs;
            Append("Connection failed error: " + args.ErrorMessage);
            InternalResetCall();
        }
        break;

        case CallEventType.ConfigurationFailed:
        {
            Byn.Media.ErrorEventArgs args = e as Byn.Media.ErrorEventArgs;
            Append("Configuration failed error: " + args.ErrorMessage);
            InternalResetCall();
        }
        break;

        case CallEventType.FrameUpdate:
        {
            //new frame received from webrtc (either from local camera or network)
            if (e is FrameUpdateEventArgs)
            {
                UpdateFrame((FrameUpdateEventArgs)e);
            }
            break;
        }

        case CallEventType.Message:
        {
            //text message received
            MessageEventArgs args = e as MessageEventArgs;
            //Append(args.Content);
            // Debug.Log("Recieved: " + args.Content);
            //HandData data = JsonConvert.DeserializeObject<HandData>(args.Content);
            HandData data = JsonUtility.FromJson <HandData>(args.Content);
            //byte[] buffer = System.Text.Encoding.UTF8.GetBytes(args.Content);
            //HandData data = MessagePackSerializer.Deserialize<HandData>(buffer);
//                    if (data.IsRightHand) RemoteHandHold.RightHandDatas.Add(data);

            if (RemoteHead != null)
            {
                // RemoteHead.transform.position = data.HeadPosition;
                RemoteHead.transform.eulerAngles = data.HeadEulerAngles;
            }

            //if (RemoteHand != null)
            //{
            //    RemoteHand.transform.localPosition = data.LeapHand.PalmPosition.ToVector3();
            //}
            //if (IsLeftHand)
            //{
            //    RemotePalmL.transform.localPosition = data.LeapHand.PalmPosition.ToVector3();
            //    RemoteThumbL.transform.localPosition = data.LeapHand.GetThumb().TipPosition.ToVector3();
            //    RemoteIndexL.transform.localPosition = data.LeapHand.GetIndex().TipPosition.ToVector3();
            //    RemoteMiddleL.transform.localPosition = data.LeapHand.GetMiddle().TipPosition.ToVector3();
            //    RemoteRingL.transform.localPosition = data.LeapHand.GetRing().TipPosition.ToVector3();
            //    RemotePinkyL.transform.localPosition = data.LeapHand.GetPinky().TipPosition.ToVector3();
            //}
            //else
            //{
            //    RemotePalmR.transform.localPosition = data.LeapHand.PalmPosition.ToVector3();
            //    RemoteThumbR.transform.localPosition = data.LeapHand.GetThumb().TipPosition.ToVector3();
            //    RemoteIndexR.transform.localPosition = data.LeapHand.GetIndex().TipPosition.ToVector3();
            //    RemoteMiddleR.transform.localPosition = data.LeapHand.GetMiddle().TipPosition.ToVector3();
            //    RemoteRingR.transform.localPosition = data.LeapHand.GetRing().TipPosition.ToVector3();
            //    RemotePinkyR.transform.localPosition = data.LeapHand.GetPinky().TipPosition.ToVector3();
            //}

            RemotePalm.transform.localPosition   = data.PalmPosition;
            RemoteThumb.transform.localPosition  = data.ThumbPosition;
            RemoteIndex.transform.localPosition  = data.IndexPosition;
            RemoteMiddle.transform.localPosition = data.MiddlePosition;
            RemoteRing.transform.localPosition   = data.RingPosition;
            RemotePinky.transform.localPosition  = data.PinkyPosition;

            Debug.Log("RemotePalm: " + RemotePalm.transform.localPosition);

            if (!effectsManager.isMaster)
            {
                effectsManager.fader           = data.FaderValue;
                effectsManager.strengthControl = data.StrengthValue;
            }

            break;
        }

        case CallEventType.WaitForIncomingCall:
        {
            //the chat app will wait for another app to connect via the same string
            WaitForIncomingCallEventArgs args = e as WaitForIncomingCallEventArgs;
            Append("Waiting for incoming call address: " + args.Address);
            break;
        }
        }
    }