object
respoke.tokensContainer object for header tokens. These are used when performing REST or web socket requests to Respoke.
string
respoke.endpointIdIf connected, this is the endpointId. Stored endpointId for use when connecting with App-Secret via web socket (when not a specific endpoint).
string
respoke.baseURLThe base respoke api to use. In most circumstances there is no reason to change this.
It should include the API version with no trailing /
.
https://api.respoke.io/v1
SocketObject
respoke.socketThe web socket connection instance from socket.io. It is recommended that you do not access this directly.
General purpose method for doing a REST call to Respoke.
params
params.body
params.json=true
params.headers=self.tokens
callback
Make a general purpose web socket call over the active .socket
.
httpMethod
urlPath
data
[data.headers]
object
respoke.authNamespace object. The methods at respoke.auth
are used for
obtaining auth credentials and connecting with Respoke.
As an admin (with respoke.tokens['App-Token']
or respoke.tokens['App-Secret']
),
obtain a tokenId
which can be used to authenticate to Respoke as an endpoint.
respoke.auth.endpoint({
endpointId: "user-billy",
roleId: "XXXX-XXX-XXXXX-XXXX"
}, function (err, authData) {
if (err) { console.error(err); return; }
console.log(authData.tokenId); // "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
});
opts
opts.appId
opts.endpointId
opts.roleId
opts.ttl=86400
opts.headers['App-Secret']
opts.headers['Admin-Token']
callback
As an endpoint, obtain an app auth session. This creates a session for the user to connect to your Respoke app.
Upon successful authentication, it sets the property respoke.tokens['App-Token']
which will be used during HTTP requests, or to establish a web socket.
{ token: 'XXXX-XXX-XXXXX-XXXX' }
In most cases, you will immediately call .connect()
to initiate the web socket.
opts
[opts.tokenId]
callback
Connect as a web socket client using the highest authentication token currently available.
After calling this, attach event listeners such as
respoke.on('connect')
and respoke.on('error')
.
opts
opts.endpointId
opts['Admin-Token']
opts['App-Secret']
opts['App-Token']
opts.connectParams
Authenticate with full admin privileges. This is not a recommended auth strategy
and should only be used in rare circustances when App-Secret
auth is not
enough.
Upon successful authentication, it sets the property respoke.tokens['Admin-Token']
which will be used during HTTP requests or to establish a web socket.
{ token: 'XXXX-XXX-XXXXX-XX' }
opts
opts.username
opts.password
callback
Delete the app auth session, disconnect the web socket, and remove all listeners.
callback
Register as an observer of presence for the specified endpoint ids.
endpoints
callback
Set your own presence.
params
params.presence
params.status
callback
Send a message to an endpoint or specific connection of an endpoint.
params
params.to
params.connectionId
params.message
params.type='message'
params.ccSelf=true
params.endpointId
callback
Send a message to a group. When authenticated as an admin via App-Secret
or Admin-Token
, you can pass messages for any endpointId
.
params
params.groupId
params.message
params.endpointId=self.endpointId
callback
Get the members of a group.
params
params.groupId
callback
Join a group.
params
params.groupId
callback
Leave a group.
params
params.groupId
params.endpointId
callback
Get an app by opts.appId
, or get all apps when opts.appId
is not supplied.
opts
[opts.appId]
[opts.headers]
callback
Retrieve a security role
options
[options.appId]
[options.roleId]
callback(err,
Create a security role.
The callback data object contains the id
of the created role,
which can be used for authenticating endpoints.
role
[role.appId]
[role.name]
opts
[opts.headers]
callback(err,
Remove a security role.
opts
[opts.roleId]
[opts.headers]
callback(err)
Listen for events on an instance of this class.
respoke.on('event-name', function (arg) {
});
event
joinAn endpoint (which can include this client) has joined a group.
res
event
leaveAn endpoint (which can include this client) has left a group.
res
Respoke for Node
Setup
Install using npm.
For more details on the node-respoke API see the project documentation. For more on the Respoke service and how it works see the full documentation.
Debugging
This library uses the
debug
npm module. To enable debugging output, use the following environment variable:Error handling
A respoke
client
inherits fromEventEmitter
.If you fail to listen for the error event, errors will be thrown so they are not buried.
Testing
Before you can run the functional tests you will need to complete the following steps.
cp spec/helpers.example.js spec/helpers.js
spec/helpers.js
fileThere are several commands to run the tests.
Building and viewing the source documentation
Respoke Authentication
There are multiple levels of authentication to Respoke, depending on your use case. In general, the hierarchy of credentials is as follows:
Examples
Instantiate a client with an
App-Secret
Obtain a session token for an endpoint
Constructor
new Respoke(options)
Arguments
options
options.appId
options['Admin-Token']
options['App-Secret']
options['App-Token']
options.endpointId
options.autoreconnect=false
options.baseURL=https://api.respoke.io/v1
options.socket
Properties and Methods