conn.onmessage = function(evt) {
var data = JSON.parse(evt.data);
switch(data.MType) {
case "text_mtype":
addMessage(data.TextMessage)
break;
case "status_mtype":
updateUsers(data.UserStatus)
break;
default:
}
};
conn.onerror = function() {
errorMessage(" An error just occured.")
};
conn.onclose = function() {
errorMessage("Connection closed.")
};
} else {
errorMessage("Your browser does not support WebSockets.");
}
如果你对这个应用很感兴趣,你可以从这里获取整个应用的源码:gochatting.
