new simpleDDP (options, plugins)simpleDDP
Name | Type | Description | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
|
||||||||||||||||||||||||||||||||
plugins |
Array |
optional
Array of plugins. |
- Version:
- 2.2.4
Returns:
Type | Description |
---|---|
simpleDDP |
|
Example
var opts = {
endpoint: "ws://someserver.com/websocket",
SocketConstructor: WebSocket,
reconnectInterval: 5000
};
var server = new simpleDDP(opts);
Members
-
All collections data recieved from server.
-
Whether the client is connected to server.
Methods
-
Calls a remote method with arguments passed in array.
Name Type Default Description method
string Name of the server publication.
arguments
Array optional Array of parameters to pass to the remote method. Pass an empty array or don't pass anything if you do not wish to pass any parameters.
atBeginning
boolean false optional If true puts method call at the beginning of the requests queue.
Returns:
Type Description Promise - Promise object, which resolves when receives a result send by server and rejects when receives an error send by server.
Example
server.apply("method1").then(function(result) { console.log(result); //show result message in console if (result.someId) { //server sends us someId, lets call next method using this id return server.apply("method2",[result.someId]); } else { //we didn't recieve an id, lets throw an error throw "no id sent"; } }).then(function(result) { console.log(result); //show result message from second method }).catch(function(error) { console.log(result); //show error message in console });
-
Calls a remote method with arguments passed after the first argument. Syntactic sugar for @see apply.
Name Type Description method
string Name of the server publication.
args
any optional repeatable List of parameters to pass to the remote method. Parameters are passed as function arguments.
Returns:
Type Description Promise - Promise object, which resolves when receives a result send by server and rejects when receives an error send by server.
-
Removes all documents like if it was removed by the server publication.
Returns:
Type Description Promise - Resolves when data is successfully removed.
-
collection (name)ddpCollection
-
Use this for fetching the subscribed data and for reactivity inside the collection.
Name Type Description name
string Collection name.
Returns:
Type Description ddpCollection -
Connects to the ddp server. The method is called automatically by the class constructor if the autoConnect option is set to true (default behavior).
Returns:
Type Description Promise - Promise which resolves when connection is established.
-
Disconnects from the ddp server by closing the WebSocket connection. You can listen on the disconnected event to be notified of the disconnection.
Returns:
Type Description Promise - Promise which resolves when connection is closed.
-
Exports the data
Name Type Default Description format
string 'string' optional Possible values are 'string' (EJSON string) and 'raw' (EJSON).
Returns:
Type Description Object | string - EJSON string or EJSON.
-
Imports the data like if it was published by the server.
Name Type Description data
Object | string ESJON string or EJSON.
Returns:
Type Description Promise - Resolves when data is successfully imported.
-
Marks every passed @see ddpSubscription object as ready like if it was done by the server publication.
Name Type Description subs
Array Array of @see ddpSubscription objects.
Returns:
Type Description Promise - Resolves when all passed subscriptions are marked as ready.
-
on (event, f)ddpEventListener
-
Starts listening server for basic DDP event running f each time the message arrives.
Name Type Description event
string Any event name from DDP specification. Default suppoted events:
connected
,disconnected
,added
,changed
,removed
,ready
,nosub
,error
,ping
,pong
.f
function Function which receives a message from a DDP server as a first argument each time server is invoking event.
Returns:
Type Description ddpEventListener Example
server.on('connected', () => { // you can show a success message here }); server.on('disconnected', () => { // you can show a reconnection message here });
-
Stops all reactivity.
-
sub (pubname, arguments)ddpSubscription
-
Tries to subscribe to a specific publication on server.
Name Type Description pubname
string Name of the publication on server.
arguments
Array optional Array of parameters to pass to the remote method. Pass an empty array or don't pass anything if you do not wish to pass any parameters.
Returns:
Type Description ddpSubscription - Subscription.
-
subscribe (pubname, args)ddpSubscription
-
Tries to subscribe to a specific publication on server. Syntactic sugar for @see sub.
Name Type Description pubname
string Name of the publication on server.
args
any optional repeatable List of parameters to pass to the remote method. Parameters are passed as function arguments.
Returns:
Type Description ddpSubscription - Subscription.