Skip to content

Commit 849e615

Browse files
author
Alec Gibson
committed
Document share.listen in the README
1 parent ca17b3e commit 849e615

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var socket = new WebSocket('ws://' + window.location.host);
3838
var connection = new sharedb.Connection(socket);
3939
```
4040

41-
The native Websocket object that you feed to ShareDB's `Connection` constructor **does not** handle reconnections.
41+
The native Websocket object that you feed to ShareDB's `Connection` constructor **does not** handle reconnections.
4242

4343
The easiest way is to give it a WebSocket object that does reconnect. There are plenty of example on the web. The most important thing is that the custom reconnecting websocket, must have the same API as the native rfc6455 version.
4444

@@ -124,6 +124,12 @@ For transports other than WebSockets, expose a duplex
124124
stream that writes and reads JavaScript objects. Then
125125
pass that stream directly into `share.listen`.
126126

127+
The `listen` method accepts the following arguments:
128+
129+
- `stream` - the stream to listen to for messages from the client
130+
- `req` (optional) - an initial request which is passed through to any `connect` middleware. This is useful for inspecting cookies; Express session; etc. on the request object in the middleware
131+
- `clientId` (optional) - an identifier for the connecting client. This will be prepended to the connection ID, and can be used to identify the source client of an operation. The `src` field will look like `<clientId>:<randomId>`
132+
127133
### Middlewares
128134

129135
Middlewares let you hook into the ShareDB server pipeline. In

lib/backend.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ Backend.prototype.connect = function(connection, req, clientId) {
128128
/**
129129
* @param stream - the stream to listen to for messages from the client
130130
* @param req (optional) - an initial request which is passed through to any connect()
131-
* middleware(). This is useful for inspecting cookies or an express
131+
* middleware. This is useful for inspecting cookies or an express
132132
* session or whatever on the request object in your middleware
133133
* @param clientId (optional) - an identifier for the connecting client. This will be
134134
* prepended to the connection ID, and can be used to identify the source client
135-
* of an operation. It will look like: <clientId>:<randomId>
135+
* of an operation. The src field will look like: <clientId>:<randomId>
136136
* @returns agent - the instance of the connected agent, which is available through all
137137
* middleware
138138
*/

0 commit comments

Comments
 (0)