-
Notifications
You must be signed in to change notification settings - Fork 42
Description
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 Github-Pages and do as little to no 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.
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 some TTL ( time to live ) option
// and maybe vapid is necessary also? don't know what should be required
// its more about the concept then my api proposal
}
// sometime later
initiateConversation(JSON.parse(localStorage.myFriend))with something like pushManager.send(subscription, payload) you can send message to a friends without involving a server - the browser will happily send that push message without worry about any CORS problem.
This could help to establish a WebRTC connection with disabled trickle option - gathering all IceCandidates and transfering them with just one single web push