|
import "websocket" for WebSocketMessage
|
|
|
|
var text = WebSocketMessage.new_(1, [72, 101, 108, 108, 111], true)
|
|
System.print(text.opcode) // expect: 1
|
|
System.print(text.isText) // expect: true
|
|
System.print(text.isBinary) // expect: false
|
|
System.print(text.isClose) // expect: false
|
|
System.print(text.isPing) // expect: false
|
|
System.print(text.isPong) // expect: false
|
|
System.print(text.text) // expect: Hello
|
|
System.print(text.bytes) // expect: [72, 101, 108, 108, 111]
|
|
|
|
var binary = WebSocketMessage.new_(2, [1, 2, 3, 4], true)
|
|
System.print(binary.opcode) // expect: 2
|
|
System.print(binary.isText) // expect: false
|
|
System.print(binary.isBinary) // expect: true
|
|
System.print(binary.bytes) // expect: [1, 2, 3, 4]
|
|
|
|
var close = WebSocketMessage.new_(8, [3, 232], true)
|
|
System.print(close.opcode) // expect: 8
|
|
System.print(close.isClose) // expect: true
|
|
System.print(close.closeCode) // expect: 1000
|
|
|
|
var closeWithReason = WebSocketMessage.new_(8, [3, 232, 98, 121, 101], true)
|
|
System.print(closeWithReason.closeCode) // expect: 1000
|
|
System.print(closeWithReason.closeReason) // expect: bye
|
|
|
|
var ping = WebSocketMessage.new_(9, [], true)
|
|
System.print(ping.isPing) // expect: true
|
|
System.print(ping.isPong) // expect: false
|
|
|
|
var pong = WebSocketMessage.new_(10, [], true)
|
|
System.print(pong.isPing) // expect: false
|
|
System.print(pong.isPong) // expect: true
|