Skip to content

Commit a07bb68

Browse files
committed
Issue #37 Added handler for websocket onerror function
1 parent 05eb20b commit a07bb68

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

jetclient-js/src/jet-0.1.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,22 @@
134134
dispatch(jet.DISCONNECT,e);
135135
};
136136

137+
ws.onerror = function (e){
138+
state = 2;
139+
dispatch(jet.EXCEPTION,e);
140+
};
141+
137142
me.addHandler = function(eventName, callback){
138143
callbacks[eventName] = callbacks[eventName] || [];
139144
callbacks[eventName].push(callback);
140145
return me;// chainable
141146
};
142147

143-
me.send = function(aEvt){
148+
me.send = function(evt){
144149
if(state != 1){
145150
throw new Error("Session is not in connected state");
146151
}
147-
var payload = me.outCodecChain.transform(aEvt);
152+
var payload = me.outCodecChain.transform(evt);
148153
ws.send( payload ); // <= send JSON/Binary data to socket server
149154
return me;
150155
};
@@ -170,15 +175,15 @@
170175
ws.close();
171176
};
172177

173-
function dispatch(eventName, message){
174-
dispatchToEventHandlers(callback[jet.ANY],message);
175-
dispatchToEventHandlers(callbacks[eventName],message);
178+
function dispatch(eventName, evt){
179+
dispatchToEventHandlers(callback[jet.ANY], evt);
180+
dispatchToEventHandlers(callbacks[eventName], evt);
176181
}
177182

178-
function dispatchToEventHandlers(chain, message){
183+
function dispatchToEventHandlers(chain, evt){
179184
if(typeof chain === 'undefined') return; // no callbacks for this event
180185
for(var i = 0; i < chain.length; i++){
181-
chain[i]( message );
186+
chain[i]( evt );
182187
}
183188
}
184189

0 commit comments

Comments
 (0)