(message)
| 90 | } |
| 91 | |
| 92 | function formatWSFrame(message) { |
| 93 | const messageBuf = Buffer.from(JSON.stringify(message)); |
| 94 | |
| 95 | const wsHeaderBuf = Buffer.allocUnsafe(16); |
| 96 | wsHeaderBuf.writeUInt8(0x81, 0); |
| 97 | let byte2 = 0x80; |
| 98 | const bodyLen = messageBuf.length; |
| 99 | |
| 100 | let maskOffset = 2; |
| 101 | if (bodyLen < 126) { |
| 102 | byte2 = 0x80 + bodyLen; |
| 103 | } else if (bodyLen < 65536) { |
| 104 | byte2 = 0xFE; |
| 105 | wsHeaderBuf.writeUInt16BE(bodyLen, 2); |
| 106 | maskOffset = 4; |
| 107 | } else { |
| 108 | byte2 = 0xFF; |
| 109 | wsHeaderBuf.writeUInt32BE(bodyLen, 2); |
| 110 | wsHeaderBuf.writeUInt32BE(0, 6); |
| 111 | maskOffset = 10; |
| 112 | } |
| 113 | wsHeaderBuf.writeUInt8(byte2, 1); |
| 114 | wsHeaderBuf.writeUInt32BE(0x01020408, maskOffset); |
| 115 | |
| 116 | for (let i = 0; i < messageBuf.length; i++) |
| 117 | messageBuf[i] = messageBuf[i] ^ (1 << (i % 4)); |
| 118 | |
| 119 | return Buffer.concat([wsHeaderBuf.slice(0, maskOffset + 4), messageBuf]); |
| 120 | } |
| 121 | |
| 122 | class InspectorSession { |
| 123 | constructor(socket, instance) { |
no test coverage detected