microsoft / MixedReality-WebRTC

MixedReality-WebRTC is a collection of components to help mixed reality app developers integrate audio and video real-time communication into their application and improve their collaborative experience
https://microsoft.github.io/MixedReality-WebRTC/
MIT License
908 stars 282 forks source link

Unity PeerConnection AutoInitializeOnStart? #525

Open rygo6 opened 4 years ago

rygo6 commented 4 years ago

So I noticed in the code here: https://github.com/microsoft/MixedReality-WebRTC/blob/9d1b34cd2047c876fc5af250417114f450865b6b/libs/unity/library/Runtime/Scripts/PeerConnection.cs#L263

It says:

        /// This method must be called once before using the peer connection. If <see cref="AutoInitializeOnStart"/>
        /// is <c>true</c> then it is automatically called during <a href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.Start.html">MonoBehaviour.Start()</a>.

This implies to me there should be a serialized bool to enable/disable the auto calling of this method and that this method should be public. But the method is not public, and there is no way to enable/disable it from being called OnEnable.

Is this comment out of date? Or representative of an expected change? Because I actually need this functionality right now, for the purpose of restarting a PeerConnection.

Right now I assume I should make InitializeAsync and Uninitialize public. Add in a bool to disable InitializeAsync from being auto called from OnEnable. Then if I called Uninitialize followed by InitializeAsync it should reset the PeerConnection and start a new one. Is that a correct assumption?

djee-ms commented 4 years ago

The comment is out of date, the methods are correctly private, we do not support anymore manual init outside OnEnable/OnDisable, this was overly complex and partially broken, without any sensible way to fix. You do not need to do anything other than enable the component to initialize it and disable it to clean it up. I think you shouldn't need anything else to restart the connection than just do some:

pc.enabled = false;
pc.enabled = true;

@fibann has been recently working on this, including peer connection restart, and might shed more light on it, and/or correct me.

rygo6 commented 4 years ago

Thank you. That will work. A restart method would be probably be useful.