Skip to content

Commit 5c528c2

Browse files
committed
Add interface file to hide the 'setArrayBuffer' method
1 parent 1686c3e commit 5c528c2

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

src/Webapi/Webapi__WebSocket.resi

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
open Js.TypedArray2
2+
3+
type readyState
4+
type t<'binaryType> = private {
5+
binaryType: [#blob | #arraybuffer],
6+
bufferedAmount: float,
7+
extensions: string,
8+
protocol: string,
9+
readyState: readyState,
10+
url: string,
11+
}
12+
@new external make: string => t<Webapi__Blob.t> = "WebSocket"
13+
let makeArrayBuffer: string => t<array_buffer>
14+
15+
@val @scope("WebSocket") external readyStateClosing: readyState = "CLOSING"
16+
@val @scope("WebSocket") external readyStateClosed: readyState = "CLOSED"
17+
@val @scope("WebSocket") external readyStateConnected: readyState = "CONNECTING"
18+
@val @scope("WebSocket") external readyStateOpen: readyState = "OPEN"
19+
20+
let isOpen: t<'binaryType> => bool
21+
22+
@send external close: t<'binaryType> => unit = "close"
23+
@send external closeWithReason: (t<'binaryType>, ~code: int, ~reason: string) => unit = "close"
24+
25+
@send
26+
external addOpenListener: (t<'binaryType>, @as("open") _, Webapi__Dom__Event.t => unit) => unit =
27+
"addEventListener"
28+
@send
29+
external removeOpenListener: (t<'binaryType>, @as("open") _, Webapi__Dom__Event.t => unit) => unit =
30+
"removeEventListener"
31+
32+
type closeEvent = private {
33+
code: int,
34+
reason: string,
35+
wasClean: bool,
36+
}
37+
@send
38+
external addCloseListener: (t<'binaryType>, @as("close") _, closeEvent => unit) => unit =
39+
"addEventListener"
40+
@send
41+
external removeCloseListener: (t<'binaryType>, @as("close") _, closeEvent => unit) => unit =
42+
"removeEventListener"
43+
44+
@send
45+
external addErrorListener: (t<'binaryType>, @as("error") _, Webapi__Dom__Event.t => unit) => unit =
46+
"addEventListener"
47+
@send
48+
external removeErrorListener: (
49+
t<'binaryType>,
50+
@as("error") _,
51+
Webapi__Dom__Event.t => unit,
52+
) => unit = "removeEventListener"
53+
54+
type messageEvent<'binaryType> = {
55+
data: Js.Json.t,
56+
origin: string,
57+
lastEventId: string,
58+
}
59+
@send
60+
external addMessageListener: (
61+
t<'binaryType>,
62+
@as("message") _,
63+
messageEvent<'binaryType> => unit,
64+
) => unit = "addEventListener"
65+
@send
66+
external removeMessageListener: (
67+
t<'binaryType>,
68+
@as("message") _,
69+
messageEvent<'binaryType> => unit,
70+
) => unit = "removeEventListener"
71+
72+
@send external sendText: (t<'binaryType>, string) => unit = "send"
73+
@send external sendBlob: (t<'binaryType>, Webapi__Blob.t) => unit = "send"
74+
@send external sendArrayBuffer: (t<'binaryType>, array_buffer) => unit = "send"
75+
@send external sendInt8Array: (t<'binaryType>, Int8Array.t) => unit = "send"
76+
@send external sendInt16Array: (t<'binaryType>, Int16Array.t) => unit = "send"
77+
@send external sendInt32Array: (t<'binaryType>, Int32Array.t) => unit = "send"
78+
@send external sendUint8Array: (t<'binaryType>, Uint8Array.t) => unit = "send"
79+
@send external sendUint8ClampedArray: (t<'binaryType>, Uint8ClampedArray.t) => unit = "send"
80+
@send external sendUint16Array: (t<'binaryType>, Uint16Array.t) => unit = "send"
81+
@send external sendUint32Array: (t<'binaryType>, Uint32Array.t) => unit = "send"
82+
@send external sendFloat32Array: (t<'binaryType>, Float32Array.t) => unit = "send"
83+
@send external sendFloat64Array: (t<'binaryType>, Float64Array.t) => unit = "send"
84+
@send external sendDataView: (t<'binaryType>, DataView.t) => unit = "send"
85+
86+
@get external unsafeMessageAsBinary: messageEvent<'binaryType> => 'binaryType = "data"
87+
@get external unsafeMessageAsText: messageEvent<'binaryType> => string = "data"
88+
89+
let messageIsText: messageEvent<'binaryType> => bool
90+
let messageAsText: messageEvent<'binaryType> => option<string>
91+
let messageAsBinary: messageEvent<'binaryType> => option<'binaryType>

0 commit comments

Comments
 (0)