| 1480 | } |
| 1481 | |
| 1482 | Result HttpWebSocketSmallHub::broadcastFrame(Span<const char> encodedFrame) |
| 1483 | { |
| 1484 | SC_TRY_MSG(not encodedFrame.empty(), "HttpWebSocketSmallHub cannot broadcast an empty frame"); |
| 1485 | for (size_t idx = 0; idx < clients.sizeInElements(); ++idx) |
| 1486 | { |
| 1487 | HttpWebSocketHubClient& client = clients[idx]; |
| 1488 | if (not client.active) |
| 1489 | { |
| 1490 | continue; |
| 1491 | } |
| 1492 | if (onBroadcastFrame.isValid()) |
| 1493 | { |
| 1494 | SC_TRY(onBroadcastFrame(idx, encodedFrame)); |
| 1495 | continue; |
| 1496 | } |
| 1497 | |
| 1498 | AsyncBufferView::ID bufferID; |
| 1499 | Span<char> writableData; |
| 1500 | SC_TRY(client.transport.buffersPool->requestNewBuffer(encodedFrame.sizeInBytes(), bufferID, writableData)); |
| 1501 | ::memcpy(writableData.data(), encodedFrame.data(), encodedFrame.sizeInBytes()); |
| 1502 | client.transport.buffersPool->setNewBufferSize(bufferID, encodedFrame.sizeInBytes()); |
| 1503 | const Result writeResult = client.transport.writableStream->write(bufferID); |
| 1504 | client.transport.buffersPool->unrefBuffer(bufferID); |
| 1505 | SC_TRY(writeResult); |
| 1506 | } |
| 1507 | return Result(true); |
| 1508 | } |
| 1509 | |
| 1510 | Result HttpWebSocketSmallHub::broadcastText(Span<const char> payload, Span<char> frameStorage) |
| 1511 | { |