/// <summary> /// Init process. Sets configuration and triggers the connection process /// </summary> /// <returns> /// Returns IEnumerator so unity treats it as a Coroutine /// </returns> private IEnumerator Start() { if (sAddress == null) { //to avoid the awkward moment of connecting two random users who test this package //we use a randomized addresses now to connect only the local test Apps ;) sAddress = "OneToManyTest_" + Random.Range(0, 1000000); } if (UnityCallFactory.Instance == null) { Debug.LogError("No access to webrtc. "); } else { UnityCallFactory.Instance.RequestLogLevel(UnityCallFactory.LogLevel.Info); //Factory works. Prepare Peers NetworkConfig config = new NetworkConfig(); config.IceServers.Add(new IceServer(mStunServer)); config.SignalingUrl = mSignalingServer; mMediaNetwork = UnityCallFactory.Instance.CreateMediaNetwork(config); //keep track of multiple local instances for testing. mIndex = sInstances; sInstances++; Debug.Log("Instance " + mIndex + " created."); if (uSender) { //sender will broadcast audio and video mMediaConfig.Audio = true; mMediaConfig.Video = true; Debug.Log("Accepting incoming connections on " + sAddress); mMediaNetwork.Configure(mMediaConfig); mMediaNetwork.StartServer(sAddress); } else { //this one will just receive (but could also send if needed) mMediaConfig.Audio = false; mMediaConfig.Video = false; mMediaNetwork.Configure(mMediaConfig); } //wait a while before trying to connect othe sender //so it has time to register at the signaling server yield return(new WaitForSeconds(5)); if (uSender == false) { Debug.Log("Tring to connect to " + sAddress); mMediaNetwork.Connect(sAddress); } } }
private void OnDestroy() { //Destroy the network if (mMediaNetwork != null) { mMediaNetwork.Dispose(); mMediaNetwork = null; Debug.Log("Instance " + mIndex + " destroyed."); } }
private void SenderSetup() { //STEP4: receiver is ready -> start the sender Debug.Log("sender setup"); sender = UnityCallFactory.Instance.CreateMediaNetwork(netConf); MediaConfig mediaConf2 = new MediaConfig(); mediaConf2.Video = false; mediaConf2.Audio = true; sender.Configure(mediaConf2); }
private void SetupReceiver() { //STEP2: Setup the receiver. See UpdateReceiver() for event handling Debug.Log("receiver setup"); MediaConfig mediaConf1 = new MediaConfig(); //first one only receives mediaConf1.Video = false; mediaConf1.Audio = false; receiver = UnityCallFactory.Instance.CreateMediaNetwork(netConf); receiver.Configure(mediaConf1); }
private void OnDestroy() { if (receiver != null) { receiver.Dispose(); receiver = null; } if (sender != null) { sender.Dispose(); sender = null; } }