0

We have a carline checkout system, where school users:

Release coordinators Teachers Parents use app to check-in to app and app sends real-time message on school uniquely created group so that all receive that parent has arrived, now release those students. To achieve real-time link we integrated azure webpub sub in our app. What we do is when parent/teacher/release-cordinators log into app we create one group per school and so that anything happens on their group all connected devices of this particular schools gets the message.

We are experiencing a strange issue where some of the clients dont receive live updates/messages. Here's my server side code that creates unique url for each client by binding into its school uuid. When each client logs in it gets its unique url and linked with its related group.

app.get('/negotiate', async (req, res) => {
    let userId = req.query.id;
    if (!userId) {
        res.status(400).send('missing user id');
        return;
    }
    let accessTokenRules = [`webpubsub.joinLeaveGroup.${req.query.uuid}`, `webpubsub.sendToGroup.${req.query.uuid}`];
    let token = await serviceClient.getClientAccessToken({ userId, "expirationTimeInMinutes": 1440, roles: accessTokenRules});
    res.json({
        url: token.url
    });
});

Later, this is how i send and receive from client side app:

const socket = new WebSocket(urlReceivedAbove, 'json.webpubsub.azure.v1');

socket.onopen = (evt) => {
     // when one client socket gets open i send a join group request to school group so that it start receiving/sending on that node
            
     socket.send(JSON.stringify({
           type: 'joinGroup',
           group: uuid, // same uuid of school so that it is in same group
           dataType: "json",
           data: {"methodName": "joiningGroup", "payLoad": ""}
     }));
};


socket.onmessage = (data) => {
// further processing 
}

Issue we are having when more than 200 people connected on one school group, some of the connected clients missed messages. Can we fix this or have some workaround on it?

I checked on azure help they say this protocol json.reliable.webpubsub.azure.v1 can be used as well.

Please help or advise, we need reliable message delivery on each connected client.

maverickosama92
  • 2,685
  • 2
  • 21
  • 35

1 Answers1

1

Here is the JS client SDK that implements auto-reconnect and reliable message delivery on top of json.reliable.webpubsub.azure.v1 https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/web-pubsub/web-pubsub-client

Here is the quickstart using the client-side SDK https://learn.microsoft.com/azure/azure-web-pubsub/quickstart-use-client-sdk?tabs=javascript

vicancy
  • 323
  • 3
  • 11
  • Thanks, I'll try the js-sdk and will let you know how it goes. BUT one question if an old user is getting connected using this protocol json.webpubsub.azure.v1 and we release a new app that is integrated with the new protocol json.reliable.webpubsub.azure.v1. Would this work? Or both clients should be using the same protocol when connecting Pubsub? – maverickosama92 Apr 12 '23 at 09:44
  • Also is there any limit to join group? How many clients can connect to one group? – maverickosama92 Apr 12 '23 at 14:40
  • Clients can connect using different subprotocols, as long as they are connected to the same hub and joining the same group, they can publish messages to and receive messages from the same group. And there is no hard limit on joining groups or clients in one group. The group in Web PubSub is some kind of group session and is light-weighted. When there are clients in the group, the group exists, when no client is in the group, the group is considered as not exist – vicancy Apr 13 '23 at 02:18
  • Thanks. One last question would you suggest creating multiple hubs or one hub to connect all the companies/school and their respective users? I am currently creating one hub, that has unique sub groups and all the users of specific group connect to their own group. – maverickosama92 Apr 13 '23 at 10:09
  • 1
    Do you have scenarios to broadcast messages to all these companies/schools? (If there are, then use one hub) Do you have event handlers registered? (If you have, configuring one hub is relatively convenient, configuring hub settings is comparatively heavy) If you are using subprotocol and its "sendToGroup" feature, using groups sounds good to go. – vicancy Apr 18 '23 at 02:55
  • Thanks got it. Working on it. Will let you know how it goes. – maverickosama92 Apr 18 '23 at 15:07
  • Hey can you please provide me a cdn link or one line file for @azure/web-pubsub-client. I need to include as js file and use it. I have compiled it using webpack cli but couldn;t figure out how to use it. Please help. – maverickosama92 May 12 '23 at 19:56
  • There is not yet a one-line file, and here is a browser version sample FYI, use `npm run build & npm run start` to start https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/web-pubsub/web-pubsub-client/samples-browser – vicancy May 15 '23 at 07:48
  • I have ionic v1 app that is being built with old JS version. I can't run it on node. Its build as static assets and the bundle into ios/android via gulp and i wanted to include it like we include any js lib, for example firebase has js sdk and i can just include in index.html and it works. Please guide the above link that you shared will only work if i am serving my code on server. Any workarounds? – maverickosama92 May 15 '23 at 21:17