Skip to content

Commit

Permalink
Merge pull request share#608 from share/reconnecting-socket-docs
Browse files Browse the repository at this point in the history
📝 Update docs around `reconnecting-websocket`
  • Loading branch information
alecgibson authored May 2, 2023
2 parents 26d5d49 + 3e1e7f0 commit 21750e3
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 9 deletions.
6 changes: 5 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ Try running the [working example](https://github.com/share/sharedb/tree/master/e
var ReconnectingWebSocket = require('reconnecting-websocket')
var Connection = require('sharedb/lib/client').Connection

var socket = new ReconnectingWebSocket('ws://localhost:8080')
var socket = new ReconnectingWebSocket('ws://localhost:8080', [], {
// ShareDB handles dropped messages, and buffering them while the socket
// is closed has undefined behavior
maxEnqueuedMessages: 0
})
var connection = new Connection(socket)

var doc = connection.get('doc-collection', 'doc-id')
Expand Down
6 changes: 5 additions & 1 deletion examples/counter-json1-vite/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {json1} from 'sharedb-client-browser/dist/ot-json1-umd.cjs';
import sharedb from 'sharedb-client-browser/dist/sharedb-client-umd.cjs';

// Open WebSocket connection to ShareDB server
var socket = new ReconnectingWebSocket('ws://' + window.location.host + '/ws');
var socket = new ReconnectingWebSocket('ws://' + window.location.host + '/ws', [], {
// ShareDB handles dropped messages, and buffering them while the socket
// is closed has undefined behavior
maxEnqueuedMessages: 0
});
sharedb.types.register(json1.type);
var connection = new sharedb.Connection(socket);

Expand Down
6 changes: 5 additions & 1 deletion examples/counter-json1/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ var sharedb = require('sharedb/lib/client');
var json1 = require('ot-json1');

// Open WebSocket connection to ShareDB server
var socket = new ReconnectingWebSocket('ws://' + window.location.host);
var socket = new ReconnectingWebSocket('ws://' + window.location.host, [], {
// ShareDB handles dropped messages, and buffering them while the socket
// is closed has undefined behavior
maxEnqueuedMessages: 0
});
sharedb.types.register(json1.type);
var connection = new sharedb.Connection(socket);

Expand Down
6 changes: 5 additions & 1 deletion examples/counter/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ var ReconnectingWebSocket = require('reconnecting-websocket');
var sharedb = require('sharedb/lib/client');

// Open WebSocket connection to ShareDB server
var socket = new ReconnectingWebSocket('ws://' + window.location.host);
var socket = new ReconnectingWebSocket('ws://' + window.location.host, [], {
// ShareDB handles dropped messages, and buffering them while the socket
// is closed has undefined behavior
maxEnqueuedMessages: 0
});
var connection = new sharedb.Connection(socket);

// Create local Doc instance mapped to 'examples' collection document with id 'counter'
Expand Down
6 changes: 5 additions & 1 deletion examples/leaderboard/client/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ var ReconnectingWebSocket = require('reconnecting-websocket');
var sharedb = require('sharedb/lib/client');

// Expose a singleton WebSocket connection to ShareDB server
var socket = new ReconnectingWebSocket('ws://' + window.location.host);
var socket = new ReconnectingWebSocket('ws://' + window.location.host, [], {
// ShareDB handles dropped messages, and buffering them while the socket
// is closed has undefined behavior
maxEnqueuedMessages: 0
});
var connection = new sharedb.Connection(socket);
module.exports = connection;
6 changes: 5 additions & 1 deletion examples/rich-text-presence/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ var collection = 'examples';
var id = 'richtext';
var presenceId = new ObjectID().toString();

var socket = new ReconnectingWebSocket('ws://' + window.location.host);
var socket = new ReconnectingWebSocket('ws://' + window.location.host, [], {
// ShareDB handles dropped messages, and buffering them while the socket
// is closed has undefined behavior
maxEnqueuedMessages: 0
});
var connection = new sharedb.Connection(socket);
var doc = connection.get(collection, id);

Expand Down
12 changes: 10 additions & 2 deletions examples/rich-text/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ var Quill = require('quill');
sharedb.types.register(richText.type);

// Open WebSocket connection to ShareDB server
var socket = new ReconnectingWebSocket('ws://' + window.location.host);
var socket = new ReconnectingWebSocket('ws://' + window.location.host, [], {
// ShareDB handles dropped messages, and buffering them while the socket
// is closed has undefined behavior
maxEnqueuedMessages: 0
});
var connection = new sharedb.Connection(socket);

// For testing reconnection
window.disconnect = function() {
connection.close();
};
window.connect = function() {
var socket = new ReconnectingWebSocket('ws://' + window.location.host);
var socket = new ReconnectingWebSocket('ws://' + window.location.host, [], {
// ShareDB handles dropped messages, and buffering them while the socket
// is closed has undefined behavior
maxEnqueuedMessages: 0
});
connection.bindToSocket(socket);
};

Expand Down
6 changes: 5 additions & 1 deletion examples/textarea/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ var StringBinding = require('sharedb-string-binding');

// Open WebSocket connection to ShareDB server
var ReconnectingWebSocket = require('reconnecting-websocket');
var socket = new ReconnectingWebSocket('ws://' + window.location.host);
var socket = new ReconnectingWebSocket('ws://' + window.location.host, [], {
// ShareDB handles dropped messages, and buffering them while the socket
// is closed has undefined behavior
maxEnqueuedMessages: 0
});
var connection = new sharedb.Connection(socket);

var element = document.querySelector('textarea');
Expand Down

0 comments on commit 21750e3

Please sign in to comment.