## Push notifications

To receive incoming calls in the browser via W3C Web Push API, enable managed push:

```javascript
// 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:

```javascript
// 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.

```javascript
// 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](https://github.com/sinch/rtc-reference-applications/blob/master/javascript/samples/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](https://download.sinch.com/js/latest/reference/interfaces/CallClientListener.html#onincomingcall-1).

Note:
For use cases requiring only outgoing App-to-Phone, App-to-SIP, or Conference calls, calling `sinchClient.setSupportManagedPush` is not required. You can place these calls directly once the Sinch client is started.