royneary / mod_push

Other
68 stars 19 forks source link

client info is registered but notification won't send #8

Open BesatZardosht opened 8 years ago

BesatZardosht commented 8 years ago

Thank you very much for this amazing work!

this module seems very promising however, I couldn't make it work. These are the steps I've done:

  1. downloaded and installed latest version of Erlang from http://www.erlang.org/downloads The latest version contains the fix mentioned in https://github.com/processone/otp/commit/45aaefe739c8ea6c33d140d056b94fcf53c3df30 and https://blog.process-one.net/apple-increasing-security-of-push-service-ahead-of-wwdc/
  2. downloaded and installed ejabberd-mod_push_adjustment from: https://github.com/royneary/ejabberd/tree/mod_push_adjustments
  3. changed ejabberd.yml file:
listen: 
  - 
    port: 5222
    module: ejabberd_c2s
    resume_timeout: 300
    stream_management: true

  mod_push:
    include_senders: true
    include_message_count: true
    include_subscription_count: true
    include_message_bodies: true
    access_backends: local_users
    backends:
      -
        type: apns
        app_name: "supDawg"
        register_host: "myserver.com"
        pubsub_host: "push.myserver.com"
        certfile: "/Applications/ejabberd-push/etc/ejabberd/myCertPrivateKeyNoPass.pem"
  mod_pubsub: 
    host: "push.myserver.com"
    nodetree: "virtual"
    access_createnode: pubsub_createnode
    ## reduces resource comsumption, but XEP in compliant
    ignore_pep_from_offline: true
    ## XEP compliant, but increases resource comsumption
    ## ignore_pep_from_offline: false
    last_item_cache: false
    plugins: 
      - "flat"
      - "hometree"
      - "pep" # pep requires mod_caps
      - "push"
  1. I register clients using this iq:

<iq type="set" to="myserver.com"><command xmlns="http://jabber.org/protocol/commands" node="register-push-apns" action="execute"><x xmlns="jabber:x:data" type="submit"><field var="token"><value>mytoken</value></field><field var="device-name"><value></value></field></x></command></iq>

  1. I get this iq:

<iq xmlns="jabber:client" from="myserver.com" to="testuser6@myserver.com/12123" type="result"><command xmlns="http://jabber.org/protocol/commands" sessionid="2016-02-16T16:09:46.115808Z" node="register-push-apns" status="completed"><x xmlns="jabber:x:data" type="result"><field var="jid"><value>push.myserver.com </value></field><field var="node"><value>123456</value></field><field var="secret"><value>789012</value></field></x></command></iq>

BUT still when I kill my app, I don't get any push notification. I am using development cert file. Does it work with gateway.sandbox.push.apple.com? Am I doing anything wrong?

robobit commented 8 years ago

Are you sure you are breaking the connection and not gracefully ending it with a presence update and a stream close? Some client libraries, such as Strophe, will do this for you automatically when you stop your app.

BesatZardosht commented 8 years ago

I don't send presence update. I simply double-click on the Home button to access the multitasking tray and then swipe up on the app to close it. Is there any way to check the stream state?

robobit commented 8 years ago

You will see it in the ejabberd log.

Also you will have to send an $iq stanza to enable the notifications, besides the registration (I don't see this in your steps.

BesatZardosht commented 8 years ago

Oh.. maybe that is the problem! THANK YOU! How should this iq be? I really appreciate if you can give me an example since I can't see any example in mod_push read me

BesatZardosht commented 8 years ago

this is my ejabberd log after I kill my app. There are two errors in my log

2016-02-16 17:33:12.043 [info] <0.690.0>@ejabberd_c2s:terminate:1785 ({socket_state,gen_tcp,#Port<0.14022>,<0.689.0>}) Close session for testuser6@myserver.com/123456

2016-02-16 17:33:12.046 [error] <0.650.0>@ejabberd_hooks:run_fold1:368 {undef,[{mod_push,on_affiliation_removal,[{xmlel,<"presence">>,[{<<"from">>,<<"testuser6@myserver.com/123456">},{<"to">>,<<"testuser10@myserver.com/78901">},{<<"type">>,<<"unavailable">>}],[]},{state,{socket_state,gen_tcp,#Port<0.13995>,<0.649.0>},ejabberd_socket,#Ref<0.0.3.2901>,false,<<"14099723632861619090">>,undefined,c2s,c2s_shaper,false,true,false,false,[verify_none,compression_none,{protocol_options,<<"no_sslv3">>},{certfile,<<"/Applications/ejabberd-push/etc/ejabberd/server.pem">>}],true,{jid,<<"testuser10">>,<<"myserver.com">>,<<"78901">>,<<"testuser10">>,<<"myserver.com">>,<<"78901">>},<<"testuser10">>,<<"myserver.com">>,<<"78901">>,{{1455,642890,775487},<0.650.0>},{2,{{<<"testuser6">>,<<"myserver.com">>,<<>>},{{<<"testuser10">>,<<"myserver.com">>,<<>>},nil,nil},nil}},{2,{{<<"testuser6">>,<<"myserver.com">>,<<>>},{{<<"testuser10">>,<<"myserver.com">>,<<>>},nil,nil},nil}},{3,{{<<"testuser10">>,<<"myserver.com">>,<<>>},{{<<"mytestroom">>,<<"conference.myserver.com">>,<<"testuser10">>},nil,nil},{{<<"testuser6">>,<<"myserver.com">>,<<>>},nil,nil}}},{xmlel,<<"presence">>,[{<<"type">>,<<"online">>}],[{xmlel,<<"x">>,[{<<"xmlns">>,<<"vcard-temp:x:update">>}],[{xmlel,<<"photo">>,[],[]}]}]},{1455,642892,922642},{userlist,none,[],false},c2s,ejabberd_auth_ldap,{{10,0,1,111},62145},[{caps_resources,{0,nil}}],active,[],inactive,undefined,undefined,1000,undefined,300,300,false,0,0,<<>>},{jid,<<"testuser10">>,<<"myserver.com">>,<<"78901">>,<<"testuser10">>,<<"myserver.com">>,<<"78901">>},{jid,<<"testuser6">>,<<"myserver.com">>,<<"820496...">>,...},...],...},...]} running hook: {user_receive_packet,[{state,{socket_state,gen_tcp,#Port<0.13995>,<0.649.0>},ejabberd_socket,#Ref<0.0.3.2901>,false,<<"14099723632861619090">>,undefined,c2s,c2s_shaper,false,true,false,false,[verify_none,compression_none,{protocol_options,<<"no_sslv3">>},{certfile,<<"/Applications/ejabberd-push/etc/ejabberd/server.pem">>}],true,{jid,<<"testuser10">>,<<"myserver.com">>,<<"78901">>,<<"testuser10">>,<<"myserver.com">>,<<"78901">>},<<"testuser10">>,<<"myserver.com">>,<<"78901">>,{{1455,642890,775487},<0.650.0>},{2,{{<<"testuser6">>,<<"myserver.com">>,<<>>},{{<<"testuser10">>,<<"myserver.com">>,<<>>},nil,nil},nil}},{2,{{<<"testuser6">>,<<"myserver.com">>,<<>>},{{<<"testuser10">>,<<"myserver.com">>,<<>>},nil,nil},nil}},{3,{{<<"testuser10">>,<<"myserver.com">>,<<>>},{{<<"mytestroom">>,<<"conference.myserver.com">>,<<"testuser10">>},nil,nil},{{<<"testuser6">>,<<"myserver.com">>,<<>>},nil,nil}}},{xmlel,<<"presence">>,[{<<"type">>,<<"online">>}],[{xmlel,<<"x">>,[{<<"xmlns">>,<<"vcard-temp:x:update">>}],[{xmlel,<<"photo">>,[],[]}]}]},{1455,642892,922642},{userlist,none,[],false},c2s,ejabberd_auth_ldap,{{10,0,1,111},62145},[{caps_resources,{0,nil}}],active,[],inactive,undefined,undefined,1000,undefined,300,300,false,0,0,<<>>},{jid,<<"testuser10">>,<<"myserver.com">>,<<"78901">>,<<"testuser10">>,<<"myserver.com">>,<<"78901">>},{jid,<<"testuser6">>,<<"myserver.com">>,<<"123456">>,<<"testuser6">>,<<"myserver.com">>,<<"123456">>},{jid,<<"testuser10">>,<<"myserver.com">>,<<"78901">>,...}]}

2016-02-16 17:33:12.048 [error] <0.650.0>@ejabberd_hooks:run_fold1:368 {undef,[{mod_push,on_affiliation_removal,[{xmlel,<"presence">>,[{<<"from">>,<<"mytestroom@conference.myserver.com/testuser6">},{<"to">>,<<"testuser10@myserver.com/78901">},{<"type">>,<<"unavailable">>}],[{xmlel,<<"x">>,[{<<"xmlns">>,<<"http://jabber.org/protocol/muc#user">>}],[{xmlel,<<"item">>,[{<<"jid">>,<<"testuser6@myserver.com/123456">},{<<"affiliation">>,<<"owner">>},{<<"role">>,<<"none">>}],[]}]}]},{state,{socket_state,gen_tcp,#Port<0.13995>,<0.649.0>},ejabberd_socket,#Ref<0.0.3.2901>,false,<<"14099723632861619090">>,undefined,c2s,c2s_shaper,false,true,false,false,[verify_none,compression_none,{protocol_options,<<"no_sslv3">>},{certfile,<<"/Applications/ejabberd-push/etc/ejabberd/server.pem">>}],true,{jid,<<"testuser10">>,<<"myserver.com">>,<<"78901">>,<<"testuser10">>,<<"myserver.com">>,<<"78901">>},<<"testuser10">>,<<"myserver.com">>,<<"78901">>,{{1455,642890,775487},<0.650.0>},{2,{{<<"testuser6">>,<<"myserver.com">>,<<>>},{{<<"testuser10">>,<<"myserver.com">>,<<>>},nil,nil},nil}},{2,{{<<"testuser6">>,<<"myserver.com">>,<<>>},{{<<"testuser10">>,<<"myserver.com">>,<<>>},nil,nil},nil}},{3,{{<<"testuser10">>,<<"myserver.com">>,<<>>},{{<<"mytestroom">>,<<"conference.myserver.com">>,<<"testuser10">>},nil,nil},{{<<"testuser6">>,<<"myserver.com">>,<<>>},nil,nil}}},{xmlel,<<"presence">>,[{<<"type">>,<<"online">>}],[{xmlel,<<"x">>,[{<<"xmlns">>,<<"vcard-temp:x:update">>}],[{xmlel,<<"photo">>,[],[]}]}]},{1455,642892,922642},{userlist,none,[],false},c2s,ejabberd_auth_ldap,{{10,0,1,111},62145},[{caps_resources,{0,nil}}],active,[],inactive,undefined,undefined,1000,undefined,300,300,false,0,0,<<>>},{jid,<<"testuser10">>,<<"myserver.com">>,<<"11497...">>,...},...],...},...]} running hook: {user_receive_packet,[{state,{socket_state,gen_tcp,#Port<0.13995>,<0.649.0>},ejabberd_socket,#Ref<0.0.3.2901>,false,<<"14099723632861619090">>,undefined,c2s,c2s_shaper,false,true,false,false,[verify_none,compression_none,{protocol_options,<<"no_sslv3">>},{certfile,<<"/Applications/ejabberd-push/etc/ejabberd/server.pem">>}],true,{jid,<<"testuser10">>,<<"myserver.com">>,<<"78901">>,<<"testuser10">>,<<"myserver.com">>,<<"78901">>},<<"testuser10">>,<<"myserver.com">>,<<"78901">>,{{1455,642890,775487},<0.650.0>},{2,{{<<"testuser6">>,<<"myserver.com">>,<<>>},{{<<"testuser10">>,<<"myserver.com">>,<<>>},nil,nil},nil}},{2,{{<<"testuser6">>,<<"myserver.com">>,<<>>},{{<<"testuser10">>,<<"myserver.com">>,<<>>},nil,nil},nil}},{3,{{<<"testuser10">>,<<"myserver.com">>,<<>>},{{<<"mytestroom">>,<<"conference.myserver.com">>,<<"testuser10">>},nil,nil},{{<<"testuser6">>,<<"myserver.com">>,<<>>},nil,nil}}},{xmlel,<<"presence">>,[{<<"type">>,<<"online">>}],[{xmlel,<<"x">>,[{<<"xmlns">>,<<"vcard-temp:x:update">>}],[{xmlel,<<"photo">>,[],[]}]}]},{1455,642892,922642},{userlist,none,[],false},c2s,ejabberd_auth_ldap,{{10,0,1,111},62145},[{caps_resources,{0,nil}}],active,[],inactive,undefined,undefined,1000,undefined,300,300,false,0,0,<<>>},{jid,<<"testuser10">>,<<"myserver.com">>,<<"78901">>,<<"testuser10">>,<<"myserver.com">>,<<"78901">>},{jid,<<"mytestroom">>,<<"conference.myserver.com">>,<<"testuser6">>,<<"mytestroom">>,<<"conference.myserver.com">>,<<"testuser6">>},{jid,<<"testuser10">>,<<"myserver.com">>,<<"78901">>,<<"testuser10">>,<<"myserver.com">>,<<"114979279057583647981...">>}]}

royneary commented 8 years ago

I merged a fix yesterday, did you pull that?

The enable stanza should look similar to this:

<iq type='set' id='x43'>
  <enable xmlns='urn:xmpp:push:0' jid='push.myserver.com' node='yxs32uqsflafdk3iuqo'>
    <x xmlns='jabber:x:data'>
      <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>

There are examples in XEP-0357.

royneary commented 8 years ago

And yes, it should work with the sandbox server, actually it only works with the sandbox server currently ;-)

@robobit, I saw you implemented a sandbox config option. I should adopt that. Just too busy at the moment.

robobit commented 8 years ago

Something like this:

<iq type='set' id='x43'>
  <enable xmlns='urn:xmpp:push:0' jid='push-5.client.example' node='yxs32uqsflafdk3iuqo'>
    <x xmlns='jabber:x:data'>
      <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>

See XEP-0357: Push Notification specification.

In your log you should see something like below when a client disconnects (this is at log level 5). (The first part would look different if your not using websockets like I am). Especially look out for the ejabberd_c2s:fm_next_state and the mod_push log entries.

2016-02-16 18:47:39.291 [debug] <0.1211.0>@ejabberd_websocket:process_frame:338 WebSocket close op unknown: <<>>
2016-02-16 18:47:50.006 [debug] <0.1212.0>@ejabberd_http_ws:terminate:263 C2S Pid : <0.1213.0>
2016-02-16 18:47:50.006 [debug] <0.1211.0>@ejabberd_http:send_text:183 Error in p1_tls:send: {error,einval}
2016-02-16 18:47:50.007 [info] <0.1214.0>@ejabberd_c2s:fsm_next_state:2505 Waiting for resumption of stream for wdj@mysecretserver.com/wbm
2016-02-16 18:47:50.007 [debug] <0.1214.0>@mod_push:dispatch:690 +++++ dispatch: found push_user
2016-02-16 18:47:50.007 [debug] <0.1214.0>@mod_push:dispatch:697 +++++ NewSubscrs = [{subscription,<<"wbm">>,true,<<"4218060266">>,{local_reg,<<"push.mysecretserver.com">>,<<"3628156109">>}}]
2016-02-16 18:47:50.007 [debug] <0.1214.0>@mod_push:dispatch:704 +++++ dispatch: found subscription
2016-02-16 18:47:50.007 [debug] <0.1214.0>@mod_push:on_wait_for_resume:1022 +++++++ adjusting timeout to 8640000

Also I forgot to mention that you will need to enable and handle stream managment XEP-0198: Stream Management.

BesatZardosht commented 8 years ago

I appreciate all your helps and responses!!

the push service is enables. I get this feature in disco#info: <feature var="urn:xmpp:push:0"/>

Steam_management default value is true but I have set it in ejabberd.yml just in case: stream_management: true

I pulled mod_push from here.

set the log level to 5. but I can't see mod_push log info.

And it is still not working!

robobit commented 8 years ago

From the feature info you can't conclude that the push service is enabled. It just means that your ejabberd supports the push feature. You still have to register for it and enable it (that 2 stanzas as described earlier). Same for the stream management, look for the ejabberd_c2s:fsm_next_state:2505 Waiting for resumption of stream in your log when you quit your app (this can take a while because there is a (configurable) timeout). If you don't see this then you don't have the prerequisites setup for mod_push.

I hope this helps.