To receive incoming calls in the browser via W3C Web Push API, enable managed push:
// Enable managed push with the default Service Worker path (sw.js)
sinchClient.setSupportManagedPush();By default, Sinch expects a Service Worker file at sw.js in your current directory. If you use a custom path or filename, pass it explicitly:
// Use a custom Service Worker path
sinchClient.setSupportManagedPush("/assets/service-workers/sinch-sw.js");Add a basic Service Worker that forwards push payloads to open tabs. This lets SinchClient process the payload and trigger CallClientListener.onIncomingCall when a new call arrives.
// sw.js (basic example)
self.addEventListener("push", (event) => {
const body = event.data?.json?.() ?? null;
event.waitUntil(
self.clients
.matchAll({ includeUncontrolled: true, type: "window" })
.then((clients) => {
clients.forEach((client) => {
client.postMessage({
visible: client.visibilityState === "visible",
data: body,
});
});
})
);
});For a more advanced sw.js that handles mobile browser limitations, see the reference app: voicecall/sw.js
When managed push is enabled and your Service Worker forwards messages as above, incoming calls will be delivered to onIncomingCall in CallClientListener.
Note
If your app only makes outgoing calls (no incoming), don’t call
setSupportManagedPush. Outgoing calls work aftersinchClient.start().