Twilio TaskRouter: change worker activity when disconnected - javascript

Let's say worker X logged in to our call center app and went online in twilio. He will now be able to receive reservations and respond to people. X lives in a third world country where the internet connection is very unreliable. His internet suddenly cut off while online and he is no longer able to respond to reservations. His activity is still Online and he has no way of changing it because he doesn't have an internet connection. Is there a way to tell twilio to go Offline when the WebSocket connection is lost between the client and the server?
I'm aware that we have disconnectActivitySid in TaskRouter.js but it is only fired on window.unload event and doesn't cover the cases where the browser crashes or we have internet connectivity problems.

Twilio developer evangelist here.
The only way to do this today would be to have the Worker receive a next Reservation, but have a Workflow ReservationTimeout of a semi-low value (10-15 seconds) and to utilize the Workspace’s TimeoutActivitySid to push the Worker to Offline.
With that setup, if the Worker loses connection (but is Idle), and receives a Reservation and is able to reconnect before that Reservation Times out (in that 15 second window), they will presented the Reservation with the JS SDK. So nothing will be lost. If they do not reconnect within that timeout window, the Worker will be pushed to Offline, and another Worker will be eligible to pick up the Task.
Let me know if that helps at all.

Related

chat problem: socket-io goes offline when mobile is locked - how to see the newly received messages?

i am developing a social network with a chat messenger. it's a responsive web application.
the messages are saved on mongo db, and then sent instantly through socket io.
the problem is when computer is sleeping/mobile is locked,
the socket io connection goes off.
and when coming back from sleep/lock mode, the connection doesn't re-create.
let's say a user got couple of messages when his phone was locked, and the webpage was open there waiting for him.
even if i re-connect the socket when user starts interacting with webpage again, still the user will not see the instant messages he was getting, because the messages from mongo arrive only when entering the app for the first time.
the only solution i can think about is that when coming back from sleep, the web page should reset itself and loads again with all the data from mongo db.
do you have any better idea? is auto refreshing after detecting waking up from sleep mode, is even possible?

Is there a way to schedule offline notifications in a pwa?

I know you can send push notifications to a user who has installed the pwa. However, this always requires a server which sends that notification and also the end user device to be online to recieve and show it.
I was wondering if there is a way to "schedule" a push notification to be shown later, like it is possible on Android to be able to realize something like reminders for events, without the need to have an internet connections.
EDIT: Since Chrome 80, notification triggers are available as an origin trial.
There are at least 3 web APIs/specs in the development related to some form of the scheduled tasks. None of them are in production though.
Periodic Background Sync API
Explainer: https://github.com/beverloo/periodic-background-sync
Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=925297
Status: https://www.chromestatus.com/feature/5689383275462656 (in dev)
Main feature: it enables a web app to run tasks periodically while the device has network connectivity
Notification Triggers (a.k.a. Scheduled Notification API / Event Alarms)
Explainer: https://github.com/beverloo/notification-triggers
Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=891339
Status: https://www.chromestatus.com/feature/5133150283890688 (proposed, part of Project Fugu)
Main feature: this allows to show a notification (nothing else) reliably at a specific time in the future, even if the device is offline
Scheduled Task API (Generic Alarms)
Explainer: internal design docs only
Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=889077
Status: TBD, part of Project Fugu
Main feature: schedule code to run at a specified time in the future - cron for the Web
So answering the original question: your choice is Notification Triggers API. Hopefully this will land in the browsers soon.

Proper procedures for reconnecting WebRTC Peer connection?

I'm developing a group voice chat application using WebRTC and React.
I have managed to establish a connection and the voice chat works fine on first connection.
The way it works is like this:
User A joins chat room.
User B joins chat room.
User A enables audio through a toggle button - this notifies the signaling server that they're open for any WebRTC connections.
User B enables audio through a toggle button - they now through the server establish the WebRTC connection process to anyone who has enabled audio (being user A in this case).
This has worked fine so far. My issue is establishing a connection a second time around in the scenario of:
Both users have audio enabled. Voice comms working fine.
User B toggles audio - disabling it. User A remains active.
User B toggles audio again to reconnect to user A.
I get the following error:
DOMException: Failed to execute 'setRemoteDescription' on 'RTCPeerConnection': Failed to set remote answer sdp: Called in wrong state: kStable
I understand this error means that there's an issue with the connection order. So I figured this could be to do with not having a adequate disconnection process.
So I implemented a feature that when User B disables audio, it sends all other users in the room a message to remove that persons Peer_Connection object from the peer conection array on each users local state. But this is to no avail.
I'm confused as to why this is happening because if I exit the chat room and re-enter on both users, the connection can be re-established once more, so I assume it has something to do with there being remnants of the old connection causing issues with the new.
(It also works if both users have audio enabled, the one disables, leaves the room, comes back and enables all while the first user had it enabled the whole time. So an error on part with the client who sends the offer?)
As always, any tips and help would be appreciated, thank you.
Reconnection was not possible. For anyone seeking a solution for a similar issue:
Instead of reconnection, simple disable the audiotracks. Locally this means no one gets any audio feed from you. Disabling remote audiotracks mutes the audio for yourself obviously. Muting both means there's no audio coming in or out, which can simulate a disconnection with a toggle switch while the person remains in the same room.

Can a service worker update the cache without an open tab?

I want to give the user a speed feel when he accesses my website. If I cache the initial page in service worker, then I can achieve it. But I am having the following doubts.
Is there any way to update that cache even user does not have any tabs with my website?
Is there any memory limitation?
1) Not in a simple way - your Service Worker is suspended until something wakes it up, for example the user opening your app. Or the push message. So you might run your cache update flow in a push message handler and send the push to all subscribed users whenever the update should happen. But you have to be aware that there are limitations of how many pushes can the app receive and/or how long the handler can run.
"Normally" this is done when the new Service Worker version is installing and requires reload (or manual handling) to take effect.
2) Yes, the general storage limit applies. It is OS-specific and you can query for the estimate with Quota Estimation API (Chrome only by now).

What's the best way for background polling in Windows 8 Metro apps?

I'm working on a Win 8 javascript app that has rss-reader-like capabilities. It should repeatedly check a server for new posts and display a toast, if a new post was found.
My question is, if I should use a background job with a time trigger (that is limited to an interval of 15 minutes) or if a setTimeout / setInterval wouldn't be the better way.
As far as I understand the app lifecycle, my app can be suspended by Windows at any time it is not focussed and Windows decides that timepoint on itself. And if the app is suspended once, neither background jobs will work, nor will the setTimeout / setInterval fire.
If I may, I'd suggest rethinking the notification mechanism here.
If you want to use a toast notification, I'd suggest a push notification. It does require a require a cloud service that does the polling of articles for you and then pushes the notification to subscribing clients; however, it won't tax the battery life of the client nearly as much as a polling trigger.
An issue with toast notifications is that they can be easily missed, so if you want to inform the user of unread articles, you may want to consider a badge notification that will persist on the application tile (like you see on the Mail application). Then at a glance the user will know there are unread articles, versus knowing that only if they happened to see the incoming toast.
Tile and badge notifications can also be updated periodically, which is similar to what you wanted to do with toast, but the mechanism for doing so is much easier. The challenge here though is that periodic notifications aren't generally personalized, that is every user of your app would see the same badge/tile unless you did a bit more work on the server side.

Categories

Resources