1 function doLogin(aForm) {
2 room = 'guests@conference.babelmonkeys.de';
3 domain = 'babelmonkeys.de'
5 password = 'ooje0OjuJeekaek6';
6 if (!aForm.nickname.value)
10 oArgs.httpbase = '/http-bind/';
11 oArgs.timerval = 2000;
12 con = new JSJaCHttpBindingConnection(oArgs)
14 nickname = aForm.nickname.value;
18 oArgs.domain = domain;
19 oArgs.username = user;
20 oArgs.resource = randomString();
21 oArgs.pass = password;
30 function setupHandlers(con) {
31 con.registerHandler('message', handleMessage);
32 con.registerHandler('presence', handlePresence);
33 con.registerHandler('iq', handleIQ);
34 con.registerHandler('onconnect', handleConnected);
35 con.registerHandler('onerror', handleError);
36 // con.registerHandler('status_changed', handleStatusChanged);
37 con.registerHandler('ondisconnect', handleDisconnected);
39 con.registerIQGet('query', NS_VERSION, handleIqVersion);
40 con.registerIQGet('query', NS_TIME, handleIqTime);
43 function handleConnected() {
44 con.send(new JSJaCPresence());
45 GCpresence = new JSJaCPresence();
46 GCpresence.setTo(room + '/' + nickname);
49 // Make things (in)visible
50 document.getElementById('login').style.display = 'none';
51 document.getElementById('chat').style.display = 'block';
52 document.getElementById('roster').style.display = 'block';
53 document.getElementById('entry').style.display = 'block';
56 function handleError(e) {
57 alert("An error occured:" +
58 "\nCode: " + e.getAttribute('code') +
59 "\nType: " + e.getAttribute('type') +
60 "\nCondition: " + e.firstChild.nodeName);
61 // Make things (in)visible
62 document.getElementById('login').style.display = 'block';
63 document.getElementById('chat').style.display = 'none';
64 document.getElementById('roster').style.display = 'none';
65 document.getElementById('entry').style.display = 'none';
72 function handleDisconnected() {
73 // Make things (in)visible
74 document.getElementById('login').style.display = 'block';
75 document.getElementById('chat').style.display = 'none';
76 document.getElementById('roster').style.display = 'none';
77 document.getElementById('entry').style.display = 'none';
80 function addBubble(nick) {
82 if (!document.getElementById(id)) {
83 root = document.getElementsByTagName('body')[0];
85 div += '<div id="' + id + '" class="bubble" onmousedown="startDrag(this)">';
86 div += '<a href="#" onclick="' +"document.getElementById('" + id + "').style.display='none'" + '">Close</a>';
87 div += '<div id="' + id + 'Chat" class="bubbleChat"></div>';
88 div += '<form id="' + id + 'Form" class="bubbleForm" onsubmit="return sendChatMessage(this,' + "'" + nick + "');" + '" action="#">';
89 div += '<input type="text" name="text" id="' + id + 'Text" class="bubbleForm"/>';
92 root.innerHTML += div;
94 document.getElementById(id).style.display = 'block';
97 function handleMessage(aJSJaCPacket) {
99 sender = aJSJaCPacket.getFromJID().getResource()
100 html += '<div class="msg">';
102 html += '<span class="sender">';
105 html += aJSJaCPacket.getBody().htmlEnc() + '</div>';
107 html += '<span class="server">';
108 html += aJSJaCPacket.getBody().htmlEnc() + '</span></div>';
111 if (aJSJaCPacket.getType() == 'chat') {
113 document.getElementById(id + 'Chat').innerHTML += html;
114 document.getElementById(id + 'Chat').lastChild.scrollIntoView();
116 document.getElementById('chat').innerHTML += html;
117 document.getElementById('chat').lastChild.scrollIntoView();
121 function handlePresence(aJSJaCPacket) {
122 if (aJSJaCPacket.getFromJID().toString().split('/')[0] != room)
124 roster_list = document.getElementById('roster_list');
125 nick = aJSJaCPacket.getFromJID().getResource();
126 if (aJSJaCPacket.getType() == 'unavailable') {
127 element = document.getElementById(nick);
128 roster_list.removeChild(element);
130 roster_list.innerHTML += '<li id="' + nick + '" onclick="addBubble(' + "'" + nick + "')" + '" >' + nick + '</li>';
134 function handleIQ(iq) {
135 con.send(iq.errorReply(ERR_FEATURE_NOT_IMPLEMENTED));
138 function handleIqVersion(iq) {
140 iq.buildNode('name', 'jsjacChatClient'),
141 iq.buildNode('version', JSJaC.Version),
142 iq.buildNode('os', navigator.userAgent)
147 function handleIqTime(iq) {
148 var now = new Date();
149 con.send(iq.reply([iq.buildNode('display',
150 now.toLocaleString()),
154 now.toLocaleString().substring(now.toLocaleString().lastIndexOf(' ')+1))
159 function sendMessage(aForm) {
160 if (aForm.text.value) {
161 message = new JSJaCMessage();
162 message.setBody(aForm.text.value);
163 message.setType('groupchat');
166 aForm.text.value = '';
171 function sendChatMessage(aForm, to) {
172 if (aForm.text.value) {
173 message = new JSJaCMessage();
174 message.setBody(aForm.text.value);
175 message.setType('chat');
176 message.setTo(room + '/' + to);
178 aForm.text.value = '';
180 html += '<div class="msg">';
181 html += '<span class="sender">';
184 html += message.getBody().htmlEnc() + '</div>';
185 document.getElementById(to + 'BubbleChat').innerHTML += html;
186 document.getElementById(to + 'BubbleChat').lastChild.scrollIntoView();
192 function randomString() {
193 var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
194 var string_length = 20;
195 var randomstring = '';
196 for (var i=0; i<string_length; i++) {
197 var rnum = Math.floor(Math.random() * chars.length);
198 randomstring += chars.substring(rnum,rnum+1);
203 var dragElement = null;
209 function startDrag(element) {
210 dragElement = element;
211 offX = mouseX - dragElement.offsetLeft;
212 offY = mouseY - dragElement.offsetTop;
215 function doDrag(eve) {
220 dragElement.style.left = (mouseX - offX) + 'px';
221 dragElement.style.top = (mouseY - offY) + 'px';
225 function stopDrag(eve) {
229 onunload = function() {
234 onmousemove = doDrag;
236 onmouseup = stopDrag;