I have a task to create javascript realtime app. Server side is ready (wss://), I have to create client-side.
The main tasks I have problems with:
The client can ping the server to check your connectivity. Client does a ping, including the sequence number (which allows to trace the exact ping duration).
{
"$type": "ping",
"seq": 1
}
server will respond:
{
"$type": "pong",
"seq": 1
}
Client request
{
"$type": "subscribe_tables"
}
Server will respond with the list of tables, and update the client with table_added, table_removed and table_updated messages whenever the status has changed.
{
"$type": "table_list",
"tables": [
{
"id": 1,
"name": "table 1",
"description" : "one, two"
}, {
"id": 2,
"name": "table 2"
"description" : "two, three"
}
]
}
table_updated event
{
"$type": "update_table",
"table": {
"id": 3,
"name": "table - Foo Fighters",
"participants": 4
}
}
Question: I know, that I can use new EventSource()
, is this correct? How can I send data $type
, for example with it?