MCPcopy
hub / github.com/socketio/socket.io / createPacketEncoderStream

Function createPacketEncoderStream

packages/socket.io/client-dist/socket.io.js:382–412  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

380 return packets;
381 };
382 function createPacketEncoderStream() {
383 return new TransformStream({
384 transform: function transform(packet, controller) {
385 encodePacketToBinary(packet, function (encodedPacket) {
386 var payloadLength = encodedPacket.length;
387 var header;
388 // inspired by the WebSocket format: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#decoding_payload_length
389 if (payloadLength < 126) {
390 header = new Uint8Array(1);
391 new DataView(header.buffer).setUint8(0, payloadLength);
392 } else if (payloadLength < 65536) {
393 header = new Uint8Array(3);
394 var view = new DataView(header.buffer);
395 view.setUint8(0, 126);
396 view.setUint16(1, payloadLength);
397 } else {
398 header = new Uint8Array(9);
399 var _view = new DataView(header.buffer);
400 _view.setUint8(0, 127);
401 _view.setBigUint64(1, BigInt(payloadLength));
402 }
403 // first bit indicates whether the payload is plain text (0) or binary (1)
404 if (packet.data && typeof packet.data !== "string") {
405 header[0] |= 0x80;
406 }
407 controller.enqueue(header);
408 controller.enqueue(encodedPacket);
409 });
410 }
411 });
412 }
413 var TEXT_DECODER;
414 function totalLength(chunks) {
415 return chunks.reduce(function (acc, chunk) {

Callers 1

socket.io.jsFile · 0.70

Calls 1

encodePacketToBinaryFunction · 0.70

Tested by

no test coverage detected