Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.
Merged
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
36 changes: 9 additions & 27 deletions src/FishyFlip/ATJetStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,44 +254,26 @@ private async Task ReceiveMessages(ClientWebSocket webSocket, CancellationToken
#if NETSTANDARD
var result =
await webSocket.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), token);
if (result.MessageType != messageType && !result.EndOfMessage)
{
continue;
}

byte[] newArray;
if (!this.compression)
{
newArray = new byte[result.Count];
Array.Copy(receiveBuffer, 0, newArray, 0, result.Count);
}
else
{
var receiveSpan = receiveBuffer.AsSpan(0, result.Count);
newArray = this.decompressor!.Unwrap(receiveSpan).ToArray();
}
#else
var result =
await webSocket.ReceiveAsync(new Memory<byte>(receiveBuffer), token);
#endif
if (result.MessageType != messageType && !result.EndOfMessage)
{
continue;
}

// Convert result to string
byte[] newArray;
if (!this.compression)
{
newArray = new byte[result.Count];
Array.Copy(receiveBuffer, 0, newArray, 0, result.Count);
}
else
ReadOnlySpan<byte> messageBytes = receiveBuffer.AsSpan(0, result.Count);
if (this.compression)
{
var receiveSpan = receiveBuffer.AsSpan(0, result.Count);
newArray = this.decompressor!.Unwrap(receiveSpan).ToArray();
messageBytes = this.decompressor!.Unwrap(messageBytes);
}

#if NETSTANDARD
var message = Encoding.UTF8.GetString(messageBytes.ToArray());
#else
var message = Encoding.UTF8.GetString(messageBytes);
#endif
var message = Encoding.UTF8.GetString(newArray);
this.OnRawMessageReceived?.Invoke(this, new JetStreamRawMessageEventArgs(message));
this.options.TaskFactory.StartNew(() => this.HandleMessage(message)).FireAndForgetSafeAsync(this.logger);
}
Expand Down