[w3c/push-api] A javascript api for sending push notifications to others (#303)

When you subscribe for push you receive a endpoint and keys for generating push and payloads. 
You can forge a payload fully in the browser but not all endpoints don't respond with CORS headers.
(Got a 401 when i was sending a OPTION preflight to google)

That creates a problem: A browser is not able to send a push notification to another person

If two persons have exchanged subscription shouldn't they be able to ping eachother to initiate a conversation without having to go throught a backend signaling server?

I'm building a PWA and i want to host it on a static site like GH-Pages and do as little server stuff as possible. And a push subscription exchange only has to happen once - then you can store the subscription in localstorage or something and reconnect a friend later again and again without having to rely on a server.

```js
function gotFriendsSubscription (friendsSubscription) {
  localStorage.myFriend = JSON.stringify(friendsSubscription)
})

async function initiateConversation (friendsSubscription) {
  const { pushManager } = serviceWorkerRegistration
  const pushSubscription = await pushManager.getSubscription()

  const sdp = await (
    // - create RTCPeerConnection
    // - create DataChannel
    // - wait for all iceCandidate to complete
    // - generate offer
    // - disable trickle
  )
  
  const payload = JSON.stringify({
    msg: "Hi lets start chatting",
    sdpOffer: sdp,
    // share my subscription so he can respond back with a sdpAnswer
    subscription: pushSubscription 
  })

  // My proposal:
  pushManager.send(friendsSubscription, payload)
  // maybe send som TTL ( time to live )
}

// sometime later
initiateConversation(JSON.parse(localStorage.myFriend))
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/push-api/issues/303

Received on Friday, 30 November 2018 17:33:06 UTC