root / trunk / web / dojo / dojox / xmpp / ChatService.js @ 10
History | View | Annotate | Download (3.18 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.xmpp.ChatService"]){ |
||
9 | dojo._hasResource["dojox.xmpp.ChatService"]=true; |
||
10 | dojo.provide("dojox.xmpp.ChatService");
|
||
11 | dojox.xmpp.chat={CHAT_STATE_NS:"http://jabber.org/protocol/chatstates",ACTIVE_STATE:"active",COMPOSING_STATE:"composing",INACTIVE_STATE:"inactive",PAUSED_STATE:"paused",GONE_STATE:"gone"}; |
||
12 | dojo.declare("dojox.xmpp.ChatService",null,{state:"",constructor:function(){ |
||
13 | this.state=""; |
||
14 | this.chatid=Math.round(Math.random()*1000000000000000); |
||
15 | },recieveMessage:function(_1,_2){ |
||
16 | if(_1&&!_2){
|
||
17 | this.onNewMessage(_1);
|
||
18 | } |
||
19 | },setSession:function(_3){ |
||
20 | this.session=_3;
|
||
21 | },setState:function(_4){ |
||
22 | if(this.state!=_4){ |
||
23 | this.state=_4;
|
||
24 | } |
||
25 | },invite:function(_5){ |
||
26 | if(this.uid){ |
||
27 | return;
|
||
28 | } |
||
29 | if(!_5||_5==""){ |
||
30 | throw new Error("ChatService::invite() contact is NULL"); |
||
31 | } |
||
32 | this.uid=_5;
|
||
33 | var _6={xmlns:"jabber:client",to:this.uid,from:this.session.jid+"/"+this.session.resource,type:"chat"}; |
||
34 | var _7=new dojox.string.Builder(dojox.xmpp.util.createElement("message",_6,false)); |
||
35 | _7.append(dojox.xmpp.util.createElement("thread",{},false)); |
||
36 | _7.append(this.chatid);
|
||
37 | _7.append("</thread>");
|
||
38 | _7.append(dojox.xmpp.util.createElement("active",{xmlns:dojox.xmpp.chat.CHAT_STATE_NS},true)); |
||
39 | _7.append("</message>");
|
||
40 | this.session.dispatchPacket(_7.toString());
|
||
41 | this.onInvite(_5);
|
||
42 | this.setState(dojox.xmpp.chat.CHAT_STATE_NS);
|
||
43 | },sendMessage:function(_8){ |
||
44 | if(!this.uid){ |
||
45 | return;
|
||
46 | } |
||
47 | if((!_8.body||_8.body=="")&&!_8.xhtml){ |
||
48 | return;
|
||
49 | } |
||
50 | var _9={xmlns:"jabber:client",to:this.uid,from:this.session.jid+"/"+this.session.resource,type:"chat"}; |
||
51 | var _a=new dojox.string.Builder(dojox.xmpp.util.createElement("message",_9,false)); |
||
52 | var _b=dojox.xmpp.util.createElement("html",{"xmlns":dojox.xmpp.xmpp.XHTML_IM_NS},false); |
||
53 | var _c=dojox.xmpp.util.createElement("body",{"xml:lang":this.session.lang,"xmlns":dojox.xmpp.xmpp.XHTML_BODY_NS},false)+_8.body+"</body>"; |
||
54 | var _d=dojox.xmpp.util.createElement("body",{},false)+dojox.xmpp.util.stripHtml(_8.body)+"</body>"; |
||
55 | if(_a.subject&&_a.subject!=""){ |
||
56 | _a.append(dojox.xmpp.util.createElement("subject",{},false)); |
||
57 | _a.append(_a.subject); |
||
58 | _a.append("</subject>");
|
||
59 | } |
||
60 | _a.append(_d); |
||
61 | _a.append(_b); |
||
62 | _a.append(_c); |
||
63 | _a.append("</html>");
|
||
64 | _a.append(dojox.xmpp.util.createElement("thread",{},false)); |
||
65 | _a.append(this.chatid);
|
||
66 | _a.append("</thread>");
|
||
67 | if(this.useChatStates){ |
||
68 | _a.append(dojox.xmpp.util.createElement("active",{xmlns:dojox.xmpp.chat.CHAT_STATE_NS},true)); |
||
69 | } |
||
70 | _a.append("</message>");
|
||
71 | this.session.dispatchPacket(_a.toString());
|
||
72 | },sendChatState:function(_e){ |
||
73 | if(!this.useChatState||this.firstMessage){ |
||
74 | return;
|
||
75 | } |
||
76 | if(_e==this._currentState){ |
||
77 | return;
|
||
78 | } |
||
79 | var _f={xmlns:"jabber:client",to:this.uid,from:this.session.jid+"/"+this.session.resource,type:"chat"}; |
||
80 | var _10=new dojox.string.Builder(dojox.xmpp.util.createElement("message",_f,false)); |
||
81 | _10.append(dojox.xmpp.util.createElement(_e,{xmlns:dojox.xmpp.chat.CHAT_STATE_NS},true)); |
||
82 | this._currentState=_e;
|
||
83 | _10.append("<thread>");
|
||
84 | _10.append(this.chatid);
|
||
85 | _10.append("</thread></message>");
|
||
86 | this.session.dispatchPacket(_10.toString());
|
||
87 | },onNewMessage:function(msg){ |
||
88 | },onInvite:function(_11){ |
||
89 | }}); |
||
90 | } |