Links

Setup and Configuration

Prerequisites and Setup
We require two packages to create a simple client application to receive notifications: 1. socket.io-client (For connectivity) 2. HTTP client-library (For HTTP sending requests)
A typical simple application to get notification enabled is as depicted below. It's a two-step process. -Authentication (/v1/auth) user -Listen (wss://api.relysia.com) for event the "notifiaction"
const axios = require('axios').default;
const { io } = require('socket.io-client')
const relysiaEndpoint = 'api.relysia.com';
(async () => {
// Login into account
const loginObject = await axios.post(`https://${relysiaEndpoint}/v1/auth`, {email: "[email protected]", password: "password"});
console.log('Login completed', loginObject.data);
// Connect websocket for this account
const socket = io(`wss://${relysiaEndpoint}`, {
extraHeaders: {
authToken: loginObject.data.data.token,
},
transports: ['websocket', 'polling']
});
socket.on('error', function(error) {
console.log("Connection Error: " + error.toString());
});
// Listen for messages and log them as notifications arrive
socket.on('notification', function (message) {
console.log('event received', message);
})
socket.on('connect', function(connection) {
console.log('WebSocket Client Connected');
socket.on('close', function() {
console.log('echo-protocol Connection Closed');
});
});
})()