node-xmpp-joap
Jabber Object Access Protocol XEP-0075 library for node-xmpp.
Installation
With package manager npm:
npm install node-xmpp-joap
Usage
;; const app = jid : "mycomponent" password : "secret" host : "127.0.0.1" port : "8888"; app;
Alias methods
app;
is equivalent to
app;
Manager
;; const comp = jid : "mycomponent" password : "secret" host : "127.0.0.1" port : "8888"; { thisid = id; } // create a new manager instanceconst mgr = comp; // add a classmgr; // implement the ACL by overriding the methodmgr { if ; else ; };
Client
xmpp = require "node-xmpp"joap = require "node-xmpp-joap" comp = jid : "mycomponent" password : "secret" host : "127.0.0.1" port : "8888" # create a new client instance c = comp # requesting the server description cdescribe "joap.server.tld" # requesting a class description cdescribe "user@server.tld" # creating a new instance cadd "use@server.tld" name:"My Name" # reading an instance cread "user@server.tld/instanceId" # reading only a few properties of an instance cread "user@server.tld/instanceId""email""age" # modifying properties of an instance cedit "user@server.tld/instanceId" age: 27 # deleting an instance cdelete "user@server.tld/instanceId" # searching for instances csearch "user@server.tld"age: 60 erriqarrayOfInstanceIDs -> # performing a method call cmethodCall "myMethod""user@server.tld/instanceId""param1""param2"
Persistence
If you want to persist the objects in a database you can simply override the
methods saveInstance
, loadInstance
and deleteInstance
.
In this example we use nStore.
nStore = require "nstore" # create database users = nStorenew './data/users.db' if err? consoleerror err else # override = if actionclass is "User" userssave objidobj next erraction else next "Storage for this class is not available"a # override = if actionclass is "User" usersget id next erractioninst else next "Storage for this class is not available"a # override = if aclass is "User" if aattributess? @usersfind aattributes next erraid for id of res else @usersall next erraid for id of res else next "Storage for this class is not available"a # override = if aclass is "User" usersremove id next erra else next "Storage for this class is not available"a
Router
xmpp = require "node-xmpp"joap = require "node-xmpp-joap" comp = jid : "mycomponent" password : "secret" host : "127.0.0.1" port : "8888" classes = objects = router = comp routeron "action" if aclass? and ainstance? and atype is "read" routersendResponse aobjectsaclassainstance routeron "read" consolelog "read iq received" routeron "edit" consolelog "edit iq received" routeron "add" consolelog "add iq received" if not classesactionclass? routersendError "'' does't exists."404action # ... routeron "search" routeron "rpc" consolelog "calling with:" for param in actionsparams consolelog param
Running tests
npm installnpm test
JOAP client implementations
ToDo's
- describe support
License
node-xmpp-joap is licensed under the MIT-Licence (see LICENSE.txt)