Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Commit 7c073de

Browse files
authored
Merge pull request #12 from proger/multibackend
Multibackend
2 parents 3898e23 + 957b3a5 commit 7c073de

9 files changed

+1014
-93
lines changed

README.md

+34-4
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,24 @@ modules:
6767
type: apns
6868
# make sure this pem file contains only one(!) certificate + key pair
6969
certfile: "/etc/ssl/private/apns_example_app.pem"
70-
# sandbox is for testing
7170
gateway: "gateway.push.apple.com"
72-
#gateway: "gateway.sandbox.push.apple.com"
71+
-
72+
type: apns
73+
# you can add more backends of each type by specifying backend_ref with unique names
74+
backend_ref: "sandbox"
75+
# make sure this pem file contains only one(!) certificate + key pair
76+
certfile: "/etc/ssl/private/apns_example_app_sandbox.pem"
77+
gateway: "gateway.sandbox.push.apple.com"
7378
-
7479
type: fcm
7580
gateway: "https://fcm.googleapis.com/fcm/send"
7681
api_key: "API_KEY"
82+
-
83+
type: fcm
84+
# you can add more backends of each type by specifying backend_ref with unique names
85+
backend_ref: "fcm2"
86+
gateway: "https://fcm.googleapis.com/fcm/send"
87+
api_key: "API_KEY_2"
7788
```
7889
7990
## Client Applications
@@ -94,15 +105,34 @@ Example (note, `to='localhost'` contain the your user's server name):
94105
node='register-push-apns'
95106
action='execute'>
96107
<x xmlns='jabber:x:data' type='submit'>
97-
<field
98-
var='token'>
108+
<field var='token'>
99109
<value>urq6urq6urq6urq6urq6urq6urq6urq6urq6urq6uro=</value>
100110
</field>
101111
</x>
102112
</command>
103113
</iq>
104114
```
105115

116+
You need to specify a `backend_ref` field to route your subscription to a particular backend:
117+
118+
```xml
119+
<iq type='set' to='localhost' id='randomrandomrequestid2'>
120+
<command xmlns='http://jabber.org/protocol/commands'
121+
node='register-push-apns'
122+
action='execute'>
123+
<x xmlns='jabber:x:data' type='submit'>
124+
<field var='backend_ref'>
125+
<value>sandbox</value>
126+
</field>
127+
<field var='token'>
128+
<value>urq6urq6urq6urq6urq6urq6urq6urq6urq6urq6uro=</value>
129+
</field>
130+
</x>
131+
</command>
132+
</iq>
133+
```
134+
135+
106136
See [client.py](client.py) for a reference client.
107137

108138
You can use `babababababababababababababababababababababababababababababababa` (`urq6urq6urq6urq6urq6urq6urq6urq6urq6urq6uro=` in base64) token to test APNS.

client.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ def text(self, to, msg):
3535
self.send_message(mto=to, mbody=msg)
3636
self.disconnect(wait=True)
3737

38-
def register_push_apns(self, token):
38+
def register_push_apns(self, token, ref=None):
39+
if ref:
40+
ref_payload = "<field var='backend_ref'><value>%s</value></field>" % ref
41+
else:
42+
ref_payload = ""
3943
self['xep_0050'].start_command(jid=self.__server,
4044
node='register-push-apns',
4145
session={
@@ -44,11 +48,16 @@ def register_push_apns(self, token):
4448
'id': 'execute',
4549
'payload': [ET.fromstring("""
4650
<x xmlns='jabber:x:data' type='submit'>
47-
<field var='token'> <value>%s</value> </field>
48-
</x>""" % hextobase64(token))]
51+
%s<field var='token'><value>%s</value></field>
52+
</x>""" % (ref_payload, hextobase64(token)))]
4953
})
5054

51-
def register_push_fcm(self, token):
55+
56+
def register_push_fcm(self, token, ref=None):
57+
if ref:
58+
ref_payload = "<field var='backend_ref'><value>%s</value></field>" % ref
59+
else:
60+
ref_payload = ""
5261
self['xep_0050'].start_command(jid=self.__server,
5362
node='register-push-fcm',
5463
session={
@@ -57,8 +66,8 @@ def register_push_fcm(self, token):
5766
'id': 'execute',
5867
'payload': [ET.fromstring("""
5968
<x xmlns='jabber:x:data' type='submit'>
60-
<field var='token'> <value>%s</value> </field>
61-
</x>""" % token)]
69+
%s<field var='token'><value>%s</value></field>
70+
</x>""" % (ref_payload, token))]
6271
})
6372

6473
def list_push_registrations(self):
@@ -91,8 +100,8 @@ def _command_error(self, iq, session):
91100

92101
def usage():
93102
print >>sys.stderr, 'usage: client.py jid password text jid msg'
94-
print >>sys.stderr, 'usage: client.py jid password register-push-apns token'
95-
print >>sys.stderr, 'usage: client.py jid password register-push-fcm token'
103+
print >>sys.stderr, 'usage: client.py jid password register-push-apns token [backend_ref]'
104+
print >>sys.stderr, 'usage: client.py jid password register-push-fcm token [backend_ref]'
96105
print >>sys.stderr, 'usage: client.py jid password list-push-registrations'
97106
print >>sys.stderr, 'usage: client.py jid password unregister-push'
98107
sys.exit(1)

0 commit comments

Comments
 (0)