FrostDigital / fruster-api-gateway

MIT License
0 stars 0 forks source link

[FEATURE] Web sockets aka fruster web bus #22

Closed Florry closed 7 years ago

Florry commented 7 years ago

Adds web sockets (aka fruster web bus) to api gateway.

To send a message to a client, simply send a request to ws.:userId.>.

Example: sending to ws.79f76857-e103-4fed-9190-62d19eb1c1bb.new-message (for a specific user) or sending to ws.*.new-message (for all connected user):

{
    "redId":"4d608585-23c8-469a-9d66-16289ffaf88a",
    "data":{
        "totalMessageCount": 32,
        "newMessages": 1
    },
    "transactionId": "2162c0d8-aa8f-41a9-937c-7d9a14b545b9"
}

Client connects to ws://localhost:3000 using the fruster web bus client (See https://github.com/FrostDigital/fruster-web-bus-client);

var bus = new FrusterWebBusClient("ws://localhost:3000");

bus.subscribe(`ws.${userService.userId}.new-message`, (msg) => {
    messageService.totalMessageCount = msg.data.totalMessageCount;
    messageService.newMessags += msg.data.newMessages;
});

bus.subscribe("ws.${userService.id}.friend-service.new-friend-request", (msg) => {
    console.log(msg.data.message);
});

bus.onError(err => {
    console.error("ERROR", err);
});

bus.onClose(closeEvent => {
    console.error("CLOSED", closeEvent);
});
joelso commented 7 years ago

retest this please