Events

While HTTP-handlers always follow the request-response pattern, Durga provides a simple "fire-and-forget" handler. We call it event. Simply define event-handlers and let clients execute them without response.

server.event('hello-world', ({ payload }) => {
    console.log(payload); // should log s.th. like { now: 93476592355 }
});

client.emit('hello-world', { now: Date.now() });

It's also possible, that the server sends events at any time to the client.

server.event('foo', ({ payload, emit }) => {
    emit('hello-world', payload);
});


client.event('hello-world', payload => console.log(payload));
client.emit('foo', { test:123 });

If you would like to emit events to a group of connected clients there is a handy feature called: rooms

results matching ""

    No results matching ""