XmppSend_wev8.js
4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var XmppSend={
_waitCon:function(){
while(true){
Debug.log("wait");
if(con!=null){
return;
}
}
},
refreshCon:function(){
if(con==null){
Login.doLogin(jid,psw,Debug);
//XmppSend._waitCon();
}
},
preSend:function(){
},
sendMessage:function(sendTo,msg){
if (msg== '' || sendTo == '') return false;
//if (sendTo.indexOf('@') == -1) sendTo += '@' + Config.JABBERSERVER;
var aMsg = new JSJaCMessage();
aMsg.setTo(sendTo);
aMsg.setBody(msg);
if(sendTo.indexOf("conference")!=-1){
aMsg.setType('groupchat');
}
con.send(aMsg);
},
getAllList:function(){
var iq = new JSJaCIQ();
iq.setIQ(null,'get','weavermessager_roster');
iq.setQuery('jabber:iq:roster');
Debug.log("do");
con.send(iq,XmppReceive.handleRoster);
},
getAllOnlineList:function(){
var iq = new JSJaCIQ();
iq.setIQ(null,'get','weavermessager_prefs');
var query = iq.setQuery('jabber:iq:private');
query.appendChild(iq.buildNode('weavermessager', {'xmlns': 'weavermessager:prefs'}));
con.send(iq,XmppReceive.handlePrefs);
},
getChatList:function(){
var iq = new JSJaCIQ();
iq.setType('get');
iq.setTo(Config.DEFAULTCONFERENCESERVER);
iq.setID(Config.DEFAULTCONFERENCESERVER+"IQ");
iq.setQuery('http://jabber.org/protocol/disco#items');
con.send(iq,XmppReceive.handleChatList);
},
joinToChat:function(chatid,nickname){
var pass="";
var aPresence = new JSJaCPresence();
aPresence.setTo(chatid+'/'+nickname);
var x = aPresence.appendNode('x',{'xmlns': 'http://jabber.org/protocol/muc'});
if (typeof(pass) != 'undefined' && pass != '') x.appendChild(aPresence.buildNode('password' ,pass));
aPresence.setShow("available");
aPresence.setStatus("online");
con.send(aPresence);
},
getChatNeedConfig:function(toJid){
alert(toJid)
var iq = new JSJaCIQ();
iq.setTo(toJid);
iq.setType('get');
iq.setQuery('http://jabber.org/protocol/muc#owner');
con.send(iq, XmppReceive.handleChatConfig);
},
sendChatInit:function(){
var aPresence = new JSJaCPresence();
aPresence.setTo(Page.chatPara.chatId+'/'+nickname);
var x = aPresence.appendNode('x', {'xmlns': 'http://jabber.org/protocol/muc'});
aPresence.setShow('');
aPresence.setStatus('');
Debug.log("sending muc presence:\n"+aPresence.xml(),3);
con.send(aPresence);
},
sendChatConfig:function(){
ownerJid=Page.chatPara.ownerJid
toJid=Page.chatPara.chatId;
chatName=Page.chatPara.chatName;
var xmlStr='<x xmlns="jabber:x:data" type="submit"><field var="FORM_TYPE"><value>http://jabber.org/protocol/muc#roomconfig</value>'+
'</field><field var="muc#roomconfig_roomname"><value>'+chatName+'</value></field><field var="muc#roomconfig_roomdesc">'+
'<value>'+chatName+'</value></field><field var="muc#roomconfig_changesubject"><value>0</value></field>'+
'<field var="muc#roomconfig_maxusers"><value>30</value></field><field var="muc#roomconfig_publicroom"><value>1</value>'+
'</field><field var="muc#roomconfig_persistentroom"><value>0</value></field><field var="muc#roomconfig_moderatedroom">'+
'<value>0</value></field><field var="muc#roomconfig_membersonly"><value>0</value></field><field var="muc#roomconfig_allowinvites">'+
'<value>0</value></field><field var="muc#roomconfig_passwordprotectedroom"><value>0</value></field>'+
'<field var="muc#roomconfig_whois"><value>anyone</value></field><field var="muc#roomconfig_enablelogging">'+
'<value>0</value></field><field var="x-muc#roomconfig_reservednick"><value>0</value></field>'+
'<field var="x-muc#roomconfig_canchangenick"><value>1</value></field><field var="x-muc#roomconfig_registration"><value>1</value>'+
'</field><field var="muc#roomconfig_roomowners"><value>'+ownerJid+'</value></field></x>';
var iq = new JSJaCIQ();
iq.setType('set');
iq.setTo(toJid);
var query = iq.setQuery('http://jabber.org/protocol/muc#owner');
var xmldoc = XmlDocument.create('body','foo');
xmldoc.loadXML('<body>'+xmlStr+'</body>');
for (var i=0; i<xmldoc.firstChild.childNodes.length; i++){
query.appendChild(xmldoc.firstChild.childNodes.item(i).cloneNode(true));
}
con.send(iq);
},
sendDestroyChat:function(chatid){
var iq = new JSJaCIQ();
iq.setType('set');
iq.setTo(chatid);
var query = iq.setQuery('http://jabber.org/protocol/muc#owner');
query.appendChild(iq.getDoc().createElement('destroy')).appendChild(iq.getDoc().createElement('reason')).appendChild(iq.getDoc().createTextNode('Close'));
con.send(iq);
},
sendMyState:function(){
var aPresence = new JSJaCPresence();
aPresence.setType(onlstat);
con.send(aPresence);
}
}