Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions Runtime/Scripts/DataStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,10 @@ public ReadAllInstruction ReadAll()
/// </remarks>
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.
Expand All @@ -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:
Expand Down Expand Up @@ -395,20 +390,15 @@ public WriteToFileInstruction WriteToFile(string directory = null, string nameOv
/// </remarks>
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:
Expand Down Expand Up @@ -509,20 +499,15 @@ public byte[] Bytes
/// </remarks>
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:
Expand Down
36 changes: 0 additions & 36 deletions Runtime/Scripts/Participant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,11 @@ internal RemoteParticipant(OwnedParticipant participant, Room room) : base(parti

public sealed class PublishTrackInstruction : YieldInstruction
{
private ulong _asyncId;
private Dictionary<string, TrackPublication> _internalTracks;
private ILocalTrack _localTrack;

internal PublishTrackInstruction(ulong asyncId, ILocalTrack localTrack, Dictionary<string, TrackPublication> internalTracks)
{
_asyncId = asyncId;
_internalTracks = internalTracks;
_localTrack = localTrack;
// One-shot completion keyed by request_async_id. Concurrent requests simply occupy
Expand All @@ -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);
Expand Down Expand Up @@ -741,21 +736,15 @@ void OnCanceled()
/// </remarks>
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);
Expand Down Expand Up @@ -807,20 +796,15 @@ public string Payload
/// </remarks>
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:
Expand Down Expand Up @@ -861,20 +845,15 @@ public TextStreamInfo Info
/// </remarks>
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:
Expand Down Expand Up @@ -915,20 +894,15 @@ public ByteStreamInfo Info
/// </remarks>
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:
Expand Down Expand Up @@ -969,20 +943,15 @@ public TextStreamWriter Writer
/// </remarks>
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:
Expand Down Expand Up @@ -1023,20 +992,15 @@ public ByteStreamWriter Writer
/// </remarks>
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:
Expand Down
5 changes: 0 additions & 5 deletions Runtime/Scripts/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand Down
5 changes: 0 additions & 5 deletions Runtime/Scripts/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,18 @@ 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);
}

private void OnGetSessionStatsReceived(GetStatsCallback e)
{
if (e.AsyncId != _asyncId)
return;

Error = e.Error;
IsError = !string.IsNullOrEmpty(Error);
IsDone = true;
Expand Down
Loading