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