Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added method to send error stanzas; emit class and instance name as p…

…arameter
  • Loading branch information...
commit 50fb90faa74b73375e8d9cf660454f66b708ed84 1 parent 70ae4d8
flosse authored
Showing with 34 additions and 7 deletions.
  1. +11 −2 README.markdown
  2. +23 −5 lib/Router.coffee
13 README.markdown
View
@@ -24,9 +24,18 @@ comp = new xmpp.Component
router = new joap.Router comp
-router.on "read", (iq)->
+router.on "read", (iq, clazz, instance)->
console.log "read iq received"
-router.on "edit", (iq)->
+router.on "edit", (iq, clazz, instance)->
console.log "edit iq received"
+
+router.on "add", (iq, clazz, instance) =>
+
+ console.log "add iq received"
+
+ if not @classes[clazz]?
+ @router.sendError "add", 404, "The class '#{clazz}' does not exist.", iq
+
+ # ...
```
28 lib/Router.coffee
View
@@ -6,16 +6,34 @@ RPC_NS = "jabber:iq:rpc"
class Router extends events.EventEmitter
- constructor: (@xmpp)->
- xmpp.on "stanza", (iq)=>
+ constructor: (@xmpp) ->
+ @xmpp.on "stanza", (iq) =>
if iq.name is "iq"
- child = iq.children[0]
+ child = iq.children[0]
+ to = iq.attrs.to
+ clazz = to.split('@')[0]
+ instance = to.split('/')[1]
if child.attrs?.xmlns is JOAP_NS
- @emit child.name.toLowerCase(), iq
+ @emit child.name.toLowerCase(), iq, clazz, instance
else if child.attrs?.xmlns is RPC_NS
- @emit "rpc", iq
+ @emit "rpc", iq, clazz, instance
+
+ sendError: (action, code, msg, iq) ->
+
+ err = new ltx.Element "iq",
+ id: iq.attrs.id
+ type:'error'
+ to: iq.attrs.from
+ from: iq.attrs.to
+
+ err
+ .c(action, xmlns: JOAP_NS).up()
+ .c("error", code: code)
+ .t(msg)
+
+ @xmpp.send err
exports.Router = Router
Please sign in to comment.
Something went wrong with that request. Please try again.