-
Notifications
You must be signed in to change notification settings - Fork 43
Description
Describe the bug
Messages/Events send to StreamDeckLib are not received completely (split in half), therefor json-Parsing fails and therefor the Event is missed. The resulting jsonString suddenly ends, the second half is received with the next ReceiveAsync.
To Reproduce
Difficult - modified & self compiled copy of StreamDeckLib. Roughly: compiled as .NET Framework, ConnectionManager.Run modified to repeatedly call my Code. On top of that, it only happens in some combination / quantity of my plugin-buttons.
Expected behavior
Receiving the whole Message / Event ;)
Proposed Fix
public async Task GetMessageAsString(CancellationToken token)
{
byte[] buffer = new byte[65536];
ArraySegment segment = new ArraySegment(buffer, 0, buffer.Length); ;
WebSocketReceiveResult result = new WebSocketReceiveResult(0, WebSocketMessageType.Text, false);
int totalCount = 0;
while (!result.EndOfMessage)
{
result = await _Socket.ReceiveAsync(segment, token);
totalCount += result.Count;
segment = new ArraySegment(buffer, totalCount, buffer.Length - totalCount);
}
string jsonString = Encoding.UTF8.GetString(buffer);
return jsonString;
}