/// <summary> /// Setting up the sender. This is called once the receiver is registered /// at the signaling server and is ready to receive an incoming connection. /// </summary> private void SenderSetup() { //STEP5: sending up the sender Debug.Log("sender setup"); sender = UnityCallFactory.Instance.Create(netConf); MediaConfig mediaConf2 = new MediaConfig(); //keep video = false for now to keep the example simple & without UI mediaConf2.Video = false; //send audio. an echo will be heard to confirm it works mediaConf2.Audio = true; sender.CallEvent += Sender_CallEvent; //Set the configuration. It will trigger an ConfigurationComplete // event once completed or ConnectionFailed if something went wrong. // //Note: platforms handle this very differently e.g. // * Windows & Mac will access the media devices and immediately trigger // ConfigurationComplete event // * iOS and Android might ask the user first for permission // (or crash the app if it isn't allowed to access! Check your // Unity project setup!) // * WebGL behavior is browser specific. Currently, Chrome has a fixed // audio & video device configured and just asks for access while // firefox lets the user decide which device to use once Configure is // called. // See Receiver_CallEvent for next step sender.Configure(mediaConf2); }
/// <summary> /// Creates the call object and uses the configure method to activate the /// video / audio support if the values are set to true. /// </summary> /// <param name="useAudio">Uses the local microphone for the call</param> /// <param name="useVideo">Uses a local camera for the call. The camera will start /// generating new frames after this call so the user can see himself before /// the call is connected.</param> private void Setup(bool useAudio = true, bool useVideo = true) { Append("Setting up ..."); //setup the server NetworkConfig netConfig = new NetworkConfig(); netConfig.IceServers.Add(mIceServer); netConfig.SignalingUrl = mSignalingUrl; netConfig.IsConference = true; mCall = UnityCallFactory.Instance.Create(netConfig); if (mCall == null) { Append("Failed to create the call"); return; } Append("Call created!"); mCall.CallEvent += Call_CallEvent; //setup local video element SetupVideoUi(ConnectionId.INVALID); mCall.Configure(config); SetGuiState(false); }
/// <summary> /// This is setting the media used for this call. /// </summary> public void Configure() { //STEP2: configure media devices MediaConfig mediaConfig = new MediaConfig(); if (_Sender) { //sender is sending audio and video mediaConfig.Audio = true; mediaConfig.Video = true; //We ask for 320x240 (should work fine //even on the weakest systems) //note that not all devices can actually //deliver the resolution we ask for mediaConfig.IdealWidth = 320; mediaConfig.IdealHeight = 240; } else { //set to false to avoid //echo & multiple calls trying to access the same camera mediaConfig.Audio = false; mediaConfig.Video = false; } mCall.Configure(mediaConfig); mState = SimpleCallState.Config; Log("Configure media devices"); }
/// <summary> /// Creates the call object and uses the configure method to activate the /// video / audio support if the values are set to true. /// </summary> /// generating new frames after this call so the user can see himself before /// the call is connected.</param> public virtual void SetupCall() { Append("Setting up ..."); //hacks to turn off certain connection types. If both set to true only //turn servers are used. This helps simulating a NAT that doesn't support //opening ports. //hack to turn off direct connections //Byn.Net.Native.AWebRtcPeer.sDebugIgnoreTypHost = true; //hack to turn off connections via stun servers //Byn.Net.Native.WebRtcDataPeer.sDebugIgnoreTypSrflx = true; NetworkConfig netConfig = CreateNetworkConfig(); Debug.Log("Creating call using NetworkConfig:" + netConfig); //setup the server mCall = UnityCallFactory.Instance.Create(netConfig); if (mCall == null) { Append("Failed to create the call"); return; } mCall.LocalFrameEvents = mLocalFrameEvents; string[] devices = UnityCallFactory.Instance.GetVideoDevices(); if (devices == null || devices.Length == 0) { Debug.Log("no device found or no device information available"); } else { foreach (string s in devices) { Debug.Log("device found: " + s); } } Append("Call created!"); mCall.CallEvent += Call_CallEvent; //this happens in awake now to allow an ui or other external app //to change media config before calling SetupCall //mMediaConfig = CreateMediaConfig(); //make a deep clone to avoid confusion if settings are changed //at runtime. mMediaConfigInUse = mMediaConfig.DeepClone(); Debug.Log("Configure call using MediaConfig: " + mMediaConfigInUse); mCall.Configure(mMediaConfigInUse); mUi.SetGuiState(false); if (mBlockSleep) { //backup sleep timeout and set it to never sleep mSleepTimeoutBackup = Screen.sleepTimeout; Screen.sleepTimeout = SleepTimeout.NeverSleep; } }
/// <summary> /// Creates the call object and uses the configure method to activate the /// video / audio support if the values are set to true. /// generating new frames after this call so the user can see himself before /// the call is connected. /// </summary> public virtual void SetupCall() { Append("Setting up ..."); //hacks to turn off certain connection types. If both set to true only //turn servers are used. This helps simulating a NAT that doesn't support //opening ports. //hack to turn off direct connections //Byn.Net.Native.AWebRtcPeer.sDebugIgnoreTypHost = true; //hack to turn off connections via stun servers //Byn.Net.Native.WebRtcDataPeer.sDebugIgnoreTypSrflx = true; NetworkConfig netConfig = CreateNetworkConfig(); Debug.Log("Creating call using NetworkConfig:" + netConfig); //setup the server mCall = UnityCallFactory.Instance.Create(netConfig); if (mCall == null) { Append("Failed to create the call"); return; } mCall.LocalFrameEvents = mLocalFrameEvents; string[] devices = UnityCallFactory.Instance.GetVideoDevices(); if (devices == null || devices.Length == 0) { Debug.Log("no device found or no device information available"); } else { foreach (string s in devices) { Debug.Log("device found: " + s + " IsFrontFacing: " + UnityCallFactory.Instance.IsFrontFacing(s)); } } Append("Call created!"); mCall.CallEvent += Call_CallEvent; //make a deep clone to avoid confusion if settings are changed //at runtime. mMediaConfigInUse = mMediaConfig.DeepClone(); //try to pick a good default video device if the user wants to send video but //didn't bother to pick a specific device if (mMediaConfigInUse.Video && string.IsNullOrEmpty(mMediaConfigInUse.VideoDeviceName)) { mMediaConfigInUse.VideoDeviceName = UnityCallFactory.Instance.GetDefaultVideoDevice(); } Debug.Log("Configure call using MediaConfig: " + mMediaConfigInUse); mCall.Configure(mMediaConfigInUse); mUi.SetGuiState(false); }
/// <summary> /// Setting up the sender. This is called once the receiver is registered /// at the signaling server and is ready to receive an incoming connection. /// </summary> private void SenderSetup() { if (sender != null) { sender.Dispose(); sender = null; } Debug.Log("sender: setup"); sender = UnityCallFactory.Instance.Create(BenchmarkConfig.NetConfig); MediaConfig mediaConf2 = new MediaConfig(); mediaConf2.Video = false; mediaConf2.Audio = false; sender.CallEvent += Sender_CallEvent; sender.Configure(mediaConf2); }
private void SetupEcho() { if (echo != null) { echo.Dispose(); echo = null; } Debug.Log("echo setup"); MediaConfig mediaConf1 = new MediaConfig(); mediaConf1.Video = false; mediaConf1.Audio = false; //this creates the receiver echo = UnityCallFactory.Instance.Create(BenchmarkConfig.NetConfig); echo.CallEvent += Echo_CallEvent; echo.Configure(mediaConf1); }
private void SetupReceiver() { //STEP2: Setup and create the receiver call Debug.Log("receiver setup"); //receiver doesn't use video and audio MediaConfig mediaConf1 = new MediaConfig(); mediaConf1.Video = false; mediaConf1.Audio = false; //this creates the receiver receiver = UnityCallFactory.Instance.Create(netConf); //register our event handler. This is used to control all //further interaction with the call object later receiver.CallEvent += Receiver_CallEvent; //Ask for permission to access the media //(will always work as both is set to false) //See Receiver_CallEvent for next step receiver.Configure(mediaConf1); }
private void Connect() { DebugLog.AddEntry("connecting..."); // create network config if (networkConfig == null) { networkConfig = CreateNetworkConfig(account); } // setup caller caller = UnityCallFactory.Instance.Create(networkConfig); if (caller == null) { Debug.Log("Failed to create caller"); return; } caller.LocalFrameEvents = true; caller.CallEvent += HandleCallEvent; // setup media config if (mediaConfig == null) { mediaConfig = CreateMediaConfig(); // prefer the external video device if (UnityCallFactory.Instance.CanSelectVideoDevice()) { string[] videoDevices = UnityCallFactory.Instance.GetVideoDevices(); // show all video device names for (int i = 0; i < videoDevices.Length; i++) { var name = videoDevices[i]; DebugLog.AddEntry("video device #" + i + ": " + name); } var preferredDevice = PlayerPrefs.GetInt(PREFS.VIDEO_DEVICE); if (preferredDevice < videoDevices.Length) { mediaConfig.VideoDeviceName = videoDevices[preferredDevice]; } else { // use defualt device if the preferred device is out of range mediaConfig.VideoDeviceName = videoDevices[0]; } } else { mediaConfig.VideoDeviceName = UnityCallFactory.Instance.GetDefaultVideoDevice(); } DebugLog.AddEntry("Using video device: " + mediaConfig.VideoDeviceName); } caller.Configure(mediaConfig); // start listening... if (Globals.role == Role.Therapist) { DebugLog.AddEntry("server listening for connections on " + account.address + "..."); SetStatusMessageText("Listening for connections on " + account.address + "..."); caller.Listen(account.address); } else { DebugLog.AddEntry("client connecting to " + account.address + "..."); SetStatusMessageText("Connecting to " + account.address + "..."); caller.Call(account.address); } }