When using the Guest Chat API, a subscription to v2.conversations.chats.{id} is established as we initialize the websocket with the return response from the POST /api/v2/webchat/guest/conversations.
After that, "Websocket Heartbeat" events are send out every 10 seconds to indicate the subscription is alive.
We want to simulate the subscription is lost and needs to be reestablished by creating a new Websocket connection (as per the docs), instead of manually waiting for it to be lost (typically takes a fairly long time and a bit hard to consistently recreate).
We could close the websocket and create a new one, but there are also a Notification API that I was thinking we could try.
However, this Notification API doesn't seem to support the Guest Chat. So to simulate "Websocket Heartbeat" events firing/subscription loss we cannot use that approach. Is that correct?
The GuestChat API notification is different from the Notification API.
I mean it shares the same principle for the WebSocket heartbeat (that can also help you detect a loss of connection) but the opening of notification channel and subscription to topics is different.
With Guest Chat API, the websocket is created/assigned when you initiate a new chat session.
If you disconnect and try to reconnect, the same WebSocket uri would have to be used on the Guest Chat client.
An example would be with Widgets v2. Let's say you load a page with Widgets v2 enabled into it, and start a chat. If you browse to another page where widgets v2 is also enabled or if you refersh the page, the Widgets v2 will automatically reconnect the chat session. To do so, it will reopen the websocket to the same URI, will use the same JWT token in its request (Widgets v2 store that in cookies I think or maybe localStorage).
Moreover, with Guest Chat, you are automatically subscribed to the topics necessary to receive message/member-join/member-leave/member-change.
With Notifications API (for an agent application or a server application connecting to PureCloud), you can explicitly request a channel, and you then have to request each topic you want to subscribe to (in a different API request). Moreover, the websocket channel you request is not tied/linked to a specific conversation.
So I don't think there is a way to simulate the subscription is lost. I mean nothing easy I can think of on my side. Or maybe disconnecting your computer from network for a while, or stopping the chat conversation in PureCloud (but in this case, you will not be able to reconnect to the same session using the same WebSocket URI - it should generate an error back to the Guest Chat client), or opening the websocket another time with same URI (like what happens with Widgets v2 when refresh/browse to a different page is done).
We are simulating loss of heartbeat in testing now by ignoring the events on the client side with a console toggle, and triggering reconnect with another console toggle.