connect
This method creates and return an instance of an object Socket.io with a connection. This method requires mandatory user authorization.
const socket = await WS.connect()
socket.on('my_event', callback)
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}*
.
Example:
{
"message": "Message",
"attributes": {
"company": {
"identifier": "company",
"type": "string",
"value": "OneEntry"
}
}
}
Schema
message string
Text message
example: Message
attributes: Record<string, any>
Contains event attributes
example:
{
"company": {
"identifier": "company",
"type": "string",
"value": "OneEntry"
}
}
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": {}
}