|
|
@@ -46,6 +46,17 @@ def donotify(sub, sleep=10): |
|
|
|
|
|
|
|
print('sending notification...') |
|
|
|
try: |
|
|
|
# Mozilla appears to not require the vapid key. |
|
|
|
# Chrome requires the vapid key. |
|
|
|
if True: |
|
|
|
kwargs = dict(vapid_private_key=None, |
|
|
|
#vapid_claims=None, |
|
|
|
) |
|
|
|
else: |
|
|
|
kwargs = dict(vapid_private_key=VAPID_PRIVATE, |
|
|
|
vapid_claims={ "sub": VAPID_SUBJECT }, |
|
|
|
) |
|
|
|
|
|
|
|
webpush( |
|
|
|
subscription_info = sub, |
|
|
|
data = json.dumps({ |
|
|
@@ -53,10 +64,9 @@ def donotify(sub, sleep=10): |
|
|
|
"body" : "Yes, it works!", |
|
|
|
"icon" : "static/i-ico.png", |
|
|
|
"image" : "static/i-banner.png" |
|
|
|
}), |
|
|
|
vapid_private_key = VAPID_PRIVATE, |
|
|
|
vapid_claims = { "sub": VAPID_SUBJECT } |
|
|
|
}), **kwargs |
|
|
|
) |
|
|
|
print('done') |
|
|
|
except WebPushException as ex: |
|
|
|
print(ex) |
|
|
|
|
|
|
@@ -71,7 +81,7 @@ def push(): |
|
|
|
# (B3-1) GET SUBSCRIBER |
|
|
|
sub = json.loads(request.form["sub"]) |
|
|
|
import sys |
|
|
|
print('sub:', repr(sub), file=sys.stderr) |
|
|
|
print('sub:', repr(json.dumps(sub)), file=sys.stderr) |
|
|
|
|
|
|
|
# (B3-2) TEST PUSH NOTIFICATION |
|
|
|
result = "OK" |
|
|
|