@@ -13,17 +13,31 @@ To create a new websocket connection:
1313
1414 (def socket (ws/create "ws://...." handlers))
1515
16- where handlers is a map containing handler functions mapped to the following keys:
16+ where ` handlers ` is a map containing handler functions mapped to the following keys:
1717
18- - ` :on-open ` => called when opening a socket connection
19- - ` :on-message ` => called when recieving message on the socket
20- - ` :on-close ` => called when closing a socket connection
18+ Required:
2119
22- To send data over the socket, do:
20+ - ` :on-message ` => called when recieving message on the socket
2321
24- (ws/send socket data encoding)
22+ Optional:
2523
26- The available encodings are ` identity ` (raw/no encoding) and ` json `
24+ - ` :on-open ` => called when opening a socket connection
25+ - ` :on-close ` => called when closing a socket connection
26+
27+ For example, to print the data received by the socket, do:
28+
29+ (def handlers {:on-message (fn [e] (prn (.-data e)))
30+ :on-open #(prn "Opening a new connection")
31+ :on-close #(prn "Closing a connection")})
32+ (def socket (ws/create "ws://...." handlers))
33+
34+ To send json data over the socket, do:
35+
36+ (require '[wscljs.format :as fmt])
37+
38+ (ws/send socket {:command "ping"} fmt/json)
39+
40+ * The supported formats are ` json ` and ` identity ` (for now).*
2741
2842After you're done, close the socket using:
2943
0 commit comments