mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Webclient overhaul (#2735)
Migrate from protobuf.js 5.x to 6.x (remove long.js and bytebuffer.js) Upgrade jQuery from 1.x to 3.x Upgrade jQueryUI to 1.12.x Use minimized version of js libraries Disable debug messages Fix default value for Event_RoomSay’s RoomMessageType field
This commit is contained in:
parent
87060dc5c7
commit
f75caa7245
32 changed files with 73 additions and 38313 deletions
|
|
@ -26,8 +26,6 @@ var WebClient = {
|
|||
keepalive: 5000
|
||||
},
|
||||
|
||||
protobuf : null,
|
||||
builder : null,
|
||||
pb : null,
|
||||
pbfiles : [
|
||||
// commands
|
||||
|
|
@ -53,14 +51,13 @@ var WebClient = {
|
|||
|
||||
initialize : function()
|
||||
{
|
||||
this.protobuf = dcodeIO.ProtoBuf;
|
||||
this.builder = this.protobuf.newBuilder({ convertFieldsToCamelCase: true });
|
||||
|
||||
$.each(this.pbfiles, function(index, fileName) {
|
||||
WebClient.protobuf.loadProtoFile(fileName, WebClient.builder);
|
||||
this.pb = new protobuf.Root({
|
||||
convertFieldsToCamelCase: true,
|
||||
});
|
||||
|
||||
this.pb.load(this.pbfiles, {
|
||||
keepCase: false
|
||||
});
|
||||
|
||||
this.pb = this.builder.build();
|
||||
|
||||
this.initialized=true;
|
||||
},
|
||||
|
|
@ -96,7 +93,7 @@ var WebClient = {
|
|||
this.pendingCommands[this.cmdId] = callback;
|
||||
|
||||
if (this.socket.readyState == WebSocket.OPEN) {
|
||||
this.socket.send(cmd.toArrayBuffer());
|
||||
this.socket.send(WebClient.pb.CommandContainer.encode(cmd).finish());
|
||||
if(this.options.debug)
|
||||
console.log("Sent: " + cmd.toString());
|
||||
} else {
|
||||
|
|
@ -107,7 +104,7 @@ var WebClient = {
|
|||
|
||||
sendRoomCommand : function(roomId, roomCmd, callback)
|
||||
{
|
||||
var cmd = new WebClient.pb.CommandContainer({
|
||||
var cmd = WebClient.pb.CommandContainer.create({
|
||||
"roomId" : roomId,
|
||||
"roomCommand" : [ roomCmd ]
|
||||
});
|
||||
|
|
@ -116,7 +113,7 @@ var WebClient = {
|
|||
|
||||
sendSessionCommand : function(ses, callback)
|
||||
{
|
||||
var cmd = new WebClient.pb.CommandContainer({
|
||||
var cmd = WebClient.pb.CommandContainer.create({
|
||||
"sessionCommand" : [ ses ]
|
||||
});
|
||||
WebClient.sendCommand(cmd, callback);
|
||||
|
|
@ -141,9 +138,9 @@ var WebClient = {
|
|||
}
|
||||
|
||||
// send a ping
|
||||
var CmdPing = new WebClient.pb.Command_Ping();
|
||||
var CmdPing = WebClient.pb.Command_Ping.create();
|
||||
|
||||
var sc = new WebClient.pb.SessionCommand({
|
||||
var sc = WebClient.pb.SessionCommand.create({
|
||||
".Command_Ping.ext" : CmdPing
|
||||
});
|
||||
|
||||
|
|
@ -157,21 +154,26 @@ var WebClient = {
|
|||
|
||||
doLogin : function()
|
||||
{
|
||||
var CmdLogin = new WebClient.pb.Command_Login({
|
||||
var CmdLogin = WebClient.pb.Command_Login.create({
|
||||
"userName" : this.options.user,
|
||||
"password" : this.options.pass,
|
||||
"clientid" : this.guid(),
|
||||
"clientver" : "webclient-0.2 (2016-08-03)",
|
||||
"clientver" : "webclient-0.3 (2017-05-26)",
|
||||
"clientfeatures" : [
|
||||
"client_id",
|
||||
"client_ver",
|
||||
"feature_set",
|
||||
"room_chat_history",
|
||||
"client_warnings"
|
||||
"client_warnings",
|
||||
/* unimplemented features */
|
||||
"forgot_password",
|
||||
"idle_client",
|
||||
"mod_log_lookup",
|
||||
"user_ban_history"
|
||||
]
|
||||
});
|
||||
|
||||
var sc = new WebClient.pb.SessionCommand({
|
||||
var sc = WebClient.pb.SessionCommand.create({
|
||||
".Command_Login.ext" : CmdLogin
|
||||
});
|
||||
|
||||
|
|
@ -227,9 +229,9 @@ var WebClient = {
|
|||
|
||||
doListRooms : function()
|
||||
{
|
||||
var CmdListRooms = new WebClient.pb.Command_ListRooms();
|
||||
var CmdListRooms = WebClient.pb.Command_ListRooms.create();
|
||||
|
||||
var sc = new WebClient.pb.SessionCommand({
|
||||
var sc = WebClient.pb.SessionCommand.create({
|
||||
".Command_ListRooms.ext" : CmdListRooms
|
||||
});
|
||||
|
||||
|
|
@ -289,11 +291,11 @@ var WebClient = {
|
|||
$.each(roomsList, function(index, room) {
|
||||
if(room.autoJoin)
|
||||
{
|
||||
var CmdJoinRoom = new WebClient.pb.Command_JoinRoom({
|
||||
var CmdJoinRoom = WebClient.pb.Command_JoinRoom.create({
|
||||
"roomId" : room.roomId
|
||||
});
|
||||
|
||||
var sc = new WebClient.pb.SessionCommand({
|
||||
var sc = WebClient.pb.SessionCommand.create({
|
||||
".Command_JoinRoom.ext" : CmdJoinRoom
|
||||
});
|
||||
|
||||
|
|
@ -395,19 +397,19 @@ var WebClient = {
|
|||
this.socket.onmessage = function(event) {
|
||||
//console.log("Received " + event.data.byteLength + " bytes");
|
||||
|
||||
var uint8msg = new Uint8Array(event.data);
|
||||
try {
|
||||
var msg = WebClient.pb.ServerMessage.decode(event.data);
|
||||
var msg = WebClient.pb.ServerMessage.decode(uint8msg);
|
||||
if(WebClient.options.debug)
|
||||
console.log(msg);
|
||||
} catch (err) {
|
||||
console.log("Processing failed:", err);
|
||||
if(WebClient.options.debug)
|
||||
{
|
||||
var view = new Uint8Array(event.data);
|
||||
var str = "";
|
||||
for(var i = 0; i < view.length; i++)
|
||||
for(var i = 0; i < uint8msg.length; i++)
|
||||
{
|
||||
str += String.fromCharCode(view[i]);
|
||||
str += String.fromCharCode(uint8msg[i]);
|
||||
}
|
||||
console.log(str);
|
||||
}
|
||||
|
|
@ -442,11 +444,11 @@ var WebClient = {
|
|||
},
|
||||
|
||||
roomSay : function(roomId, msg) {
|
||||
var CmdRoomSay = new WebClient.pb.Command_RoomSay({
|
||||
var CmdRoomSay = WebClient.pb.Command_RoomSay.create({
|
||||
"message" : msg
|
||||
});
|
||||
|
||||
var sc = new WebClient.pb.RoomCommand({
|
||||
var sc = WebClient.pb.RoomCommand.create({
|
||||
".Command_RoomSay.ext" : CmdRoomSay
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue