Class: Adapter

Adapter

new Adapter(options) → {Adapter}

This function creates an Adapter.
Parameters:
Name Type Argument Default Description
options Object <optional>
{} Object containing the properties listed below.
Properties:
Name Type Argument Default Description
name String The name of the adapter.
events Boolean <optional>
false indicates whether the Adapter supports server events, if set to true, the on and trigger methods must be implemented.
connect function Function that should return a Promise that resolves when connection to the server has been established, and rejects when it failed to do so.
disconnect function Function that should return a Promise that resolves when the client has disconnected from the server, and rejects when it failed to do so.
request function Function that should return a Promise that resolves when a request has been successfully executed, and rejects when it failed to do so. The data object contains a url, method and data property.
on function Function that should listen for a server event and trigger a callback when it occurs.
trigger function Function that should trigger a server event with data.
Author:
  • Rik Hoffbauer
Returns:
Type
Adapter
Example
const adapter = Adapter({
  events: true,

  connect(url) {
    return new Promise({
      // ....
    });
  },

  disconnect(url) {
    return new Promise({
      // ....
    });
  },

  // data contains a url, method and data property
  request(data) {
    return new Promise({
      // ....
    });
  },

  on(event, cb) {
    // ...
  },

  emit(event, data) {
    // ...
  }
});
Rik Hoffbauer 2015
Documentation generated by JSDoc 3.4.0 on 2015-12-01T13:53:50+01:00