websocket connection login
- userGet tokenand Get websocket connection informationlater,Log in to the push server, maintain the connection, and then push the data related to the user in real time
- If the connection is connected as a server, the connection must be maintained at all times. Consider the case of disconnection and reconnection. As an H5 client, if you switch to the background, you are advised to reconnect the page to ensure that the page is synchronized to the latest status
Request parameter
field | type | required | desc |
---|---|---|---|
token | string | Yes | token returned by login |
allowPBData | bool | No | allow return protubuf |
Push format
field | type | desc |
---|---|---|
hdr | object | websocket headers, as defined in Table 1 |
Other fields are determined by different message types, and see the definition of each push message
Table 1:websocket headers
field | type | desc |
---|---|---|
code | integer | Status code |
message | string | Message |
msgType | integer | Message type |
reqSN | integer | Request sequence number. Each data sent increases by 1 |
respSN | integer | When the response number is 0, the message is pushed |
Data push
After a successful login, the first data isVehicle online list
Example
Request example
url
ws://localhost:8081/web_session?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbkd1aWQiOjYsInVzZXJHdWlkIjo2LCJ1c2VyTmFtZSI6ImxjYWRtaW4iLCJ1c2VyVHlwZSI6MiwibWF4RGV2aWNlTnVtIjo1MDAsIlRva2VuU3RyaW5nIjoiIiwiaXNzIjoibHl6IiwiZXhwIjoxNjk5MDg0NDAxfQ.oWB6nUUyEJo-ZcQEYUCPb0Td9TLbs43N8l3Jw-4zd_4
ws://localhost:8081/web_session?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbkd1aWQiOjYsInVzZXJHdWlkIjo2LCJ1c2VyTmFtZSI6ImxjYWRtaW4iLCJ1c2VyVHlwZSI6MiwibWF4RGV2aWNlTnVtIjo1MDAsIlRva2VuU3RyaW5nIjoiIiwiaXNzIjoibHl6IiwiZXhwIjoxNjk5MDg0NDAxfQ.oWB6nUUyEJo-ZcQEYUCPb0Td9TLbs43N8l3Jw-4zd_4
Response example
json
{
"hdr":{
"code":200,
"message":"",
"msgType":8000, //View the message type definition
"reqSN":1,
"respSN":0
},"data":{
//According to different message types, the field is not necessarily data, it may be another name, check the definition of each message
}
}
{
"hdr":{
"code":200,
"message":"",
"msgType":8000, //View the message type definition
"reqSN":1,
"respSN":0
},"data":{
//According to different message types, the field is not necessarily data, it may be another name, check the definition of each message
}
}