@@ -275,14 +275,35 @@ protocol:
275
275
(on-close [listener socket code reason]))
276
276
```
277
277
278
- The arguments are described as follows:
278
+ #### on-open
279
279
280
- * ` socket ` - described in section 3.3.
281
- * ` message ` - a ` String ` or ` java.nio.ByteBuffer ` containing a message
282
- * ` data ` - a ` java.nio.ByteBuffer ` containing pong data
283
- * ` throwable ` - an error inheriting from ` java.lang.Throwable `
284
- * ` code ` - an integer from 1000 to 4999
285
- * ` reason ` - a string describing the reason for closing the socket
280
+ Called once when the websocket is first opened. Supplies a ` socket `
281
+ argument that satisfies ` ring.websocket/Socket ` , described in section
282
+ 3.3.
283
+
284
+ #### on-message
285
+
286
+ Called when a text or binary message frame is received from the client.
287
+ The ` message ` argument may be a ` String ` or a ` java.nio.ByteBuffer `
288
+ depending on whether the message is text or binary.
289
+
290
+ #### on-pong
291
+
292
+ Called when a "pong" frame is received from the client. The ` data `
293
+ argument is a ` java.nio.ByteBuffer ` that contains optional client
294
+ session data.
295
+
296
+ #### on-error
297
+
298
+ Called when an error occurs. This may cause the websocket to be closed.
299
+ The ` throwable ` argument is a ` java.lang.Throwable ` that was generated
300
+ by the error.
301
+
302
+ #### on-close
303
+
304
+ Called once when the websocket is closed. Guaranteed to be called, even
305
+ if an error occurs, so may be used for finalizing/cleanup logic. Takes
306
+ an integer ` code ` and a string ` reason ` as arguments.
286
307
287
308
### 3.3. Websocket Sockets
288
309
@@ -294,19 +315,44 @@ A socket must satisfy the `ring.websocket/Socket` protocol:
294
315
(-send [socket message])
295
316
(-ping [socket data])
296
317
(-pong [socket data])
297
- (-close [socket status reason]))
318
+ (-close [socket code reason]))
298
319
```
299
320
300
- The types of the arguments are the same as those described for the
301
- ` Listener ` protocol. The ` -open? ` method must return true or false.
302
-
303
321
It * may* optionally satisfy the ` ring.websocket/AsyncSocket ` protocol:
304
322
305
323
``` clojure
306
324
(defprotocol AsyncSocket
307
325
(-send-async [socket message succeed fail]))
308
326
```
309
327
310
- Where ` succeed ` is a callback function that expects zero arguments, and
311
- ` fail ` is a callback function expecting a single ` java.lang.Throwable `
312
- argument.
328
+ #### -open?
329
+
330
+ Returns a truthy or falsey value denoting whether the socket is
331
+ currently connected to the client.
332
+
333
+ #### -send
334
+
335
+ Sends a websocket message frame that may be a ` String ` (for text), or
336
+ a ` java.nio.ByteBuffer ` (for binary).
337
+
338
+ #### -send-async
339
+
340
+ As above, but does not block and requires two callback functions:
341
+
342
+ - ` succeed ` is called with zero arguments when the send succeeds
343
+ - ` fail ` is called with a single ` java.lang.Throwable ` argument when the
344
+ send fails
345
+
346
+ #### -ping
347
+
348
+ Sends a websocket ping frame with a ` java.nio.ByteBuffer ` of session
349
+ data (which may be empty).
350
+
351
+ #### -pong
352
+
353
+ Sends an unsolicited pong frame with a ` java.nio.ByteBuffer ` of session
354
+ data (which may be empty).
355
+
356
+ #### -close
357
+
358
+ Closes the websocket with the supplied integer code and reason string.
0 commit comments