Permalink
Browse files

update to use ejabberd

  • Loading branch information...
stliu committed Mar 4, 2014
1 parent 6b7e16b commit 791f4a5c996cb2061884254c2d4974af68eb452e
Showing with 15 additions and 29 deletions.
  1. +9 −21 lib/pushservices/xmpp-elements.coffee
  2. +6 −8 lib/pushservices/xmpp.coffee
@@ -1,7 +1,7 @@
xmpp = require 'node-xmpp'
-exports.register = (id, jid, password) ->
- return new xmpp.Element('iq', {id:id, to:'ac2', type:'set'})
+exports.register = (id, jid, password, host) ->
+ return new xmpp.Element('iq', {id:id, to:host, type:'set'})
.c('query', {xmlns:'jabber:iq:register'})
.c('username').t(jid)
.up()
@@ -16,10 +16,10 @@ exports.register = (id, jid, password) ->
exports.presence = () ->
return new xmpp.Element('presence', {}).c('show').t('chat').up().c('status').t('this is the push server, enjoy')
-exports.publish = (id, node, message) ->
+exports.publish = (id, node, message, host) ->
return new xmpp.Element('iq', {
id: id,
- to: 'pubsub.ac2',
+ to: "pubsub.#{host}",
type: 'set'
}).c('pubsub', {
xmlns: 'http://jabber.org/protocol/pubsub'
@@ -29,36 +29,24 @@ exports.publish = (id, node, message) ->
xmlns: 'easemob:pubsub'
}).t(message).root()
-exports.subscribe = (id, node, jid) ->
+exports.subscribe = (id, node, jid, host) ->
return new xmpp.Element('iq', {
id: id,
- to: 'pubsub.ac2',
+ to: "pubsub.#{host}",
type: 'set',
- from: 'admin@ac2'
+ from: "admin@#{host}"
} ).c('pubsub', {
xmlns: 'http://jabber.org/protocol/pubsub#owner'
}).c('subscriptions', {
node: node
})
.c('subscription',{jid: jid, subscription:'subscribed'})
.root()
-#exports.subscribe = (id, node, jid) ->
-# return new xmpp.Element('iq', {
-# id: id,
-# to: 'pubsub.ac2',
-# type: 'set',
-# from: 'admin@ac2'
-# } ).c('pubsub', {
-# xmlns: 'http://jabber.org/protocol/pubsub'
-# }).c('subscribe', {
-# node: node,
-# jid: jid
-# }).root()
-exports.create_node = (id, node_name) ->
+exports.create_node = (id, node_name, host) ->
return new xmpp.Element('iq', {
id: id,
- to: 'pubsub.ac2',
+ to: "pubsub.#{host}",
type: 'set'
}).c('pubsub', {
xmlns: 'http://jabber.org/protocol/pubsub'
@@ -24,7 +24,7 @@ class PushServiceXMPP
@logger.verbose "publishing event #{nodeName} from xmpp with payload:"
@logger.verbose sys.inspect playload
id = rand.generateKey 7
- publishElement = elements.publish(id, nodeName, playload.msg)
+ publishElement = elements.publish(id, nodeName, playload.msg, @host)
@logger.verbose 'the xml to be sent is'
@logger.verbose publishElement
@handler.send publishElement
@@ -43,7 +43,7 @@ class PushServiceXMPP
if event.exists is 1
@logger.verbose "pubsub node #{nodeName} is not existed yet, about to create"
id = rand.generateKey 7
- createNodeElement = elements.create_node(id, nodeName)
+ createNodeElement = elements.create_node(id, nodeName, @host)
@logger.verbose createNodeElement
@handler.send createNodeElement
else
@@ -53,14 +53,12 @@ class PushServiceXMPP
@logger.verbose "pubsub node is #{nodeName}, subscriber info is"
@logger.verbose sys.inspect info
id = rand.generateKey 7
- subscribeElement = elements.subscribe(id, nodeName, "#{info.jiduser}")
-# subscribeElement = elements.subscribe(id, event.name, info.jid.toLowerCase())
-
+ subscribeElement = elements.subscribe(id, nodeName, "#{info.jiduser}", @host)
@logger.verbose subscribeElement
@handler.send subscribeElement
- createSubscriber : (subscriber, fields) ->
+ createSubscriber : (subscriber, fields) =>
if fields.jiduser?
@logger.verbose 'there is already a jid attached, so ignore'
else
@@ -71,11 +69,11 @@ class PushServiceXMPP
password = jid
@logger.verbose "create new user[#{jid}] on xmpp"
id = rand.generateKey 7
- register = elements.register id, jid, password
+ register = elements.register id, jid, password, @host
@logger.verbose "the xml is:"
@logger.verbose register
@handler.send register
- subscriber.set({jid: jid})
+ subscriber.set({jiduser: jid})

0 comments on commit 791f4a5

Please sign in to comment.