-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathWebSocket.res
More file actions
71 lines (57 loc) · 2.48 KB
/
Copy pathWebSocket.res
File metadata and controls
71 lines (57 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
type t = WebSocketsTypes.webSocket = private {...WebSocketsTypes.webSocket}
type binaryType = WebSocketsTypes.binaryType
type messageEvent<'t> = WebSocketsTypes.messageEvent<'t> = {...WebSocketsTypes.messageEvent<'t>}
type closeEvent = WebSocketsTypes.closeEvent = private {...WebSocketsTypes.closeEvent}
type messageEventSource = WebSocketsTypes.messageEventSource
/**
`fromURL(~url: string, ~protocols: string=?)`
Creates a new `WebSocket` from a URL and an optional single protocol.
```res
let socket = WebSocket.fromURL(~url="wss://example.com/socket")
```
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebSocket)
*/
@new
external fromURL: (~url: string, ~protocols: string=?) => t = "WebSocket"
/**
`fromURLWithProtocols(~url: string, ~protocols: array<string>)`
Creates a new `WebSocket` from a URL and multiple protocols.
```res
let socket =
WebSocket.fromURLWithProtocols(
~url="wss://example.com/socket",
~protocols=["chat", "superchat"],
)
```
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebSocket)
*/
@new
external fromURLWithProtocols: (~url: string, ~protocols: array<string>) => t = "WebSocket"
include EventTarget.Impl({type t = t})
/**
Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebSocket/close)
*/
@send
external close: (t, ~code: int=?, ~reason: string=?) => unit = "close"
/**
Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
*/
@send
external send: (t, DataView.t) => unit = "send"
/**
Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
*/
external sendArrayBuffer: (t, ArrayBuffer.t) => unit = "send"
/**
Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
*/
external sendBlob: (t, Blob.t) => unit = "send"
/**
Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
*/
external sendString: (t, string) => unit = "send"