Skip to content

Commit 400626f

Browse files
authored
Merge pull request #774 from Marssssssss/v2.1.4-release
Add more messages for websocket and xhr events states displaying
2 parents 01eca90 + 8579456 commit 400626f

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

assets/cases/05_scripting/11_network/NetworkCtrl.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ cc.Class({
107107
this._wsiSendBinary.binaryType = "arraybuffer";
108108
this._wsiSendBinary.onopen = function(evt) {
109109
websocketLabel.textKey = i18n.t("cases/05_scripting/11_network/NetworkCtrl.js.5");
110+
respLabel.string = "Opened!";
110111
};
111112

112113
this._wsiSendBinary.onmessage = function(evt) {
@@ -133,13 +134,15 @@ cc.Class({
133134

134135
this._wsiSendBinary.onerror = function(evt) {
135136
websocketLabel.textKey = i18n.t("cases/05_scripting/11_network/NetworkCtrl.js.7");
137+
respLabel.string = "Error!";
136138
};
137139

138140
this._wsiSendBinary.onclose = function(evt) {
139141
websocketLabel.textKey = i18n.t("cases/05_scripting/11_network/NetworkCtrl.js.8");
140142
// After close, it's no longer possible to use it again,
141143
// if you want to send another request, you need to create a new websocket instance
142144
self._wsiSendBinary = null;
145+
respLabel.string = "Close!";
143146
};
144147

145148
this.scheduleOnce(this.sendWebSocketBinary, 1);
@@ -189,6 +192,7 @@ cc.Class({
189192

190193
var msg = this.tag + " disconnected!";
191194
this.socketIO.textKey = i18n.t("cases/05_scripting/11_network/NetworkCtrl.js.12") + msg;
195+
this.socketIOResp.string = msg;
192196
},
193197

194198
reconnecting: function () {
@@ -254,7 +258,12 @@ cc.Class({
254258
xhr["on" + eventname] = function () {
255259
eventLabel.string = eventLabelOrigin + "\nEvent : " + eventname;
256260
if (eventname === 'timeout') {
257-
label.string = '(timeout)';
261+
label.string += '(timeout)';
262+
}
263+
else if (eventname === 'loadend') {
264+
if (eventname !== '(timeout)') {
265+
label.string += '...loadend!';
266+
}
258267
}
259268
};
260269
});
@@ -264,6 +273,21 @@ cc.Class({
264273
if (xhr.readyState === 4 && xhr.status >= 200) {
265274
label.string = handler(xhr.responseText);
266275
}
276+
else if (xhr.status === 404) {
277+
label.string = "404 page not found!"
278+
}
279+
else if (xhr.readyState === 3) {
280+
label.string = "Request dealing!";
281+
}
282+
else if (xhr.readyState === 2) {
283+
label.string = "Request received!";
284+
}
285+
else if (xhr.readyState === 1) {
286+
label.string = "Server connection established! Request hasn't been received";
287+
}
288+
else if (xhr.readyState === 0) {
289+
label.string = "Request hasn't been initiated!";
290+
}
267291
};
268292
},
269293

0 commit comments

Comments
 (0)