Skip to content

Protocol

Johnny Mast edited this page Apr 19, 2020 · 9 revisions

User information

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 Registration

Request

{
  "user": {
    "username": "Mabelle Zboncak",
    "id": "6902f0cb44ab8e48195d585dad60ec0f"
  },
  "type": "registration"
}

Response

None

User list

Request

{
  "user": {
    "username": "Mabelle Zboncak",
    "id": "6902f0cb44ab8e48195d585dad60ec0f"
  },
  "type": "userlist"
}

Response

This response object is sent back to the user requesting the userlist.

{
  "users": {
    "82": {
      "username": "Mabelle Zboncak",
      "id": "6902f0cb44ab8e48195d585dad60ec0f"
    }
  },
  "type": "userlist"
}

Sending message

{
  "user": {
    "username": "Mabelle Zboncak",
    "id": "6902f0cb44ab8e48195d585dad60ec0f"
  },
  "message": "dd",
  "to_user": null,
  "type": "message"
}

Receiving message

{
  "user": {
    "username": "Mabelle Zboncak",
    "id": "6902f0cb44ab8e48195d585dad60ec0f"
  },
  "message": "aa",
  "to_user": null,
  "type": "message"
}

Sending Private message

This package will send a message from user Tavares Bergstrom V to the user Dr. Kailey Douglas.

{
  "user": {
    "username": "Tavares Bergstrom V",
    "id": "30fb2c45e59353e83dcdbc625cdb7a61"
  },
  "message": "abc",
  "to_user": {
    "id": "c756f90f3e832c6c92b45b4bfe11c847",
    "username": "Dr. Kailey Douglas"
  },
  "type": "message"
}

Receiving private message

Only the targeted user will receive this package. In the example below we are the targeted user Dr. Kailey Douglas and we receive an private message from Tavares Bergstrom V.

{
  "user": {
    "username": "Tavares Bergstrom V",
    "id": "30fb2c45e59353e83dcdbc625cdb7a61"
  },
  "message": "abc",
  "to_user": {
    "id": "c756f90f3e832c6c92b45b4bfe11c847",
    "username": "Dr. Kailey Douglas"
  },
  "type": "message"
}

Typing indicator

sending

We are Tavares Bergstrom V

{
  "user": {
    "username": "Tavares Bergstrom V",
    "id": "30fb2c45e59353e83dcdbc625cdb7a61"
  },
  "type": "typing",
  "value": true
}

Receiving

{
  "user": {
    "username": "Tavares Bergstrom V",
    "id": "30fb2c45e59353e83dcdbc625cdb7a61"
  },
  "type": "typing",
  "value": true
}
Clone this wiki locally