Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 93 lines (64 sloc) 1.782 kB
f4bf100 @flosse initial commit
authored
1 # node-xmpp-joap
2
3 Jabber Object Access Protocol
4 [XEP-0075](http://xmpp.org/extensions/xep-0075.html) library for
5 [node-xmpp](https://github.com/astro/node-xmpp).
6
7 ## Installation
8
9 With package manager [npm](http://npmjs.org/):
10
11 npm install node-xmpp-joap
70ae4d8 @flosse describe router usage
authored
12
13 ## Usage
14
f7c3eb7 @flosse added first prototype of a simple object manager
authored
15 ### Manager
16
17 ```coffeescript
18 xmpp = require "node-xmpp"
19 joap = require "node-xmpp-joap"
20
21 comp = new xmpp.Component
22 jid : "mycomponent"
23 password : "secret"
24 host : "127.0.0.1"
25 port : "8888"
26
27 class User
28 constructor: (params) ->
29 { @name, @age } = params
30
031caef @flosse added edit and delete support; refactored error handling
authored
31 # create a new manager instance
f7c3eb7 @flosse added first prototype of a simple object manager
authored
32 mgr = new joap.Manager comp
031caef @flosse added edit and delete support; refactored error handling
authored
33
34 # add a class
35 mgr.addClass "User", User, ["name", "age"], ["name"]
36
37 # implement the ACL by overriding the method
38 mgr.hasPermission = (action) ->
39
40 if myACLRules(action.from, action.type, action.class, action.instance)
41 true
42 else
43 false
44
f7c3eb7 @flosse added first prototype of a simple object manager
authored
45 ```
46
47 ### Router
48
70ae4d8 @flosse describe router usage
authored
49 ```coffeescript
50 xmpp = require "node-xmpp"
51 joap = require "node-xmpp-joap"
52
53 comp = new xmpp.Component
54 jid : "mycomponent"
55 password : "secret"
56 host : "127.0.0.1"
57 port : "8888"
58
b8db4bf @flosse set package version to v0.0.2
authored
59 classes = {}
5f55d2e @flosse moved parse and serialize methods into separate classes; created joap…
authored
60 objects = {}
b8db4bf @flosse set package version to v0.0.2
authored
61
70ae4d8 @flosse describe router usage
authored
62 router = new joap.Router comp
63
031caef @flosse added edit and delete support; refactored error handling
authored
64 router.on "action", (a) ->
65 if a.class? and a.instance? and a.type is "read"
66 router.sendResponse a, objects[a.class][a.instance]
cdb058c @flosse added parser
authored
67
031caef @flosse added edit and delete support; refactored error handling
authored
68 router.on "read", (action) ->
70ae4d8 @flosse describe router usage
authored
69 console.log "read iq received"
70
031caef @flosse added edit and delete support; refactored error handling
authored
71 router.on "edit", (action) ->
70ae4d8 @flosse describe router usage
authored
72 console.log "edit iq received"
50fb90f @flosse added method to send error stanzas; emit class and instance name as p…
authored
73
031caef @flosse added edit and delete support; refactored error handling
authored
74 router.on "add", (action) ->
50fb90f @flosse added method to send error stanzas; emit class and instance name as p…
authored
75 console.log "add iq received"
76
031caef @flosse added edit and delete support; refactored error handling
authored
77 if not classes[action.class]?
78 router.sendError "add", 404, "The class '#{action.class}' does not exists."
50fb90f @flosse added method to send error stanzas; emit class and instance name as p…
authored
79
80 # ...
cdb058c @flosse added parser
authored
81
031caef @flosse added edit and delete support; refactored error handling
authored
82 router.on "rpc", (action) ->
cdb058c @flosse added parser
authored
83 console.log "calling #{action.method} with:"
84 for param in actions.params
85 console.log param
86 ```
87
88 ## Running tests
89
90 ```shell
91 jasmine-node --coffee --color spec/
70ae4d8 @flosse describe router usage
authored
92 ```
Something went wrong with that request. Please try again.