Skip to main content

connect

This method creates and return an instance of an object Socket.io with a connection. This method requires user authorization.

Description

When the attributes change (if the user is subscribed to the corresponding event and the Websocket option is active in the event) The "attributes" field always contains event attributes (the "events" field), and depending on the selected type of event for the catalog or form, the fields with the attributes "product" contain product attributes, and "user" contains fields from the user form, respectively. For a product, there is an additional field "title" (product name as a string), and for registration and code submission forms, there are additional fields "code" and "email."

The attribute value is stored in the format *key - marker*, *value - {type, identifier, value}*.

Examples

Minimal example

// connect() is synchronous — do not await it.
const socket = WS.connect();

socket.on('my_event', callback);

ℹ️ socket.io-client is imported the first time connect() is called, so it stays out of bundles that never open a socket. Handlers registered on the returned socket are queued and replayed before the connection can deliver anything, so nothing is lost — see Bundle Size & Module Formats.

Product Example:

{
"product": {
"id": 10,
"info": {
"title": "Pink Planet",
},
"status": {
"identifier": "available",
"info": {
"title": "ADD TO CART"
}
},
"attributes": {
"currency": {
"identifier": "currency",
"type": "string",
"value": "USD"
}
}
}
}

User Example:

{
"user": {
"notificationData": {},
"attributes": {}
},
"order": {
"id": 1,
"attributes": {}
}
}

Order Example:

{
"user": {
"notificationData": {},
"attributes": {}
},
"order": {
"id": 1,
"attributes": {}
}
}

Form example:

{
"email": "string",
"formData": {}
}

Example response

{
"message": "Message",
"attributes": {
"company": {
"identifier": "company",
"type": "string",
"value": "OneEntry"
}
}
}

Response schema

Schema: Socket

message string
Text message
example: Message

attributes: Record<string, any>
Contains event attributes
example:

{
"company": {
"identifier": "company",
"type": "string",
"value": "OneEntry"
}
}