I'm looking for some help with best practices and standards for my first Websockets chat app. I don't have any reference for this– so this is what I have currently implemented. There are many types of Messages that can be sent in this service:
• Text Messages
• Video Messages
• Image Messages
... etc
So imagine chatrooms that multiple people can be in. Here is how I am thinking about sending messages from the client to server:
{
"type": "room.message",
"data": {
"meta": {
"color": "#FFFFFF"
},
"message": "Hello, how are you?"
}
}
This is the design for the message being sent down from the server to the clients connected to the room.
{
"type": "room.message_broadcast",
"data": {
"meta": {
"color": "#FFFFFF"
},
"message": "Hello, how are you?",
"user": userObject
}
}
From a best practices standpoint, does it make sense to follow this type
and type_broadcast
format? Following on from that, does it make sense how I'm structuring the interior data structure regarding type
and data
? Following this same pattern, we would do this for images:
{
"type": "room.image",
"data": {
"url": "https://www.google.com/someimage.png"
}
}
{
"type": "room.image_broadcast",
"data": {
"url": "https://www.google.com/someimage.png"
"user": userObject
}
}
From a design perspective, does this pattern make sense for a realtime chat room with multiple types?
Aucun commentaire:
Enregistrer un commentaire