beta 5 - breaking changes
some things considered Channel_OnTypeChanged optional, grr. Make fourCC a thing so people don't manage to get the wrong channel for their activities and then break stuff
This commit is contained in:
parent
3770586592
commit
1a730fdb64
|
@ -1,2 +1,3 @@
|
||||||
tmp/*
|
tmp/*
|
||||||
node_modules/*
|
node_modules/*
|
||||||
|
*.bak
|
||||||
|
|
26
client.js
26
client.js
|
@ -10,6 +10,12 @@ const __messengerjs__ = {
|
||||||
__messengerjs__.fade = document.createElement("div");
|
__messengerjs__.fade = document.createElement("div");
|
||||||
__messengerjs__.fade.style.cssText = "position: absolute;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.75);color:white;text-align:center;font-family:sans-serif;";
|
__messengerjs__.fade.style.cssText = "position: absolute;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.75);color:white;text-align:center;font-family:sans-serif;";
|
||||||
__messengerjs__.fade.textContent = "connecting to WebSocket server...";
|
__messengerjs__.fade.textContent = "connecting to WebSocket server...";
|
||||||
|
__messengerjs__.callIfExists = function(fnName) {
|
||||||
|
// THIS function exists because some of the events we call may not exist on the client... why?
|
||||||
|
if(typeof window[fnName] === "function") {
|
||||||
|
window[fnName]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const beforeUnloadHandler = function(ev) {
|
const beforeUnloadHandler = function(ev) {
|
||||||
Channel_OnAppClose();
|
Channel_OnAppClose();
|
||||||
|
@ -84,8 +90,8 @@ window.external.Channel = {"Data": "", "SendData": null, "Initialize": null, "Er
|
||||||
// things may want Channel.IM: string and Channel.FileInfo: object {Path: string, Size: number, Progress: number<0-100>, Incoming: bool, Status: num<0-3>}
|
// things may want Channel.IM: string and Channel.FileInfo: object {Path: string, Size: number, Progress: number<0-100>, Incoming: bool, Status: num<0-3>}
|
||||||
window.external.Channel.SendData = function(d) {channelSocket.send(d)}; // this is dumb but trying to redirect this gives you TypeError's
|
window.external.Channel.SendData = function(d) {channelSocket.send(d)}; // this is dumb but trying to redirect this gives you TypeError's
|
||||||
window.external.Channel.Initialize = function() {
|
window.external.Channel.Initialize = function() {
|
||||||
// no idea we're already pretty initalized by the time most things call this
|
// no idea we're already pretty initalized by the time most things call
|
||||||
Channel_OnTypeChanged(); // make client check if its even connected still
|
__messengerjs__.callIfExists("Channel_OnTypeChanged"); // make client check if its even connected still
|
||||||
};
|
};
|
||||||
Object.defineProperty(window.external.Channel, "Type", {
|
Object.defineProperty(window.external.Channel, "Type", {
|
||||||
get: function Type() {
|
get: function Type() {
|
||||||
|
@ -165,7 +171,7 @@ channelSocket.onmessage = function(event) {
|
||||||
__messengerjs__.fade.textContent = "the channel server was closed. please try again later.";
|
__messengerjs__.fade.textContent = "the channel server was closed. please try again later.";
|
||||||
__messengerjs__.fade.style.display = "block";
|
__messengerjs__.fade.style.display = "block";
|
||||||
channelSocket.close(1000, "server shutdown acknoledged.");
|
channelSocket.close(1000, "server shutdown acknoledged.");
|
||||||
Channel_OnTypeChanged();
|
__messengerjs__.callIfExists("Channel_OnTypeChanged");
|
||||||
Channel_OnRemoteAppClosed(); // they're gone
|
Channel_OnRemoteAppClosed(); // they're gone
|
||||||
Channel_OnAppClose(); // we're gone too
|
Channel_OnAppClose(); // we're gone too
|
||||||
break;
|
break;
|
||||||
|
@ -174,15 +180,15 @@ channelSocket.onmessage = function(event) {
|
||||||
console.warn("channel was full, generating new room");
|
console.warn("channel was full, generating new room");
|
||||||
__messengerjs__.sessionID = Math.random().toString(36).split('.')[1].substring(0,8);
|
__messengerjs__.sessionID = Math.random().toString(36).split('.')[1].substring(0,8);
|
||||||
history.pushState(null, "", `#channel=${__messengerjs__.sessionID}`);
|
history.pushState(null, "", `#channel=${__messengerjs__.sessionID}`);
|
||||||
channelSocket.send(new TextEncoder("utf8").encode(EncodeCommandString(["connect", __messengerjs__.sessionID])));
|
channelSocket.send(new TextEncoder("utf8").encode(EncodeCommandString(["connect", __messengerjs__.sessionID, window.GameCode])));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
__messengerjs__.fade.textContent = "server error:" + args[1] + "code (" + args[2] + ")";
|
__messengerjs__.fade.textContent = "server error:" + args[1] + "code (" + args[2] + ")";
|
||||||
__messengerjs__.fade.style.display = "block";
|
__messengerjs__.fade.style.display = "block";
|
||||||
channelSocket.close(1000, "server sent non-zero error");
|
channelSocket.close(1000, "server sent non-zero error");
|
||||||
Channel_OnTypeChanged();
|
__messengerjs__.callIfExists("Channel_OnTypeChanged");
|
||||||
Channel_OnDataError(); // this may just attempt to retry to send the failed data... when we're already closed;
|
__messengerjs__.callIfExists("Channel_OnDataError"); // this may just attempt to retry to send the failed data... when we're already closed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -209,7 +215,7 @@ channelSocket.onmessage = function(event) {
|
||||||
__messengerjs__.onloadfunction(__messengerjs__.onloadargs);
|
__messengerjs__.onloadfunction(__messengerjs__.onloadargs);
|
||||||
}
|
}
|
||||||
Channel_OnRemoteAppLoaded();
|
Channel_OnRemoteAppLoaded();
|
||||||
Channel_OnTypeChanged();
|
__messengerjs__.callIfExists("Channel_OnTypeChanged");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "remuser": {
|
case "remuser": {
|
||||||
|
@ -240,18 +246,18 @@ channelSocket.onerror = function(ev) {
|
||||||
Channel_OnDataError();
|
Channel_OnDataError();
|
||||||
}
|
}
|
||||||
channelSocket.onclose = function() {
|
channelSocket.onclose = function() {
|
||||||
Channel_OnTypeChanged();
|
__messengerjs__.callIfExists("Channel_OnTypeChanged");
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWSEventsNowThatImReady() {
|
function createWSEventsNowThatImReady() {
|
||||||
if(channelSocket.readyState === 1) {
|
if(channelSocket.readyState === 1) {
|
||||||
// if we're already there
|
// if we're already there
|
||||||
channelSocket.send(new TextEncoder("utf8").encode(EncodeCommandString(["rename"])));
|
channelSocket.send(new TextEncoder("utf8").encode(EncodeCommandString(["rename"])));
|
||||||
channelSocket.send(new TextEncoder("utf8").encode(EncodeCommandString(["connect", __messengerjs__.sessionID])));
|
channelSocket.send(new TextEncoder("utf8").encode(EncodeCommandString(["connect", __messengerjs__.sessionID, window.GameCode])));
|
||||||
}
|
}
|
||||||
channelSocket.onopen = function() {
|
channelSocket.onopen = function() {
|
||||||
channelSocket.send(new TextEncoder("utf8").encode(EncodeCommandString(["rename"])));
|
channelSocket.send(new TextEncoder("utf8").encode(EncodeCommandString(["rename"])));
|
||||||
channelSocket.send(new TextEncoder("utf8").encode(EncodeCommandString(["connect", __messengerjs__.sessionID])));
|
channelSocket.send(new TextEncoder("utf8").encode(EncodeCommandString(["connect", __messengerjs__.sessionID, window.GameCode])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** pure evil **/
|
/** pure evil **/
|
||||||
|
|
10
server.js
10
server.js
|
@ -87,7 +87,7 @@ const MessageParser = function(webSocket, message, isBinary) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "connect": {
|
case "connect": {
|
||||||
if(args.length <= 1) {
|
if(args.length <= 2) {
|
||||||
webSocket.send(EncodeCommandString(["error", "need more arguments", 768]), true);
|
webSocket.send(EncodeCommandString(["error", "need more arguments", 768]), true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,14 @@ const MessageParser = function(webSocket, message, isBinary) {
|
||||||
if(ChannelStorage.has(getChannelId) === false) {
|
if(ChannelStorage.has(getChannelId) === false) {
|
||||||
// make the channel right then and there
|
// make the channel right then and there
|
||||||
console.log(`creating #${getChannelId} for (${webSocket.getUserData().uid})`);
|
console.log(`creating #${getChannelId} for (${webSocket.getUserData().uid})`);
|
||||||
ChannelStorage.set(getChannelId, {"owner": webSocket.getUserData().uid});
|
ChannelStorage.set(getChannelId, {"owner": webSocket.getUserData().uid, "fourCC": args[2]});
|
||||||
};
|
};
|
||||||
|
if(ChannelStorage.get(getChannelId).fourCC !== args[2]) {
|
||||||
|
// if the fourCC is not the same as the channel, error as such
|
||||||
|
webSocket.send(EncodeCommandString(["error", `data is incompatible! (You: ${args[2]}, Remote: ${ChannelStorage.get(getChannelId).fourCC}.`, 256]), true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
if(webSocket.isSubscribed(`channels/${getChannelId}`) === true) {
|
if(webSocket.isSubscribed(`channels/${getChannelId}`) === true) {
|
||||||
// already in this channel
|
// already in this channel
|
||||||
webSocket.send(EncodeCommandString(["error", "already in this channel", 517]), true);
|
webSocket.send(EncodeCommandString(["error", "already in this channel", 517]), true);
|
||||||
|
|
Loading…
Reference in New Issue