Websocket Connections
The WebSocket Connection is an advanced technology that makes it possible to open a two-way interactive communication session between the user's browser and a server. With this, a developer can send a request to a server and receive event-driven responses without having to poll the server for a reply.
Samdock Microservices have WebSocket connections implemented to increase the throughput of the endpoint calls. For any endpoint having a 200
response with a message indicating a trigger, means the developer needs to have a WebSocket client developer in order to receive the result against the microservice call.
e.g. POST /api/contacts/Persons Add Person responds with a triggered notification which indicates a websocket action is required.

Websockets Structuring within Microservices
Currently, Samdock Microservices has three specific cases within which the Websockets are handled.
- activities
- activities-by-person
- activities-by-organization
Keep yourself informed
Do make sure to keep a track of this space to get an update over new Websocket implementations within Samdock Microservices.
There are several steps to be followed to set up the WebSockets connections specific to the case.
Setting up WebSocket Connection
Setting up a WebSocket connection is similar for all three available cases. The developer needs to change the path accordingly.
activitiesSocket: {
url: ‘dev.samdock.app’,
path: ‘/api/activities/socket.io’,
}
//Please note that path can be set as per the available cases.
Once the WebSocket connection is established, the Developer will be able to subscribe to the channel and receive data on the go.
activities
this.activitySocketService.emit(‘activities’, {
headers: { authorization: `Bearer ${this.authService?.jwt?.token}` },
});
As this sets up the live connection, the developer will be able to receive new information about new activities that came after specific actions and can update the activity stream with the latest news. Here is a list of currently available events.
- ActivityAddedEvent
- ActivityEditedEvent
- ActivityDeletedEvent
- PersonDeletedEvent
- OrganizationDeletedEvent
- DealDeletedEvent
- TaskDeletedEvent
Future Plans
Plans are in place to mirror all possible actions from EventStore for it to be able to handle more options, like notifying the user about editing/deleting entity performed successfully or to have the possibility to chain complicated requests without problems with uncompleted data
activities-by-person
This is a browse request which will provide data right after emitting this event and provide activities for a specific person.
this.activitySocketService.emit(‘activities-by-organization’, {
_organizationID: organizationID,
headers: { authorization: `Bearer ${this.authService?.jwt?.token}` },
});
activities-by-organization
This is a browse request which will provide data right after emitting this event and provide activities for a specific organization.
this.activitySocketService.emit(‘activities-by-organization’, {
_organizationID: organizationID,
headers: { authorization: `Bearer ${this.authService?.jwt?.token}` },
});
Receiving Events
importSocketUrl: ‘dev.samdock.app’,
importSocketPath: ‘/api/contacts/import/socket.io’,
Emitting to ‘connectImportID’
This will set up a live connection against which the developer will be able to receive events named as below.
- importError: fired when something went wrong with import.
- imported: fired when the progress of importing changed. Import started or steps of the import.
- importFinished: fired when import finished.
Updated about 2 years ago