Emit an event to a room in a collection. A successful emit request will respond with OK (17)
Syntax
[scope, room_id, event, ...args]
The room_id
parameter accepts either a room-ID or room-name to designate the desired room.
Room names require ThingsDB version 1.7.0 or higher.
The args
are optional argument to send with the event.
The socket needs to be authorized before sending a emit
request.
See the auth example for how to authorize a socket connection.
As an example we assume that we have a room with Id 17 in collection stuff.
This is the data we want to pack (emit event “new-message” to room Id 17 with one argument “Hello!"):
["//stuff", 17, "new-message", "Hello!"]
Serializing the above using MessagePack results in the following 29
bytes:
\x94\xa7//stuff\x11\xabnew-message\xa6Hello!
Now we create the header. For this example we just use Id 0:
\x1d\x00\x00\x00
\x00\x00
\x28
0xd7
Sending the Emit package
\x1d\x00\x00\x00\x00\x00\x28\xd7\x94\xa7//stuff\x11\xabnew-message\xa6Hello!
Responding OK package
\x00\x00\x00\x00\x00\x00\x11\xee