diff --git a/Runtime/Scripts/DataStream.cs b/Runtime/Scripts/DataStream.cs index d2ef195a..8cfa5f1a 100644 --- a/Runtime/Scripts/DataStream.cs +++ b/Runtime/Scripts/DataStream.cs @@ -182,12 +182,10 @@ public ReadAllInstruction ReadAll() /// public sealed class ReadAllInstruction : YieldInstruction { - private ulong _asyncId; private string _text; internal ReadAllInstruction(ulong asyncId) { - _asyncId = asyncId; // ReadAll is modeled as a single async completion rather than a stream of // incremental events, so it uses the request_async_id pending map. Rust returns // the same value through callback.AsyncId. @@ -196,9 +194,6 @@ internal ReadAllInstruction(ulong asyncId) internal void OnReadAll(TextStreamReaderReadAllCallback e) { - if (e.AsyncId != _asyncId) - return; - switch (e.ResultCase) { case TextStreamReaderReadAllCallback.ResultOneofCase.Error: @@ -395,20 +390,15 @@ public WriteToFileInstruction WriteToFile(string directory = null, string nameOv /// public sealed class ReadAllInstruction : YieldInstruction { - private ulong _asyncId; private byte[] _bytes; internal ReadAllInstruction(ulong asyncId) { - _asyncId = asyncId; FfiClient.Instance.RegisterPendingCallback(asyncId, static e => e.ByteStreamReaderReadAll, OnReadAll, OnCanceled); } internal void OnReadAll(ByteStreamReaderReadAllCallback e) { - if (e.AsyncId != _asyncId) - return; - switch (e.ResultCase) { case ByteStreamReaderReadAllCallback.ResultOneofCase.Error: @@ -509,20 +499,15 @@ public byte[] Bytes /// public sealed class WriteToFileInstruction : YieldInstruction { - private ulong _asyncId; private string _filePath; internal WriteToFileInstruction(ulong asyncId) { - _asyncId = asyncId; FfiClient.Instance.RegisterPendingCallback(asyncId, static e => e.ByteStreamReaderWriteToFile, OnWriteToFile, OnCanceled); } internal void OnWriteToFile(ByteStreamReaderWriteToFileCallback e) { - if (e.AsyncId != _asyncId) - return; - switch (e.ResultCase) { case ByteStreamReaderWriteToFileCallback.ResultOneofCase.Error: diff --git a/Runtime/Scripts/Participant.cs b/Runtime/Scripts/Participant.cs index 078043b1..772016fe 100644 --- a/Runtime/Scripts/Participant.cs +++ b/Runtime/Scripts/Participant.cs @@ -594,13 +594,11 @@ internal RemoteParticipant(OwnedParticipant participant, Room room) : base(parti public sealed class PublishTrackInstruction : YieldInstruction { - private ulong _asyncId; private Dictionary _internalTracks; private ILocalTrack _localTrack; internal PublishTrackInstruction(ulong asyncId, ILocalTrack localTrack, Dictionary internalTracks) { - _asyncId = asyncId; _internalTracks = internalTracks; _localTrack = localTrack; // One-shot completion keyed by request_async_id. Concurrent requests simply occupy @@ -611,9 +609,6 @@ internal PublishTrackInstruction(ulong asyncId, ILocalTrack localTrack, Dictiona internal void OnPublish(PublishTrackCallback e) { - if (e.AsyncId != _asyncId) - return; - IsError = !string.IsNullOrEmpty(e.Error); IsDone = true; var publication = new LocalTrackPublication(e.Publication.Info); @@ -741,21 +736,15 @@ void OnCanceled() /// public sealed class PerformRpcInstruction : YieldInstruction { - private ulong _asyncId; private string _payload; internal PerformRpcInstruction(ulong asyncId) { - _asyncId = asyncId; FfiClient.Instance.RegisterPendingCallback(asyncId, static e => e.PerformRpc, OnRpcResponse, OnCanceled); } internal void OnRpcResponse(PerformRpcCallback e) { - if (e.AsyncId != _asyncId) - return; - - if (e.Error != null) { Error = RpcError.FromProto(e.Error); @@ -807,20 +796,15 @@ public string Payload /// public sealed class SendTextInstruction : YieldInstruction { - private ulong _asyncId; private TextStreamInfo _info; internal SendTextInstruction(ulong asyncId) { - _asyncId = asyncId; FfiClient.Instance.RegisterPendingCallback(asyncId, static e => e.SendText, OnSendText, OnCanceled); } internal void OnSendText(StreamSendTextCallback e) { - if (e.AsyncId != _asyncId) - return; - switch (e.ResultCase) { case StreamSendTextCallback.ResultOneofCase.Error: @@ -861,20 +845,15 @@ public TextStreamInfo Info /// public sealed class SendFileInstruction : YieldInstruction { - private ulong _asyncId; private ByteStreamInfo _info; internal SendFileInstruction(ulong asyncId) { - _asyncId = asyncId; FfiClient.Instance.RegisterPendingCallback(asyncId, static e => e.SendFile, OnSendFile, OnCanceled); } internal void OnSendFile(StreamSendFileCallback e) { - if (e.AsyncId != _asyncId) - return; - switch (e.ResultCase) { case StreamSendFileCallback.ResultOneofCase.Error: @@ -915,20 +894,15 @@ public ByteStreamInfo Info /// public sealed class StreamTextInstruction : YieldInstruction { - private ulong _asyncId; private TextStreamWriter _writer; internal StreamTextInstruction(ulong asyncId) { - _asyncId = asyncId; FfiClient.Instance.RegisterPendingCallback(asyncId, static e => e.TextStreamOpen, OnStreamOpen, OnCanceled); } internal void OnStreamOpen(TextStreamOpenCallback e) { - if (e.AsyncId != _asyncId) - return; - switch (e.ResultCase) { case TextStreamOpenCallback.ResultOneofCase.Error: @@ -969,20 +943,15 @@ public TextStreamWriter Writer /// public sealed class StreamBytesInstruction : YieldInstruction { - private ulong _asyncId; private ByteStreamWriter _writer; internal StreamBytesInstruction(ulong asyncId) { - _asyncId = asyncId; FfiClient.Instance.RegisterPendingCallback(asyncId, static e => e.ByteStreamOpen, OnStreamOpen, OnCanceled); } internal void OnStreamOpen(ByteStreamOpenCallback e) { - if (e.AsyncId != _asyncId) - return; - switch (e.ResultCase) { case ByteStreamOpenCallback.ResultOneofCase.Error: @@ -1023,20 +992,15 @@ public ByteStreamWriter Writer /// public sealed class PublishDataTrackInstruction : YieldInstruction { - private ulong _asyncId; private LocalDataTrack _track; internal PublishDataTrackInstruction(ulong asyncId) { - _asyncId = asyncId; FfiClient.Instance.RegisterPendingCallback(asyncId, static e => e.PublishDataTrack, OnPublishDataTrack, OnCanceled); } internal void OnPublishDataTrack(PublishDataTrackCallback e) { - if (e.AsyncId != _asyncId) - return; - switch (e.ResultCase) { case PublishDataTrackCallback.ResultOneofCase.Error: diff --git a/Runtime/Scripts/Room.cs b/Runtime/Scripts/Room.cs index 202fa600..dc74740e 100644 --- a/Runtime/Scripts/Room.cs +++ b/Runtime/Scripts/Room.cs @@ -593,13 +593,11 @@ internal Participant GetParticipant(string identity) public sealed class ConnectInstruction : YieldInstruction { - private ulong _asyncId; private Room _room; private RoomOptions _roomOptions; internal ConnectInstruction(ulong asyncId, Room room, RoomOptions options) { - _asyncId = asyncId; _room = room; _roomOptions = options; // Register before the request is sent so a fast native completion cannot race ahead @@ -610,9 +608,6 @@ internal ConnectInstruction(ulong asyncId, Room room, RoomOptions options) void OnConnect(ConnectCallback e) { - if (_asyncId != e.AsyncId) - return; - bool success = string.IsNullOrEmpty(e.Error); if (success) { diff --git a/Runtime/Scripts/Track.cs b/Runtime/Scripts/Track.cs index 91cc0608..397c2e60 100644 --- a/Runtime/Scripts/Track.cs +++ b/Runtime/Scripts/Track.cs @@ -171,13 +171,11 @@ internal RemoteVideoTrack(OwnedTrack track, Room room, RemoteParticipant partici public sealed class GetSessionStatsInstruction : YieldInstruction { - private readonly ulong _asyncId; public RtcStats[] Stats; public string Error; internal GetSessionStatsInstruction(ulong asyncId) { - _asyncId = asyncId; // This waiter is a one-shot response; cancellation and completion race through the // same pending entry, so only one path can finish the instruction. FfiClient.Instance.RegisterPendingCallback(asyncId, static e => e.GetStats, OnGetSessionStatsReceived, OnCanceled); @@ -185,9 +183,6 @@ internal GetSessionStatsInstruction(ulong asyncId) private void OnGetSessionStatsReceived(GetStatsCallback e) { - if (e.AsyncId != _asyncId) - return; - Error = e.Error; IsError = !string.IsNullOrEmpty(Error); IsDone = true;