/// <summary>
            /// Sets the track of the video sink.
            /// </summary>
            /// <param name="track">The track to use.</param>
            /// <returns>
            /// MLResult.Result will be <c>MLResult.Code.Ok</c> if destroying all handles was successful.
            /// MLResult.Result will be <c>MLResult.Code.WebRTCResultInstanceNotCreated</c> if MLWebRTC instance was not created.
            /// MLResult.Result will be <c>MLResult.Code.WebRTCResultMismatchingHandle</c> if an incorrect handle was sent.
            /// </returns>
            protected override MLResult SetTrack(MediaStream.Track track)
            {
#if PLATFORM_LUMIN
                ulong         sourceHandle = track != null ? track.Handle : MagicLeapNativeBindings.InvalidHandle;
                MLResult.Code resultCode   = NativeBindings.MLWebRTCVideoSinkSetSource(this.Handle, sourceHandle);
                DidNativeCallSucceed(resultCode, "MLWebRTCVideoSinkSetSource()");
                return(MLResult.Create(resultCode));
#else
                return(new MLResult());
#endif
            }
        /// <summary>
        /// Calls Disconnect(), destroys the WebRTC sinks and WebRTC instance.
        /// </summary>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if destroying all handles was successful.
        /// MLResult.Result will be <c>MLResult.Code.WebRTCResultInstanceNotCreated</c> if MLWebRTC instance was not created.
        /// MLResult.Result will be <c>MLResult.Code.WebRTCResultMismatchingHandle</c> if an incorrect handle was sent.
        /// </returns>
        protected override MLResult.Code StopAPI()
        {
            // Destroy connections.
            PeerConnection[] remainingConnections = new PeerConnection[connections.Count];
            // PeerConnection.Destroy() removes the connection from Instance.connections list.
            connections.CopyTo(remainingConnections);
            foreach (PeerConnection connection in remainingConnections)
            {
                connection.Destroy();
            }

            // Destroy sinks.
            Sink[] remainingSinks = new Sink[sinks.Count];
            // Sink.Destroy() removes the sink from Instance.sinks list.
            sinks.CopyTo(remainingSinks);
            foreach (Sink sink in remainingSinks)
            {
                sink.Destroy();
            }

            // Destroy local tracks.
            MediaStream.Track[] remainingTracks = new MediaStream.Track[localTracks.Count];
            // MediaStream.Track.Destroy() removes the track from Instance.localTracks list.
            localTracks.CopyTo(remainingTracks);
            foreach (MediaStream.Track localTracks in remainingTracks)
            {
                localTracks.DestroyLocal();
            }

            Instance.connections.Clear();
            Instance.sinks.Clear();
            Instance.localTracks.Clear();

            MLResult.Code resultCode = NativeBindings.MLWebRTCInstanceDestroy();
            return(resultCode);
        }