Closed pvthuyet closed 6 years ago
What app do you run on ios?
This Appserver is for app developers and runs on a server of the app developer.
If you run your own XMPP server, configuring XEP-0357 should be enough. Prosody has a module called mod_cloud_notify which does everything needed to make push work with your own xmpp server (as long as the app you want to use supports XEP-0357 push).
ios apps supporting push are: ChatSecure and Monal (only the upcoming version 3.0).
What app do you run on ios?
We are developing an application on iOS and android. That's the reason why we need to build Appserver. We will use Appserver with mod_cloud_notify, don't we? How can I configure mod_cloud_notify registers Appserver ?
Okay, so you are an app developer. The steps are as follows:
push node
push secret
. The http api endpoints and return values provided by mod_push_appserver are descried here: https://github.com/tmolitor-stud-tu/mod_push_appserver#http-api-endpointspush node
and push secret
with the xmpp server the app uses (this doesn't have to be the same xmpp server your appserver is running on). This server has to provide XEP-0357 push support via prosody's mod_cloud_notify or the corresponding push module for ejabberd.For an example how to add this to an app see the pull request here: https://github.com/anurodhp/Monal/pull/75 (especially my commit here: https://github.com/anurodhp/Monal/pull/75/commits/eb75f5c814055b982f17900977aec6e1376a0033 the output prefixed by several "****
" will guide you here)
The steps for Android are the same, you just have to get the push token from Google using their sdk instead of apple's. Then you have to register your push node and push token to the appserver and register the returned push secret and push node to your xmpp server exactly as outlined in my last post.
Hi @tmolitor-stud-tu ,
I used HTTPS api endpoint to test my server:
Register:
https://hfhdemo.xyz:5281/push_appserver/v1/register
type: apns
node: A14CD712-C862-4651-8F3F-24F281DBC6E4
token: 46364132e96ce2f6c6147d2017dc8181962d086a66fd1681d2c238eea9e44a17
=> Result:
OK
A14CD712-C862-4651-8F3F-24F281DBC6E4
691d8009061936b0b0d31b99fd4053809f3efc2cf81327833c575360ed2595ac
send push notification to device
https://hfhdemo.xyz:5281/push_appserver/v1/push
node: A14CD712-C862-4651-8F3F-24F281DBC6E4
secret: 691d8009061936b0b0d31b99fd4053809f3efc2cf81327833c575360ed2595ac
=> Result:
ERROR
Internal server error!
Below log file:
Jan 02 22:55:55 general info Hello and welcome to Prosody version 0.9.10
Jan 02 22:55:55 general info Prosody is using the select backend for connection handling
Jan 02 22:55:55 hostmanager debug Activated host: echo.hfhdemo.xyz
Jan 02 22:55:56 portmanager debug No active service for s2s, activating...
Jan 02 22:55:56 socket debug server.lua: new server listener on '[::]:5269'
Jan 02 22:55:56 portmanager debug Added listening service s2s to [::]:5269
Jan 02 22:55:56 socket debug server.lua: new server listener on '[*]:5269'
Jan 02 22:55:56 portmanager debug Added listening service s2s to [*]:5269
Jan 02 22:55:56 portmanager info Activated service 's2s' on [::]:5269, [*]:5269
Jan 02 22:55:56 hostmanager debug Activated host: hfhdemo.xyz
Jan 02 22:55:56 hfhdemo.xyz:storage_sql debug Successfully connected to database
Jan 02 22:55:56 auth_internal_hashed debug initializing internal_hashed authentication provider for host 'hfhdemo.xyz'
Jan 02 22:55:56 usermanager debug host 'hfhdemo.xyz' now set to use user provider 'internal_hashed'
Jan 02 22:55:56 portmanager debug No active service for http, activating...
Jan 02 22:55:56 socket debug server.lua: new server listener on '[::]:5280'
Jan 02 22:55:56 portmanager debug Added listening service http to [::]:5280
Jan 02 22:55:56 socket debug server.lua: new server listener on '[*]:5280'
Jan 02 22:55:56 portmanager debug Added listening service http to [*]:5280
Jan 02 22:55:56 portmanager info Activated service 'http' on [::]:5280, [*]:5280
Jan 02 22:55:56 portmanager debug No active service for https, activating...
Jan 02 22:55:56 socket debug server.lua: new ssl server listener on '[::]:5281'
Jan 02 22:55:56 portmanager debug Added listening service https to [::]:5281
Jan 02 22:55:56 socket debug server.lua: new ssl server listener on '[*]:5281'
Jan 02 22:55:56 portmanager debug Added listening service https to [*]:5281
Jan 02 22:55:56 portmanager info Activated service 'https' on [::]:5281, [*]:5281
Jan 02 22:55:56 hfhdemo.xyz:http debug Serving 'push_appserver' at https://hfhdemo.xyz:5281/push_appserver
Jan 02 22:55:56 hfhdemo.xyz:push_appserver warn Debugging is activated, you should turn this off on production servers for security reasons!!!
Jan 02 22:55:56 hfhdemo.xyz:push_appserver warn Setting: 'push_appserver_debugging'.
Jan 02 22:55:56 hfhdemo.xyz:push_appserver info Appserver started at URL: <https://hfhdemo.xyz:5281/push_appserver/>
Jan 02 22:55:56 hfhdemo.xyz:push_appserver_apns info Appserver APNS submodule loaded
Jan 02 22:55:56 hfhdemo.xyz:push_appserver_apns info Connecting to APNS feedback service
Jan 02 22:55:56 hfhdemo.xyz:push_appserver_apns debug connecting to feedback.sandbox.push.apple.com port 2196
Jan 02 22:55:57 hfhdemo.xyz:push_appserver_apns debug connection established successfully
Jan 02 22:55:57 hfhdemo.xyz:push_appserver_apns error Could not receive data from APNS feedback socket (receive 1): closed
Jan 02 22:55:57 portmanager debug No active service for console, activating...
Jan 02 22:55:57 socket debug server.lua: new server listener on '[127.0.0.1]:5582'
Jan 02 22:55:57 portmanager debug Added listening service console to [127.0.0.1]:5582
Jan 02 22:55:57 socket debug server.lua: new server listener on '[::1]:5582'
Jan 02 22:55:57 portmanager debug Added listening service console to [::1]:5582
Jan 02 22:55:57 portmanager info Activated service 'console' on [127.0.0.1]:5582, [::1]:5582
Jan 02 22:55:57 portmanager debug No active service for c2s, activating...
Jan 02 22:55:57 socket debug server.lua: new server listener on '[::]:5222'
Jan 02 22:55:57 portmanager debug Added listening service c2s to [::]:5222
Jan 02 22:55:57 socket debug server.lua: new server listener on '[*]:5222'
Jan 02 22:55:57 portmanager debug Added listening service c2s to [*]:5222
Jan 02 22:55:57 portmanager info Activated service 'c2s' on [::]:5222, [*]:5222
Jan 02 22:55:57 portmanager debug No active service for legacy_ssl, activating...
Jan 02 22:55:57 portmanager info Activated service 'legacy_ssl' on no ports
Jan 02 22:55:57 modulemanager debug push_appserver is already loaded for hfhdemo.xyz, so not loading again
Jan 02 22:55:57 hfhdemo.xyz:cloud_notify info Module loaded
Jan 02 22:55:57 hfhdemo.xyz:http debug Serving 'bosh' at https://hfhdemo.xyz:5281/http-bind
Jan 02 22:55:57 modulemanager debug disco is already loaded for hfhdemo.xyz, so not loading again
Jan 02 22:55:57 mod_posix info Prosody is about to detach from the console, disabling further console output
Jan 02 22:55:57 mod_posix info Successfully daemonized to PID 13630
Jan 02 22:55:57 hostmanager debug Activated host: apple.hfhdemo.xyz
Jan 02 22:55:57 hostmanager debug Activated host: conference.hfhdemo.xyz
Jan 02 22:58:07 socket debug server.lua: auto-starting ssl negotiation...
Jan 02 22:58:07 socket debug server.lua: attempting to start tls on tcp{client}: 0x14ca568
Jan 02 22:58:07 socket debug server.lua: accepted new client connection from 115.73.5.189:41986 to 5281
Jan 02 22:58:07 socket debug server.lua: ssl handshake done
Jan 02 22:58:07 http.server debug Firing event: GET hfhdemo.xyz/push_appserver/v1/register
Jan 02 22:58:35 http.server debug Firing event: POST hfhdemo.xyz/push_appserver/v1/register
Jan 02 22:58:35 hfhdemo.xyz:push_appserver info Registered push device, returning: 'OK', 'A14CD712-C862-4651-8F3F-24F281DBC6E4', '691d8009061936b0b0d31b99fd4053809f3efc2cf81327833c575360ed2595ac'
Jan 02 22:58:35 hfhdemo.xyz:push_appserver debug settings: {
type = "apns",
token = "46364132e96ce2f6c6147d2017dc8181962d086a66fd1681d2c238eea9e44a17",
registered = "2018-01-03T03:58:35Z",
node = "A14CD712-C862-4651-8F3F-24F281DBC6E4",
secret = "691d8009061936b0b0d31b99fd4053809f3efc2cf81327833c575360ed2595ac"
}
Jan 02 22:59:08 http.server debug Firing event: GET hfhdemo.xyz/push_appserver/v1/push
Jan 02 22:59:28 http.server debug Firing event: POST hfhdemo.xyz/push_appserver/v1/push
Jan 02 22:59:28 hfhdemo.xyz:push_appserver info Firing event 'incoming-push-to-apns' (node = 'A14CD712-C862-4651-8F3F-24F281DBC6E4', secret = '691d8009061936b0b0d31b99fd4053809f3efc2cf81327833c575360ed2595ac')
Jan 02 22:59:28 hfhdemo.xyz:push_appserver_apns debug Frame ID: f5e89e48
Jan 02 22:59:28 hfhdemo.xyz:push_appserver_apns debug Frame length: 80 (00000050)
Jan 02 22:59:28 hfhdemo.xyz:push_appserver_apns debug Frame data: 01002046364132E96CE2F6C6147D2017DC8181962D086A66FD1681D2C238EEA9E44A1702001F7B22617073223A7B22636F6E74656E742D617661696C61626C65223A317D7D030004F5E89E4805000105
Jan 02 22:59:28 hfhdemo.xyz:push_appserver_apns debug Frame: 020000005001002046364132E96CE2F6C6147D2017DC8181962D086A66FD1681D2C238EEA9E44A1702001F7B22617073223A7B22636F6E74656E742D617661696C61626C65223A317D7D030004F5E89E4805000105
Jan 02 22:59:28 hfhdemo.xyz:push_appserver_apns debug connecting to gateway.sandbox.push.apple.com port 2195
Jan 02 22:59:29 hfhdemo.xyz:push_appserver_apns debug connection established successfully
Jan 02 22:59:29 hfhdemo.xyz:push_appserver_apns error Could not receive data from APNS socket: wantread
Jan 02 22:59:29 hfhdemo.xyz:push_appserver error Push handler for type 'apns' not executed successfully: Error communicating with APNS (receive)
Jan 02 22:59:29 hfhdemo.xyz:push_appserver debug settings: {
type = "apns",
token = "46364132e96ce2f6c6147d2017dc8181962d086a66fd1681d2c238eea9e44a17",
registered = "2018-01-03T03:58:35Z",
last_push_error = "2018-01-03T03:59:29Z",
node = "A14CD712-C862-4651-8F3F-24F281DBC6E4",
secret = "691d8009061936b0b0d31b99fd4053809f3efc2cf81327833c575360ed2595ac"
}
Jan 02 23:01:24 socket debug server.lua: client 115.73.5.189:41986 read error: closed
Jan 02 23:01:24 socket debug server.lua: closed client handler and removed socket from list
I changed: push_appserver_apns_push_priority = "high";
The message reached to device.
But why did the error still appear?
error Push handler for type 'apns' not executed successfully: Error communicating with APNS (receive)
How can I register app server https://hfhdemo.xyz:5281/push_appserver/ work with mod_cloud_notify ? How stanza format to use register/unregister/push as HTTP API end point ? I looked at XEP-0357, for example : Enabling Notifications, with provided publish options
<iq type='set' id='x43'>
<enable xmlns='urn:xmpp:push:0' jid='push-5.client.example' node='yxs32uqsflafdk3iuqo'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE'><value>http://jabber.org/protocol/pubsub#publish-options</value></field>
<field var='secret'><value>eruio234vzxc2kla-91</value></field>
</x>
</enable>
</iq>
How do I modify this stanza to use register function of push_appserver ?
How can I register app server https://hfhdemo.xyz:5281/push_appserver/ with mod_cloud_notify ?
See XEP-0357. This XEP is describing exactly this.
I try to Enabling Notifications follow to XEP-0357. But it is failed. Here my stanza:
<iq type='set' id='x43'>
<enable xmlns='urn:xmpp:push:0' jid='thuyet@hfhdemo.xyz' node='A14CD712-C862-4651-8F3F-24F281DBC6E4'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE'>
<value>http://jabber.org/protocol/pubsub#publish-options</value>
</field>
<field var='type'>
<value>apns</value>
</field>
<field var='node'>
<value>A14CD712-C862-4651-8F3F-24F281DBC6E4</value>
</field>
<field var='token'>
<value>46364132e96ce2f6c6147d2017dc8181962d086a66fd1681d2c238eea9e44a17</value>
</field>
<field var='endpoint'>
<value>https://hfhdemo.xyz:5281/push_appserver/v1/register</value>
</field>
</x>
</enable>
</iq>
I got error from log:
hfhdemo.xyz:cloud_notify error Error writing push notification storage for user 'thuyet': Error executing statement parameters: Data too long for column 'value' at row 1
I have still confused about value of attributes: enable.jid, enable.node. Please help me correct. I used pidgin console to send this stanza.
Please have a closer look at the Monal pull request I linked to earlier, especially the function named setPushEnableWithNodeandSecret
here: https://github.com/anurodhp/Monal/pull/75/files#diff-44237bc92547efc3560e5517172f52bcR32
You'll see that the form has only one entry named secret
, exactly as in the example taken from XEP-0357 you provided yourself (and this is something I outlined under section 4 in my earlier comment as well: https://github.com/tmolitor-stud-tu/mod_push_appserver/issues/5#issuecomment-354565808)
The next mistake you made: The stanza has to go to the bare jid of the host having mod_push_appserver loaded, not to any user jid as you tried (that user would not even exist if the server running mod_push_appserver solely served the appserver and nothing else on a specialized subdomain and I would recommend this specialized subdomain anyways)
Next thing: You don't need the form fields type
, node
, token
and endpoint
. The node is already provided as attribute of the <enable/>
element of the stanza.
The secret has to be delivered inside a form element named secret
, not token
(see again the example in XEP-0357)
Thus, your stanza has to look like this:
<iq type='set' id='some_random_id'>
<enable xmlns='urn:xmpp:push:0' jid='hfhdemo.xyz' node='A14CD712-C862-4651-8F3F-24F281DBC6E4'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE'><value>http://jabber.org/protocol/pubsub#publish-options</value></field>
<field var='secret'><value>691d8009061936b0b0d31b99fd4053809f3efc2cf81327833c575360ed2595ac</value></field>
</x>
</enable>
</iq>
Again: All of this is already documented in XEP-0357, my linked pull request and my "step-by-step" comment: https://github.com/tmolitor-stud-tu/mod_push_appserver/issues/5#issuecomment-354565808
Something really useful as well: https://xmpp.org/extensions/xep-0357.html#xmpp-architecture This ascii-art diagram shows exactly the difference between the app server and the user's xmpp server. Something that is very important and should not be mixed up!
See also the diagrams over here: https://xmpp.org/extensions/xep-0357.html#general-architecture to understand what push in general means.
Success! Thank you, tmolitor-stud-tu
Great! :)
I'm closing this now.
Hi @tmolitor-stud-tu , After installed and setup configure, I haven't known how to use this modules. Could you please make a tutorial a little bit? I am sorry because I am new with prosody. Now, I want to push a notification to iso device. So, how do I register? how do I push a notification? and how do I use HTTP API endpoints?
I use browser to test HTTP API endpoints, but it seams doesn't work.
I tested GET HTTP API:
I sent a stanza to prosody:
But the result is not as XEP-0357 expectation. Here response from my server:
Please help me finger out my issues?