]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/ircconnection.js
Dos2Unix
[irc/quakenet/qwebirc.git] / js / irc / ircconnection.js
1 var IRCConnection = new Class({
2 Implements: [Events, Options],
3 options: {
4 initialNickname: "ircconnX"
5 },
6 initialize: function(options) {
7 this.setOptions(options);
8
9 this.initialNickname = this.options.initialNickname;
10
11 this.counter = 0;
12 this.disconnected = false;
13 },
14 send: function(data) {
15 var r = new Request.JSON({url: "/e/p/" + this.sessionid + "?c=" + encodeURIComponent(data) + "&t=" + this.counter++, onComplete: function(o) {
16 if(o[0] == false)
17 alert("An error occured: " + o[1]);
18 }});
19
20 r.get();
21 },
22 x: function() {
23 this.fireEvent("recv", [[false, "moo"]]);
24 },
25 recv: function() {
26 if(this.disconnected)
27 return;
28
29 var r = new Request.JSON({url: "/e/s/" + this.sessionid + "?t=" + this.counter++, onComplete: function(o) {
30 if(o[0] == false) {
31 alert("An error occured: " + o[1]);
32 return;
33 }
34 o.each(function(x) {
35 this.fireEvent("recv", [x]);
36 }, this);
37
38 this.recv();
39 }.bind(this)});
40 r.get();
41 },
42 connect: function() {
43 var r = new Request.JSON({url: "/e/n?nick=" + encodeURIComponent(this.initialNickname) + "&r=" + Math.random() * 1024 * 1024, onComplete: function(o) {
44 if(o[0] == false) {
45 alert("An error occured: " + o[1]);
46 return;
47 }
48 this.sessionid = o[1];
49
50 this.recv();
51 }.bind(this)});
52 r.get();
53 },
54 disconnect: function() {
55 this.disconnected = true;
56 }
57 });