Members
Methods
connect(callback)
Tell the wrapper client to connect to the configured ShareJS server.
Example
share.connect(function onConnected() {
console.log(share.content);
});
Parameters
Name | Type | Description |
---|---|---|
callback |
ShareJSWrapper~connectCallback | A callback to call once connected |
disconnect()
Tell the wrapper client to close the ShareJS connection and socket.
Example
share.disconnect();
insert(offset, text)
Send an insert operation from this client to the server.
Example
share.insert(10, 'Foo');
Parameters
Name | Type | Description |
---|---|---|
offset |
number | The offset at which to start the insert operation |
text |
string | The text to be inserted |
on(event, fn, context) → {ShareJSWrapper}
Add a listener to an event.
Example
share.on('connect', function onConnect() {
// ...
});
Parameters
Name | Type | Description |
---|---|---|
event |
string | The name of the event |
fn |
function | The function to call when the event occurs |
context |
* | The context on which to call the function |
once(event, fn, context) → {ShareJSWrapper}
Add a listener to an event which will fire once.
Example
share.once('connect', function onConnect() {
// ...
});
Parameters
Name | Type | Description |
---|---|---|
event |
string | The name of the event |
fn |
function | The function to call when the event occurs |
context |
* | The context on which to call the function |
remove(start, length)
Send a remove operation from this client to the server.
Example
share.remove(0, 3);
Parameters
Name | Type | Description |
---|---|---|
start |
number | The position at which to start the remove |
length |
number | The number of characters to remove |
removeAllListeners(eventopt) → {ShareJSWrapper}
Remove all listeners or only for the specified event.
Example
share.removeAllListeners();
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
event |
string |
<optional> |
The event to remove all listeners for |
removeListener(event, fnopt, contextopt, once) → {ShareJSWrapper}
Remove a listener from an event.
Example
share.removeListener('connect', connectHandler, this, true);
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
event |
string | The event to remove listener(s) from |
|
fn |
function |
<optional> |
The listener to remove |
context |
* |
<optional> |
Only match listeners matching this context |
once |
boolean | Only remove "once" listeners |
Type Definitions
connectCallback()
A callback called on successful connection after a connect
call
Insert
A two-element array consisting of a length of text to retain and a string to insert
Remove
A two-element array consisting of a length of text to retain and a length of text to remove
Events
disconnect
An event emitted when the client has fatally disconnected and will no longer attempt reconnects.
Check err.message
for "abnormal", "no_pong", "forbidden",
"not_found", or "unexpected".