]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/ircconnection.js
375fbf8d0102d880ddb80926cefba116a37b35c4
1 /* This could do with a rewrite from scratch. */
3 qwebirc
.irc
.IRCConnection
= new Class({
4 Implements: [Events
, Options
],
6 initialNickname: "ircconnX",
10 initialize: function(options
) {
11 this.setOptions(options
);
13 this.initialNickname
= this.options
.initialNickname
;
16 this.disconnected
= false;
18 this.activerequest
= null;
19 this.timeoutid
= null;
21 __error: function(text
) {
22 this.fireEvent("error", text
);
23 if(this.options
.errorAlert
)
26 send: function(data
) {
29 var r
= new Request
.JSON({url: "/e/p/" + this.sessionid
+ "?c=" + encodeURIComponent(data
) + "&t=" + this.counter
++, onComplete: function(o
) {
30 if(!o
|| (o
[0] == false)) {
31 if(!this.disconnected
) {
32 this.disconnected
= true;
33 this.__error("An error occured: " + o
[1]);
42 __timeout: function() {
43 if(this.lastactiverequest
) {
44 this.lastactiverequest
.cancel();
45 this.lastactiverequest
= null;
47 if(this.activerequest
) {
48 this.lastactiverequest
= this.activerequest
;
49 /*this.activerequest.cancel();
50 this.activerequest = null;*/
52 if($defined(this.timeoutid
)) {
53 $clear(this.timeoutid
);
54 this.timeoutid
= null;
59 var r
= new Request
.JSON({url: "/e/s/" + this.sessionid
+ "?t=" + this.counter
++, onComplete: function(o
) {
60 if(this.lastactiverequest
!= r
)
61 this.activerequest
= null;
63 if($defined(this.timeoutid
)) {
64 $clear(this.timeoutid
);
65 this.timeoutid
= null;
69 if(this.lastactiverequest
== r
)
70 this.lastactiverequest
= null;
73 if(!this.disconnected
) {
74 this.disconnected
= true;
76 this.__error("An error occured: " + o
[1]);
81 this.fireEvent("recv", [x
]);
84 if(this.lastactiverequest
== r
) {
85 this.lastactiverequest
= null;
88 if(!this.disconnected
) {
90 this.disconnected
= true;
92 this.__error("Error: the server closed the connection.");
103 if(this.options
.timeout
)
104 this.timeoutid
= this.__timeout
.delay(this.options
.timeout
, this);
106 this.activerequest
= r
;
109 connect: function() {
110 var r
= new Request
.JSON({url: "/e/n?nick=" + encodeURIComponent(this.initialNickname
) + "&r=" + Math
.random() * 1024 * 1024, onComplete: function(o
) {
112 this.disconnected
= true;
113 this.__error("Couldn't connect to remote server.");
117 this.disconnected
= true;
118 this.__error("An error occured: " + o
[1]);
121 this.sessionid
= o
[1];
127 disconnect: function() {
128 this.disconnected
= true;