web-push-libs / pywebpush

Python Webpush Data encryption library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Send Push to Offline Devices (When it comes Online)

salimbuet09 opened this issue · comments

Hi,

When my browser is open and I send a push, Browser receives it almost instantly (No Issue).
But when Browser is closed and I send a push. After 2 minutes If I open the browser I am not receiving any push. But I should receive push. (it works fine in php-web-push, but not working in pywebpush).

requirements.txt

http-ece>=1.1.0
requests>=2.21.0
six>=1.15.0
py-vapid>=1.7.0
pywebpush

push.php

from pywebpush import webpush
try:
    endpointData = json.loads(getN['endpointData'])
    subscriberData = {
        "endpoint":endpointData['endpoint'],
        "keys": { "auth": endpointData['keys']['auth'], "p256dh": endpointData['keys']['p256dh'] }
    }
    webpush(
    subscriberData,
    thisPayload,
    vapid_private_key=vapid_private_key,
    vapid_claims={"sub": "mailto:team@example.com"},
    timeout=None
    )
except:
    print('F')

O I found it, it's ttl

Can you elaborate on this TTL thing?

NVM, I also found it. It works great now!

Yeah, as a bit of clarity:

TTL is the number of seconds that a message should stay valid. Basically "If you can't delivery it right away, hang onto it for this long". Setting a TTL:0 means "If you can't deliver this message RIGHT NOW, get rid of it."

The max TTL you can set depends on the service you're talking to, but for most, it's about a month. Honestly? I'd probably pick something more like 24 hours (86400). Notifications are supposed to be short, timely messages. You probably don't care that you got a new email 27 days ago, or that you package arrived 2 weeks ago, neither do your recipients.

I think it's better to make this field required because the default of 0 is pretty useless in most situations.

Good news?

For most push services, the field is required. It's just that the default value is 0.

It's just that the default value is 0.

I mean in the library itself, defaulting to 0 is the same thing as not required.