mrdoctorwho / ejabberd_mod_gcm Goto Github PK
View Code? Open in Web Editor NEWGoogle Cloud Messaging API for Ejabberd (PUSH Messages)
License: MIT License
Google Cloud Messaging API for Ejabberd (PUSH Messages)
License: MIT License
This module was my first experience with Erlang. Since then I improved my Erlang knowledge a bit, so the module can be improved, too.
Dear
I tested the module and install the module, but I had to restart ejabberd for configuration and then I'm not receiver notifications de offline message.
regards
ejabberd_hooks:run_fold(roster_get_jid_info, ...
server error log:
@ejabberd_hooks:run1:332 {undef,[{xml,get_tag_attr_s,[<<"type">>,{xmlel,<<"message">>,[{<<"xml:lang">>,<<"en">>},{<<"to">>,<<"[email protected]">>},{<<"type">>,<<"chat">>},{<<"id">>,<<"125">>}],[{xmlel,<<"body">>,[],[{xmlcdata,<<"dasd">>}]},{xmlel,<<"thread">>,[],[{xmlcdata,<<"VHTVVQPDlDznyPhoWYrZDLGmDPHqmkZx">>}]}]}],[]},{mod_gcm,message,3,[{file,"src/mod_gcm.erl"},{line,87}]},{ejabberd_hooks,safe_apply,3,[{file,"src/ejabberd_hooks.erl"},{line,382}]},{ejabberd_hooks,run1,3,[{file,"src/ejabberd_hooks.erl"},{line,329}]},{ejabberd_sm,route,3,[{file,"src/ejabberd_sm.erl"},{line,114}]},{ejabberd_local,route,3,[{file,"src/ejabberd_local.erl"},{line,112}]},{ejabberd_router,route,3,[{file,"src/ejabberd_router.erl"},{line,77}]},{ejabberd_c2s,check_privacy_route,5,[{file,"src/ejabberd_c2s.erl"},{line,2113}]}]}
Am not able to register the gcm id to xmpp server.
Sent:
2016-04-22 10:39:39.840 [debug] <0.5349.0>@ejabberd_receiver:process_data:283 Received XML on stream = <<"APA91bGaAKqg9KT1o5JmNG3xuL8l0E37pPtcduRV4_0iTc2-kD0qzl4DoK4MqT2aqZlfa3ced4wxuq1tUhy2IPCD-G07nkX3hT9qVUljteZpmuLoYW5spwJMGZOR8cQGBuWvAxFd55Dn">>
Received:
2016-04-22 10:39:39.843 [error] <0.5350.0>@gen_iq_handler:process_iq:129 {undef,[{xml,get_subtag,[{xmlel,<<"register">>,[{<<"xmlns">>,<<"https://android.googleapis.com/gcm">>}],[{xmlel,<<"key">>,[],[{xmlcdata,<<"APA91bGaAKqg9KT1o5JmNG3xuL8l0E37pPtcduRV4_0iTc2-kD0qzl4DoK4MqT2aqZlfa3ced4wxuq1tUhy2IPCD-G07nkX3hT9qVUljteZpmuLoYW5spwJMGZOR8cQGBuWvAxFd55Dn">>}]}]},<<"key">>],[]},{mod_gcm,iq,3,[{file,"src/mod_gcm.erl"},{line,128}]},{gen_iq_handler,process_iq,6,[{file,"src/gen_iq_handler.erl"},{line,128}]},{ejabberd_local,route,3,[{file,"src/ejabberd_local.erl"},{line,112}]},{ejabberd_router,route,3,[{file,"src/ejabberd_router.erl"},{line,77}]},{ejabberd_c2s,check_privacy_route,5,[{file,"src/ejabberd_c2s.erl"},{line,2113}]},{ejabberd_c2s,session_established2,2,[{file,"src/ejabberd_c2s.erl"},{line,1271}]},{p1_fsm,handle_msg,10,[{file,"src/p1_fsm.erl"},{line,582}]}]}
Can you please help me out in the issue.
Use rebar to actually compile the module
Line #95:
Msg = xml:get_tag_cdata(xml:get_subtag(Packet, <<"body">>)),
Should be replaced by something what works.
Hi, It's a great plugin especially for mobile apps where chances of your service getting killed is very high. It's not useful for offline messages since GCM is based on XMPP and will itself be offline. GCM have even more problems with a very high ping time.
I wanted to see if it can be modified to signal a new message and get the xmpp reconnected. Sending offline messages through GCM have few issue since there is no roster, no jingle support and if used as signaling it will be great.
2017-05-08 09:50:13.938 [error] <0.484.0>@ejabberd_hooks:safe_apply:383 Hook offline_message_hook crashed when running mod_gcm:message/1:
** Reason = {error,undef,[{mod_gcm,message,[],[{bounce,{message,<<>>,normal,<<"en">>,{jid,<<"cr3397">>,<<"kripter.io">>,<<"mobile">>,<<"cr3397">>,<<"kripter.io">>,<<"mobile">>},{jid,<<"dz9199">>,<<"kripter.io">>,<<>>,<<"dz9199">>,<<"kripter.io">>,<<>>},[],[],undefined,[{xmlel,<<"paused">>,[{<<"xmlns">>,<<"http://jabber.org/protocol/chatstates">>}],[]}],#{ip => {0,0,0,0,0,65535,28806,20552}}}}]},{ejabberd_hooks,safe_apply,[{file,"src/ejabberd_hooks.erl"},{line,380}],4},{ejabberd_hooks,run_fold1,[{file,"src/ejabberd_hooks.erl"},{line,364}],4},{ejabberd_sm,route,[{file,"src/ejabberd_sm.erl"},{line,138}],1},{ejabberd_local,route,[{file,"src/ejabberd_local.erl"},{line,116}],1},{ejabberd_router,do_route,[{file,"src/ejabberd_router.erl"},{line,346}],1},{ejabberd_router,route,[{file,"src/ejabberd_router.erl"},{line,87}],1},{ejabberd_c2s,check_privacy_then_route,[{file,"src/ejabberd_c2s.erl"},{line,770}],2}]}
Hi Doctor,
I've setup ejabberd in Elixir/Phoenix application. Mix.exs has {:ejabberd, "~> 17.9"}. I've also copied mod_gcm.erl in src folder and put the following entry in ejabberd.yml.
mod_gcm:
gcm_api_key: "key"
While starting the phoenix app application stops with following error:
[warn] module 'mod_gcm' doesn't export mod_opt_type/1
[error] Problem starting the module mod_gcm for host localhost
options: [{gcm_api_key,<<"key">>}]
error: undef
[{mod_gcm,start,
[<<"localhost">>,
[{gcm_api_key,<<"key">>}]],
[]},
{gen_mod,start_module,4,[{file,"src/gen_mod.erl"},{line,200}]},
{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},
{gen_mod,start_link,0,[{file,"src/gen_mod.erl"},{line,79}]},
{supervisor,do_start_child,2,[{file,"supervisor.erl"},{line,365}]},
{supervisor,start_children,3,[{file,"supervisor.erl"},{line,348}]},
{supervisor,init_children,2,[{file,"supervisor.erl"},{line,314}]},
{gen_server,init_it,6,[{file,"gen_server.erl"},{line,328}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
[error] ejabberd initialization was aborted because a module start failed.
Hi @mrDoctorWho, how can i remove the subscription check from the module? Which part must be modified? Thanks in advance.
Hello Doctor, I'm trying to use your mod_gcm (and understand how it works) on Ejabberd 16.03, but i have a problem.
For start..i have added the mod_gcm.erl in the ejabberd/src dir and also the following in the ejabberd.yml file under the MODULES section
mod_gcm: gcm_api_key: gcm_api_key
where the last gcm_api_key is a global variable containing my API KEY (private, based on my Android App).
After the ejabberd reboot seems ok, the log return a row: mod_gcm:start:159 mod_gcm Has start successfully!.
So, as next step i've added to my Android XMPPManager Class the method to send the set iq stanza with the server and token (sender gcm registration id) info. This is what i've sent (Android Studio log):
<iq to='myserveraddr' id='dPqJJ-10' type='set'><register xmlns='https://android.googleapis.com/gcm'><key>f6Es9KFADRQ:APA92bGovzSlDsM3v0vmEaOTbQduDIj2pZbd8TRA_J7fLP_lH1CrhlG-sI62Iyi2L6sNXK0HZAIdFs5F7AUobIVCf4ZVfXxE0tDZek1TNwardz4aa1PbsE8gLzFEx5IQ1MQgdNAymQg-</key></register></iq>
The response seems ok (Android Studio log), no error:
<iq from='myserveraddr' to='1@myserveraddr/f6Es9KFADRQ' id='dPqJJ-10' type='result'/>
(f6Es9KFADRQ is the device name and is ok)
In the Ejabberd log now i can see a row that say that a new user has been registered (1@myserveraddr)... OK!
Done the above "registration" for both the user n.1 and n.2 (with success) i've tried to send a message from user n.1 to the offline user n.2, but on the Ejabberd log i've found the following error:
mod_gcm:message:89 FORMAT ERROR: "Offline message ~s [{jid,<<"1">>,<<"myserveraddr">>,<<"f6Es9KFADRQ">>,<<"1">>,<<"myserveraddr">>,<<"f6Es9KFADRQ">>}]
the offline message was not sent.. what can be the problem?
-- EDIT --
Changing the mod_gcm.erl INFO_MSG log parameter from [From] to [To]:
?INFO_MSG("Offline message ~s", [To]),
i noticed that return the same jid info of the sender (1, myserveraddr, f6Es9KFADRQ), it should be "2"?.. but i don't know how to set it
Hi Doctor,
I have tried using this module and followed your mentioned steps. I am using Android and my device is nexus 5 with 5.1 OS.
I have declared module in yml like following
mod_gcm:
gcm_api_key: "xxxxxxxxxxxxxxxxxxxxxxxxxx"
and copied .beam file in ebin directory. I am using 15.04 version of Ejabberd.
How I tested:
After login I sent a packet with mentioned format. But and then put the A party on offline mode. Then I tried sending messages from Party B and no push message was received. Can you please help me getting fixed this issue thanks.
Could you make the module compatible with the MySQL databases?
You could get my help if you want!
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.