/
WebSocket.cljs
251 lines (177 loc) · 6.98 KB
/
WebSocket.cljs
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
(ns web.websockets.WebSocket
"The WebSocket object provides the API for creating and managing
WebSocket connection to a server, as well as for sending and
data on the connection."
(:refer-clojure :exclude []))
(defn close
"Method.
The WebSocket.close() method closes the `web.websockets.WebSocket`
or connection attempt, if any. If the connection is already CLOSED,
method does nothing.
`WebSocket.close();`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close`"
[this ]
(-> this (.close)))
(defn send
"Method.
The WebSocket.send() method enqueues the specified data to be
to the server over the WebSocket connection, increasing the value
bufferedAmount by the number of bytes needed to contain the data.
the data can't be sent (for example, because it needs to be buffered
the buffer is full), the socket is closed automatically.
`WebSocket.send(\\\"Hello server!\\\");`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send`"
[this & args]
(-> this .-send (.apply this (clj->js args))))
(defn binary-type
"Property.
The WebSocket.binaryType property returns the type of binary
being transmitted by the connection.
`var binaryType = aWebSocket.binaryType;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType`"
[this]
(-> this (.-binaryType)))
(defn set-binary-type!
"Property.
The WebSocket.binaryType property returns the type of binary
being transmitted by the connection.
`var binaryType = aWebSocket.binaryType;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType`"
[this val]
(aset this "binaryType" val))
(defn buffered-amount
"Property.
[Read Only]
The WebSocket.bufferedAmount read-only property returns the number
bytes of data that have been queued using calls to send() but
yet transmitted to the network. This value resets to zero once
queued data has been sent. This value does not reset to zero
the connection is closed; if you keep calling send(), this will
to climb.
`var bufferedAmount = aWebSocket.bufferedAmount;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/bufferedAmount`"
[this]
(-> this (.-bufferedAmount)))
(defn extensions
"Property.
[Read Only]
The WebSocket.extensions read-only property returns the extensions
by the server. This is currently only the empty string or a list
extensions as negotiated by the connection.
`var extensions = aWebSocket.extensions;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/extensions`"
[this]
(-> this (.-extensions)))
(defn onclose
"Property.
The WebSocket.onclose property is an `EventHandler` that is called
the WebSocket connection's `readyState` changes to `CLOSED`.
is called with a `web.websockets.CloseEvent`.
`aWebSocket.onclose = function(event) {
console.log(\\\"WebSocket is closed now.\\\");
};`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onclose`"
[this]
(-> this (.-onclose)))
(defn set-onclose!
"Property.
The WebSocket.onclose property is an `EventHandler` that is called
the WebSocket connection's `readyState` changes to `CLOSED`.
is called with a `web.websockets.CloseEvent`.
`aWebSocket.onclose = function(event) {
console.log(\\\"WebSocket is closed now.\\\");
};`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onclose`"
[this val]
(aset this "onclose" val))
(defn onerror
"Property.
The `web.websockets.WebSocket` interface's onerror event handler
is a function which gets called when an error occurs on the WebSocket.
`webSocket.onerror = eventHandler;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onerror`"
[this]
(-> this (.-onerror)))
(defn set-onerror!
"Property.
The `web.websockets.WebSocket` interface's onerror event handler
is a function which gets called when an error occurs on the WebSocket.
`webSocket.onerror = eventHandler;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onerror`"
[this val]
(aset this "onerror" val))
(defn onmessage
"Property.
The WebSocket.onmessage property is an `EventHandler` that is
when a message is received from the server. It is called with
`web.workers.MessageEvent`.
`aWebSocket.onmessage = function(event) {
console.debug(\\\"WebSocket message received:\\\", event);
};`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onmessage`"
[this]
(-> this (.-onmessage)))
(defn set-onmessage!
"Property.
The WebSocket.onmessage property is an `EventHandler` that is
when a message is received from the server. It is called with
`web.workers.MessageEvent`.
`aWebSocket.onmessage = function(event) {
console.debug(\\\"WebSocket message received:\\\", event);
};`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onmessage`"
[this val]
(aset this "onmessage" val))
(defn onopen
"Property.
The WebSocket.onopen property is an `EventHandler` that is called
the `web.websockets.WebSocket` connection's `readyState` changes
`OPEN`; this indicates that the connection is ready to send and
data. It is called with an `web.event.Event`.
`aWebSocket.onopen = function(event) {
console.log(\\\"WebSocket is open now.\\\");
};`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onopen`"
[this]
(-> this (.-onopen)))
(defn set-onopen!
"Property.
The WebSocket.onopen property is an `EventHandler` that is called
the `web.websockets.WebSocket` connection's `readyState` changes
`OPEN`; this indicates that the connection is ready to send and
data. It is called with an `web.event.Event`.
`aWebSocket.onopen = function(event) {
console.log(\\\"WebSocket is open now.\\\");
};`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onopen`"
[this val]
(aset this "onopen" val))
(defn protocol
"Property.
[Read Only]
The WebSocket.protocol read-only property returns the name of
sub-protocol the server selected; this will be one of the strings
in the protocols parameter when creating the `web.websockets.WebSocket`
or the empty string if no connection is established.
`var protocol = aWebSocket.protocol;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/protocol`"
[this]
(-> this (.-protocol)))
(defn ready-state
"Property.
[Read Only]
The WebSocket.readyState read-only property returns the current
of the `web.websockets.WebSocket` connection.
`var readyState = aWebSocket.readyState;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState`"
[this]
(-> this (.-readyState)))
(defn url
"Property.
[Read Only]
The WebSocket.url read-only property returns the absolute URL
the `web.websockets.WebSocket` as resolved by the constructor.
`var url = aWebSocket.url;`
See also: `https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/url`"
[this]
(-> this (.-url)))