Strophe.addConnectionPlugin("pubsub",{_connection:null,init:function(conn){this._connection=conn;Strophe.addNamespace("PUBSUB","http://jabber.org/protocol/pubsub");Strophe.addNamespace("PUBSUB_SUBSCRIBE_OPTIONS",Strophe.NS.PUBSUB+"#subscribe_options");Strophe.addNamespace("PUBSUB_ERRORS",Strophe.NS.PUBSUB+"#errors");Strophe.addNamespace("PUBSUB_EVENT",Strophe.NS.PUBSUB+"#event");Strophe.addNamespace("PUBSUB_OWNER",Strophe.NS.PUBSUB+"#owner");Strophe.addNamespace("PUBSUB_AUTO_CREATE",Strophe.NS.PUBSUB+"#auto-create");Strophe.addNamespace("PUBSUB_PUBLISH_OPTIONS",Strophe.NS.PUBSUB+"#publish-options");Strophe.addNamespace("PUBSUB_NODE_CONFIG",Strophe.NS.PUBSUB+"#node_config");Strophe.addNamespace("PUBSUB_CREATE_AND_CONFIGURE",Strophe.NS.PUBSUB+"#create-and-configure");Strophe.addNamespace("PUBSUB_SUBSCRIBE_AUTHORIZATION",Strophe.NS.PUBSUB+"#subscribe_authorization");Strophe.addNamespace("PUBSUB_GET_PENDING",Strophe.NS.PUBSUB+"#get-pending");Strophe.addNamespace("PUBSUB_MANAGE_SUBSCRIPTIONS",Strophe.NS.PUBSUB+"#manage-subscriptions");Strophe.addNamespace("PUBSUB_META_DATA",Strophe.NS.PUBSUB+"#meta-data")},createNode:function(jid,service,node,options,call_back){var iqid=this._connection.getUniqueId("pubsubcreatenode");var iq=$iq({from:jid,to:service,type:"set",id:iqid});var c_options=Strophe.xmlElement("configure",[]);var x=Strophe.xmlElement("x",[["xmlns","jabber:x:data"]]);var form_field=Strophe.xmlElement("field",[["var","FORM_TYPE"],["type","hidden"]]);var value=Strophe.xmlElement("value",[]);var text=Strophe.xmlTextNode(Strophe.NS.PUBSUB+"#node_config");value.appendChild(text);form_field.appendChild(value);x.appendChild(form_field);for(var i in options){var val=options[i];x.appendChild(val)}if(options.length&&options.length!=0){c_options.appendChild(x)}iq.c("pubsub",{xmlns:Strophe.NS.PUBSUB}).c("create",{node:node}).up().cnode(c_options);this._connection.addHandler(call_back,null,"iq",null,iqid,null);this._connection.send(iq.tree());return iqid},subscribe:function(jid,service,node,options,event_cb,call_back){var subid=this._connection.getUniqueId("subscribenode");var sub_options=Strophe.xmlElement("options",[]);var x=Strophe.xmlElement("x",[["xmlns","jabber:x:data"]]);var form_field=Strophe.xmlElement("field",[["var","FORM_TYPE"],["type","hidden"]]);var value=Strophe.xmlElement("value",[]);var text=Strophe.xmlTextNode(Strophe.NS.PUBSUB_SUBSCRIBE_OPTIONS);value.appendChild(text);form_field.appendChild(value);x.appendChild(form_field);var sub=$iq({from:jid,to:service,type:"set",id:subid});if(options&&options.length&&options.length!==0){for(var i=0;i