//>>built define("dojox/xmpp/xmppSession",["dijit","dojo","dojox","dojo/require!dojox/xmpp/TransportSession,dojox/xmpp/RosterService,dojox/xmpp/PresenceService,dojox/xmpp/UserService,dojox/xmpp/ChatService,dojox/xmpp/sasl"],function(_1,_2,_3){ _2.provide("dojox.xmpp.xmppSession"); _2.require("dojox.xmpp.TransportSession"); _2.require("dojox.xmpp.RosterService"); _2.require("dojox.xmpp.PresenceService"); _2.require("dojox.xmpp.UserService"); _2.require("dojox.xmpp.ChatService"); _2.require("dojox.xmpp.sasl"); _3.xmpp.xmpp={STREAM_NS:"http://etherx.jabber.org/streams",CLIENT_NS:"jabber:client",STANZA_NS:"urn:ietf:params:xml:ns:xmpp-stanzas",SASL_NS:"urn:ietf:params:xml:ns:xmpp-sasl",BIND_NS:"urn:ietf:params:xml:ns:xmpp-bind",SESSION_NS:"urn:ietf:params:xml:ns:xmpp-session",BODY_NS:"http://jabber.org/protocol/httpbind",XHTML_BODY_NS:"http://www.w3.org/1999/xhtml",XHTML_IM_NS:"http://jabber.org/protocol/xhtml-im",INACTIVE:"Inactive",CONNECTED:"Connected",ACTIVE:"Active",TERMINATE:"Terminate",LOGIN_FAILURE:"LoginFailure",INVALID_ID:-1,NO_ID:0,error:{BAD_REQUEST:"bad-request",CONFLICT:"conflict",FEATURE_NOT_IMPLEMENTED:"feature-not-implemented",FORBIDDEN:"forbidden",GONE:"gone",INTERNAL_SERVER_ERROR:"internal-server-error",ITEM_NOT_FOUND:"item-not-found",ID_MALFORMED:"jid-malformed",NOT_ACCEPTABLE:"not-acceptable",NOT_ALLOWED:"not-allowed",NOT_AUTHORIZED:"not-authorized",SERVICE_UNAVAILABLE:"service-unavailable",SUBSCRIPTION_REQUIRED:"subscription-required",UNEXPECTED_REQUEST:"unexpected-request"}}; _3.xmpp.xmppSession=function(_4){ this.roster=[]; this.chatRegister=[]; this._iqId=Math.round(Math.random()*1000000000); if(_4&&_2.isObject(_4)){ _2.mixin(this,_4); } this.session=new _3.xmpp.TransportSession(_4); _2.connect(this.session,"onReady",this,"onTransportReady"); _2.connect(this.session,"onTerminate",this,"onTransportTerminate"); _2.connect(this.session,"onProcessProtocolResponse",this,"processProtocolResponse"); }; _2.extend(_3.xmpp.xmppSession,{roster:[],chatRegister:[],_iqId:0,open:function(_5,_6,_7){ if(!_5){ throw new Error("User id cannot be null"); }else{ this.jid=_5; if(_5.indexOf("@")==-1){ this.jid=this.jid+"@"+this.domain; } } if(_6){ this.password=_6; } if(_7){ this.resource=_7; } this.session.open(); },close:function(){ this.state=_3.xmpp.xmpp.TERMINATE; this.session.close(_3.xmpp.util.createElement("presence",{type:"unavailable",xmlns:_3.xmpp.xmpp.CLIENT_NS},true)); },processProtocolResponse:function(_8){ var _9=_8.nodeName; var _a=_9.indexOf(":"); if(_a>0){ _9=_9.substring(_a+1); } switch(_9){ case "iq": case "presence": case "message": case "features": this[_9+"Handler"](_8); break; default: if(_8.getAttribute("xmlns")==_3.xmpp.xmpp.SASL_NS){ this.saslHandler(_8); } } },messageHandler:function(_b){ switch(_b.getAttribute("type")){ case "chat": this.chatHandler(_b); break; case "normal": default: this.simpleMessageHandler(_b); } },iqHandler:function(_c){ if(_c.getAttribute("type")=="set"){ this.iqSetHandler(_c); return; }else{ if(_c.getAttribute("type")=="get"){ return; } } },presenceHandler:function(_d){ switch(_d.getAttribute("type")){ case "subscribe": this.presenceSubscriptionRequest(_d.getAttribute("from")); break; case "subscribed": case "unsubscribed": break; case "error": this.processXmppError(_d); break; default: this.presenceUpdate(_d); break; } },featuresHandler:function(_e){ var _f=[]; var _10=false; var _11=false; if(_e.hasChildNodes()){ for(var i=0;i<_e.childNodes.length;i++){ var n=_e.childNodes[i]; switch(n.nodeName){ case "mechanisms": for(var x=0;x-1&&_13){ var _15=this.chatRegister[_14]; _15.setState(_13); if(_15.firstMessage){ if(_13==_3.xmpp.chat.ACTIVE_STATE){ _15.useChatState=(_13!=null)?true:false; _15.firstMessage=false; } } } if((!_12.body||_12.body=="")&&!_12.xhtml){ return; } if(_14>-1){ var _15=this.chatRegister[_14]; _15.recieveMessage(_12); }else{ var _16=new _3.xmpp.ChatService(); _16.uid=this.getBareJid(_12.from); _16.chatid=_12.chatid; _16.firstMessage=true; if(!_13||_13!=_3.xmpp.chat.ACTIVE_STATE){ this.useChatState=false; } this.registerChatInstance(_16,_12); } },simpleMessageHandler:function(msg){ },registerChatInstance:function(_17,_18){ _17.setSession(this); this.chatRegister.push(_17); this.onRegisterChatInstance(_17,_18); _17.recieveMessage(_18,true); },iqSetHandler:function(msg){ if(msg.hasChildNodes()){ var fn=msg.firstChild; switch(fn.nodeName){ case "query": if(fn.getAttribute("xmlns")=="jabber:iq:roster"){ this.rosterSetHandler(fn); this.sendIqResult(msg.getAttribute("id"),msg.getAttribute("from")); } break; default: break; } } },sendIqResult:function(_19,to){ var req={id:_19,to:to||this.domain,type:"result",from:this.jid+"/"+this.resource}; this.dispatchPacket(_3.xmpp.util.createElement("iq",req,true)); },rosterSetHandler:function(_1a){ for(var i=0;i<_1a.childNodes.length;i++){ var n=_1a.childNodes[i]; if(n.nodeName=="item"){ var _1b=false; var _1c=-1; var _1d=null; var _1e=null; for(var x=0;x"); var def=this.dispatchPacket(req,"iq",_23.id); def.addCallback(this,"onRetrieveRoster"); },getRosterIndex:function(jid){ if(jid.indexOf("@")==-1){ jid+="@"+this.domain; } for(var i=0;i"); } _27.append(""); var def=this.dispatchPacket(_27,"iq",_26.id); def.addCallback(this,function(msg){ this.onBindResource(msg,_25); return msg; }); },getNextIqId:function(){ return "im_"+this._iqId++; },presenceSubscriptionRequest:function(msg){ this.onSubscriptionRequest(msg); },dispatchPacket:function(msg,_28,_29){ if(this.state!="Terminate"){ return this.session.dispatchPacket(msg,_28,_29); }else{ } },setState:function(_2a,_2b){ if(this.state!=_2a){ if(this["on"+_2a]){ this["on"+_2a](_2a,this.state,_2b); } this.state=_2a; } },search:function(_2c,_2d,_2e){ var req={id:this.getNextIqId(),"xml:lang":this.lang,type:"set",from:this.jid+"/"+this.resource,to:_2d}; var _2f=new _3.string.Builder(_3.xmpp.util.createElement("iq",req,false)); _2f.append(_3.xmpp.util.createElement("query",{xmlns:"jabber:iq:search"},false)); _2f.append(_3.xmpp.util.createElement(_2e,{},false)); _2f.append(_2c); _2f.append(""); _2f.append(""); var def=this.dispatchPacket(_2f.toString,"iq",req.id); def.addCallback(this,"_onSearchResults"); },_onSearchResults:function(msg){ if((msg.getAttribute("type")=="result")&&(msg.hasChildNodes())){ this.onSearchResults([]); } },onLogin:function(){ this.retrieveRoster(); },onLoginFailure:function(msg){ },onBindResource:function(msg,_30){ if(msg.getAttribute("type")=="result"){ if((msg.hasChildNodes())&&(msg.firstChild.nodeName=="bind")){ var _31=msg.firstChild; if((_31.hasChildNodes())&&(_31.firstChild.nodeName=="jid")){ if(_31.firstChild.hasChildNodes()){ var _32=_31.firstChild.firstChild.nodeValue; this.jid=this.getBareJid(_32); this.resource=this.getResourceFromJid(_32); } } if(_30){ var _33={id:this.getNextIqId(),type:"set"}; var _34=new _3.string.Builder(_3.xmpp.util.createElement("iq",_33,false)); _34.append(_3.xmpp.util.createElement("session",{xmlns:_3.xmpp.xmpp.SESSION_NS},true)); _34.append(""); var def=this.dispatchPacket(_34,"iq",_33.id); def.addCallback(this,"onBindSession"); return; } }else{ } this.onLogin(); }else{ if(msg.getAttribute("type")=="error"){ var err=this.processXmppError(msg); this.onLoginFailure(err); } } },onBindSession:function(msg){ if(msg.getAttribute("type")=="error"){ var err=this.processXmppError(msg); this.onLoginFailure(err); }else{ this.onLogin(); } },onSearchResults:function(_35){ },onRetrieveRoster:function(msg){ if((msg.getAttribute("type")=="result")&&msg.hasChildNodes()){ var _36=msg.getElementsByTagName("query")[0]; if(_36.getAttribute("xmlns")=="jabber:iq:roster"){ for(var i=0;i<_36.childNodes.length;i++){ if(_36.childNodes[i].nodeName=="item"){ this.roster[i]=this.createRosterEntry(_36.childNodes[i]); } } } }else{ if(msg.getAttribute("type")=="error"){ } } this.setState(_3.xmpp.xmpp.ACTIVE); this.onRosterUpdated(); return msg; },onRosterUpdated:function(){ },onSubscriptionRequest:function(req){ },onPresenceUpdate:function(p){ },onTransportReady:function(){ this.setState(_3.xmpp.xmpp.CONNECTED); this.rosterService=new _3.xmpp.RosterService(this); this.presenceService=new _3.xmpp.PresenceService(this); this.userService=new _3.xmpp.UserService(this); },onTransportTerminate:function(_37,_38,_39){ this.setState(_3.xmpp.xmpp.TERMINATE,_39); },onConnected:function(){ },onTerminate:function(_3a,_3b,_3c){ },onActive:function(){ },onRegisterChatInstance:function(_3d,_3e){ },onRosterAdded:function(ri){ },onRosterRemoved:function(ri){ },onRosterChanged:function(ri,_3f){ },processXmppError:function(msg){ var err={stanzaType:msg.nodeName,id:msg.getAttribute("id")}; for(var i=0;i"); } _44.append(""); this.dispatchPacket(_44.toString()); },getBareJid:function(jid){ var i=jid.indexOf("/"); if(i!=-1){ return jid.substring(0,i); } return jid; },getResourceFromJid:function(jid){ var i=jid.indexOf("/"); if(i!=-1){ return jid.substring((i+1),jid.length); } return ""; }}); });