/// <summary> /// Initiate a connection by having <see cref="Peer1"/> send an offer to <see cref="Peer2"/>, /// and wait until the SDP exchange completed. To wait for completion, use <see cref="WaitForConnection(int)"/> /// then check the value of <see cref="IsConnected"/> after that to determine if /// <see cref="WaitForConnection(int)"/> terminated due to the connection being established or /// if it timed out. /// </summary> /// <returns><c>true</c> if the exchange started successfully, or <c>false</c> otherwise.</returns> /// <seealso cref="Connect"/> public bool StartConnection() { EnsureIsMainAppThread(); _remoteApplied1.Reset(); _remoteApplied2.Reset(); IsConnected = false; return(Peer1.StartConnection()); }
/// <inheritdoc/> protected override void Update() { // Do not forget to call the base class Update(), which processes events from background // threads to fire the callbacks implemented in this class. base.Update(); if (startConnection) { PeerConnection.StartConnection(); _nativePeer.RenegotiationNeeded += Connection_RenegotiationNeeded; _nativePeer.IceGatheringStateChanged += Connection_IceGatheringStateChanged; _nativePeer.IceStateChanged += Connection_IceStateChanged; startConnection = false; } //if there's a pending sdpanswer, then connect and consume it if (sdpAnswer != null) { //PeerConnection.HandleConnectionMessageAsync(sdpAnswer); // If i call this I publish my video but I'm not able to subscribe long i = idMessage++; // follow with a ReceiveVideoFrom on RPC RemotePeerId = joinRoomAnswer.result.value[0].id; string message = "{\"jsonrpc\": \"2.0\"," + "\"method\": \"receiveVideoFrom\"," + "\"params\": { \"sender\": \"" + joinRoomAnswer.result.value[0].streams[0].Id + "\"" + ",\"sdpOffer\": \"" + lastOffer.Content + "\"" + "},\"id\": " + i + " }"; Debug.Log("ReceiveVideoFrom : " + message); webSocket.SendText(message); messages.Add(i, OpenViduType.ReceiveVideoFrom); sdpAnswer = null; } // If we have not reached our PollTimeMs value... if (timeSincePollMs <= PollTimeMs) { // ...then we keep incrementing our local counter until we do. timeSincePollMs += Time.deltaTime * 1000.0f; return; } // If we have a pending request still going, don't queue another yet. if (!lastGetComplete) { return; } // When we have reached our PollTimeMs value... timeSincePollMs = 0f; // ...begin the poll and process. lastGetComplete = false; Ping(); }