Configuration.encodeWebSocket()
Description
Appends an encodeWebSocket filter to the current pipeline layout.
An encodeWebSocket filter encodes WebSocket messages into a raw byte stream.
- INPUT - WebSocket Messages to encode.
- OUTPUT - Encoded Data stream from the input WebSocket messages.
The encoder expects an input Message to have:
- head
- opcode - Interpretation of the payload
- masked - Whether the payload is masked
- body - Binary data in the body
The opcode can be:
- 1 = text data
- 2 = binary data
- 8 = connection close
- 9 = ping
- 10 = pong
Syntax
pipy().pipeline().encodeWebSocket()
Parameters
encodeWebSocket()
Return Value
The same Configuration object.
Example
pipy().listen(8080).demuxHTTP().to($=>$.acceptHTTPTunnel(msg => (((hash = new crypto.Hash('sha1'),) => (hash.update(msg.head.headers['sec-websocket-key'] +'258EAFA5-E914-47DA-95CA-C5AB0DC85B11'),new Message({status: 101,headers: {'upgrade': 'websocket','connection': 'upgrade','sec-websocket-accept': hash.digest('base64'),}})))())).to($=>$.decodeWebSocket().replaceMessage(() => new Message({ opcode: 1 }, 'yay!')).encodeWebSocket()))