-
-
Notifications
You must be signed in to change notification settings - Fork 12
Protocol
Johnny Mast edited this page Apr 19, 2020
·
9 revisions
In the index.php javascript, the user object is randomly generated by @fzaninotto/faker. This is emulating a random user from your database.
{
"username": "Mabelle Zboncak",
"id": "6902f0cb44ab8e48195d585dad60ec0f"
}This object is communicated over the network to the WebSocket server. That being said, lets talk a litle bit more about the loop of the protocol.
Before receiving any information from the WebSocket server we need to register the user with the User Registration call. After the user is registered to the WebSocket server you can start sending User list requests on an interval (WebSocket.js does this every 2000 milliseconds). With the User list response object, you can update the UI.
WE ARE Mabelle Zboncak
{
"user": {
"username": "Mabelle Zboncak",
"id": "6902f0cb44ab8e48195d585dad60ec0f"
},
"type": "registration"
}None
{
"user": {
"username": "Mabelle Zboncak",
"id": "6902f0cb44ab8e48195d585dad60ec0f"
},
"type": "userlist"
}{
"users": {
"82": {
"username": "Mabelle Zboncak",
"id": "6902f0cb44ab8e48195d585dad60ec0f"
}
},
"type": "userlist"
}{
"user": {
"username": "Mabelle Zboncak",
"id": "6902f0cb44ab8e48195d585dad60ec0f"
},
"message": "dd",
"to_user": null,
"type": "message"
}{
"user": {
"username": "Mabelle Zboncak",
"id": "6902f0cb44ab8e48195d585dad60ec0f"
},
"message": "aa",
"to_user": null,
"type": "message"
}We are Tavares Bergstrom V
{
"user": {
"username": "Tavares Bergstrom V",
"id": "30fb2c45e59353e83dcdbc625cdb7a61"
},
"message": "abc",
"to_user": {
"id": "c756f90f3e832c6c92b45b4bfe11c847",
"username": "Dr. Kailey Douglas"
},
"type": "message"
}We are Dr. Kailey Douglas
{
"user": {
"username": "Tavares Bergstrom V",
"id": "30fb2c45e59353e83dcdbc625cdb7a61"
},
"message": "abc",
"to_user": {
"id": "c756f90f3e832c6c92b45b4bfe11c847",
"username": "Dr. Kailey Douglas"
},
"type": "message"
}We are Tavares Bergstrom V
{
"user": {
"username": "Tavares Bergstrom V",
"id": "30fb2c45e59353e83dcdbc625cdb7a61"
},
"type": "typing",
"value": true
}{
"user": {
"username": "Tavares Bergstrom V",
"id": "30fb2c45e59353e83dcdbc625cdb7a61"
},
"type": "typing",
"value": true
}