An API key plays an important role in identitfying your app when publising events or conneciing to the realtime services. Head over to the
dashboard to register for a free account and create an API key if you havn't already.
string
generateTokenResponse()
Responsible for generating a secure token to be sent as an HTTP response, which can be exchanged for access to real-time services via @relaybox/client. To learn more about auth tokens, please refer to the Auth Tokens documentation.
Include a clientId to associate an identity with the token. You must provide a clientId for
a connection using the generated token to participate in a room's presence set.
-
expiresIn
(optional)
The length of time specified in seconds before the generated token expires and can no longer
be used to connect to real-time services
900
permissions
(optional)
Optional dynamic permissions overrides specific to the token being generated. To learn more
about permissions please see
Dynamic Permissions
["*"]
Example:
1// Generate a token response with a clientId and custom expiry2const tokenResponse = relayBox.generateTokenResponse({
3clientId: 123,
4expiresIn: 3005});
67// Generate a token response attaching dynamic permissions8const permissions = {
9myRoom: [
10'subscribe',
11'publish',
12'presence',
13'metrics',
14'history'15 ];
16};
1718const tokenResponse = relayBox.generateTokenResponse({
19 permissions
20});
publish()
Responsible for publishing an event to a named "room".
**Room Name (required):** The name of the room to publish the event to
string
2
**Event Name (required):** The name of the published event. Connections subscribing to this
event by name will receive the event.
string / function
2
**Data (optional):** The data to be sent as the event payload
string / object
Example:
1const data = {
2hello: 'world'3};
45// Publish an event named 'message' to 'room:one' containing data payload6const response = relayBox.publish('room:one', 'message', data);
License
This project is licensed under the MIT License - see the LICENSE file for details.