Skip to main content

Quick Start

Intro

In the Trisk, we use WebSockets to implement real-time, live-updating user interfaces. When some data is updated on the server, a message is typically sent over a WebSocket connection to be handled by the client. This provides a more robust, efficient alternative to continually polling your application for changes.

To implement WebSockets, we used Laravel Echo. This JavaScript library makes it painless to subscribe channels and listen for events broadcast by Laravel. You may install Echo via the NPM package manager.

npm i -S laravel-echo

But this is just a socket wrapper, and you still need to import Socket.IO into your project.

Pay attention! Vendor lock limitation is a socket.io version 2.3.0, you can download it from the npm by the link or:

npm i -S socket.io-client@2.3.0

Headers

The server URL is

https://api.trisk.io/socket.io/

Every request should have default Headers:

Accept: application/vnd.api+json
Content-Type: application/vnd.api+json

Authorization token should be set via Authorization Header:

Authorization: Bearer t318a31a-0bcf-48d1-9350-a6ae499007c0

and X-CSRF-TOKEN Header:

X-CSRF-TOKEN: t318a31a-0bcf-48d1-9350-a6ae499007c0

API has a multi-tenant application scheme. Therefore, every request should have X-Domain Header:

X-Domain: example

X-API-KEY this is a Public key from the For Developer menu

X-API-SECRET this is a Secret key from the For Developer menu

An example of the subscription request where:

[
"subscribe",
{
"channel": "private-formulas.task-3965cf46-8e85-491e-a00b-a6cadfd6045e",
"auth": {
"headers": {
"Content-Type": "application/vnd.api+json",
"Accept": "application/vnd.api+json",
"Authorization": "Bearer t318a31a-0bcf-48d1-9350-a6ae499007c0",
"X-Domain": "example",
"X-API-KEY": "B5TPwTAbgb",
"X-API-SECRET": "a31a-0bcf-48d1-9350-a6ae4990",
"X-CSRF-TOKEN": "t318a31a-0bcf-48d1-9350-a6ae499007c0"
}
}
}
]