|
26 | 26 | * events are listened for, messages are pushed to the server, and |
27 | 27 | * the channel is joined with ok/error/timeout matches: |
28 | 28 | * |
29 | | - * ```javascript |
| 29 | + * ``` |
30 | 30 | * let channel = socket.channel("room:123", {token: roomToken}) |
31 | 31 | * channel.on("new_msg", msg => console.log("Got message", msg) ) |
32 | 32 | * $input.onEnter( e => { |
|
82 | 82 | * Lifecycle events of the multiplexed connection can be hooked into via |
83 | 83 | * `socket.onError()` and `socket.onClose()` events, ie: |
84 | 84 | * |
85 | | - * ```javascript |
| 85 | + * ``` |
86 | 86 | * socket.onError( () => console.log("there was an error with the connection!") ) |
87 | 87 | * socket.onClose( () => console.log("the connection dropped") ) |
88 | 88 | * ``` |
|
93 | 93 | * For each joined channel, you can bind to `onError` and `onClose` events |
94 | 94 | * to monitor the channel lifecycle, ie: |
95 | 95 | * |
96 | | - * ```javascript |
| 96 | + * ``` |
97 | 97 | * channel.onError( () => console.log("there was an error!") ) |
98 | 98 | * channel.onClose( () => console.log("the channel has gone away gracefully") ) |
99 | 99 | * ``` |
|
121 | 121 | * To sync presence state from the server, first instantiate an object and |
122 | 122 | * pass your channel in to track lifecycle events: |
123 | 123 | * |
124 | | - * ```javascript |
| 124 | + * ``` |
125 | 125 | * let channel = socket.channel("some:topic") |
126 | 126 | * let presence = new Presence(channel) |
127 | 127 | * ``` |
|
130 | 130 | * from the server. For example, to render the list of users every time |
131 | 131 | * the list changes, you could write: |
132 | 132 | * |
133 | | - * ```javascript |
| 133 | + * ``` |
134 | 134 | * presence.onSync(() => { |
135 | 135 | * myRenderUsersFunction(presence.list()) |
136 | 136 | * }) |
|
150 | 150 | * each user. This could be the first tab they opened, or the first device |
151 | 151 | * they came online from: |
152 | 152 | * |
153 | | - * ```javascript |
| 153 | + * ``` |
154 | 154 | * let listBy = (id, {metas: [first, ...rest]}) => { |
155 | 155 | * first.count = rest.length + 1 // count of this user's presences |
156 | 156 | * first.id = id |
|
164 | 164 | * The `presence.onJoin` and `presence.onLeave` callbacks can be used to |
165 | 165 | * react to individual presences joining and leaving the app. For example: |
166 | 166 | * |
167 | | - * ```javascript |
| 167 | + * ``` |
168 | 168 | * let presence = new Presence(channel) |
169 | 169 | * |
170 | 170 | * // detect if user has joined for the 1st time or from another tab/device |
|
0 commit comments