Firebase Cloud Messaging 1. Versuch
This commit is contained in:
1 parent
f1fb926c2f
commit
4c8b11c4d5
25 files changed
+2111
-31
No files matched your search
@@ -17,15 +17,17 @@ from cmbnet.ws.protocol import WSMessage
|
||||
|
||||
|
||||
def _parse_auth_payload(value):
|
||||
"""Liefert (Token, Client-ID) aus dem Code-0-Payload.
|
||||
"""Liefert (Token, Client-ID, Client-Typ) aus dem Code-0-Payload.
|
||||
|
||||
Ältere Clients senden statt ``client_id`` noch ``session_id``. Der
|
||||
alte Schlüssel wird übergangsweise weiter akzeptiert.
|
||||
alte Schlüssel wird übergangsweise weiter akzeptiert. ``client_type``
|
||||
ist optional; ohne Angabe bleibt FCM für die Webview deaktiviert.
|
||||
"""
|
||||
if isinstance(value, dict):
|
||||
return (
|
||||
value.get('token'),
|
||||
value.get('client_id') or value.get('session_id')
|
||||
value.get('client_id') or value.get('session_id'),
|
||||
value.get('client_type')
|
||||
)
|
||||
|
||||
if isinstance(value, str):
|
||||
@@ -34,15 +36,16 @@ def _parse_auth_payload(value):
|
||||
try:
|
||||
data = json.loads(text)
|
||||
except (TypeError, ValueError):
|
||||
return None, None
|
||||
return None, None, None
|
||||
if isinstance(data, dict):
|
||||
return (
|
||||
data.get('token'),
|
||||
data.get('client_id') or data.get('session_id')
|
||||
data.get('client_id') or data.get('session_id'),
|
||||
data.get('client_type')
|
||||
)
|
||||
return text, None
|
||||
return text, None, None
|
||||
|
||||
return None, None
|
||||
return None, None, None
|
||||
|
||||
|
||||
@sock.route('/<tenant>/ws')
|
||||
@@ -97,14 +100,19 @@ def ws(ws, tenant):
|
||||
ws.close()
|
||||
break
|
||||
|
||||
token, requested_client_id = _parse_auth_payload(msg.msg)
|
||||
token, requested_client_id, client_type = _parse_auth_payload(
|
||||
msg.msg
|
||||
)
|
||||
if not requested_client_id:
|
||||
requested_client_id = getattr(msg, 'client_id', None)
|
||||
if client_type is None:
|
||||
client_type = getattr(msg, 'client_type', None)
|
||||
client_id = broker.normalize_client_id(requested_client_id, account_id)
|
||||
msg.client_id = client_id
|
||||
|
||||
if not token or not broker.register_connection(
|
||||
tenant_id, account_id, client_id, ws
|
||||
tenant_id, account_id, client_id, ws,
|
||||
client_type=client_type
|
||||
):
|
||||
broker.log_incoming(
|
||||
tenant_id, msg, recipients=[],
|
||||
|
||||
Reference in new issue
Block a user