aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2020-02-19 12:06:37 +0300
committerRblSb <msrblsb@gmail.com>2020-02-19 12:06:37 +0300
commit2ecf9b8d31457175c6cc4ca5a441a165556afb77 (patch)
treeac78bb6e4432d239af3f752972c03c8ef473cadb /build
parent07d1955cefc093ffb12002902ed45e963030746e (diff)
More buttons
Emotes, filters, config, server history, autologin, tab blinking
Diffstat (limited to 'build')
-rw-r--r--build/client.js214
-rw-r--r--build/server.js107
2 files changed, 254 insertions, 67 deletions
diff --git a/build/client.js b/build/client.js
index 9ceba8f..6a6b5f8 100644
--- a/build/client.js
+++ b/build/client.js
@@ -106,6 +106,25 @@ Lambda.find = function(it,f) {
}
return null;
};
+var haxe_ds_StringMap = function() {
+ this.h = { };
+};
+haxe_ds_StringMap.__name__ = true;
+haxe_ds_StringMap.prototype = {
+ setReserved: function(key,value) {
+ if(this.rh == null) {
+ this.rh = { };
+ }
+ this.rh["$" + key] = value;
+ }
+ ,getReserved: function(key) {
+ if(this.rh == null) {
+ return null;
+ } else {
+ return this.rh["$" + key];
+ }
+ }
+};
var Lang = function() { };
Lang.__name__ = true;
Lang.request = function(path,callback) {
@@ -218,14 +237,27 @@ Std.__name__ = true;
Std.string = function(s) {
return js_Boot.__string_rec(s,"");
};
+var StringTools = function() { };
+StringTools.__name__ = true;
+StringTools.startsWith = function(s,start) {
+ if(s.length >= start.length) {
+ return s.lastIndexOf(start,0) == 0;
+ } else {
+ return false;
+ }
+};
+StringTools.replace = function(s,sub,by) {
+ return s.split(sub).join(by);
+};
var client_Main = function(host,port) {
if(port == null) {
port = 4201;
}
- this.pageTitle = window.document.title;
this.onTimeGet = new haxe_Timer(2000);
this.isConnected = false;
this.personalHistoryId = -1;
+ this.filters = [];
+ this.pageTitle = window.document.title;
this.personalHistory = [];
this.clients = [];
var _gthis = this;
@@ -241,6 +273,14 @@ var client_Main = function(host,port) {
_gthis.send({ type : "GetTime"});
return;
};
+ window.document.onvisibilitychange = function() {
+ if(!window.document.hidden && _gthis.onBlinkTab != null) {
+ window.document.title = _gthis.getPageTitle();
+ _gthis.onBlinkTab.stop();
+ _gthis.onBlinkTab = null;
+ }
+ return;
+ };
Lang.init("langs",function() {
_gthis.openWebSocket(host,port);
return;
@@ -273,17 +313,31 @@ client_Main.prototype = {
}
,initListeners: function() {
var _gthis = this;
+ window.document.querySelector("#smilesbtn").onclick = function(e) {
+ var smilesWrap = window.document.querySelector("#smileswrap");
+ if(smilesWrap.style.display == "") {
+ return smilesWrap.style.display = "block";
+ } else {
+ return smilesWrap.style.display = "";
+ }
+ };
var guestName = window.document.querySelector("#guestname");
- guestName.onkeydown = function(e) {
- if(e.keyCode == 13) {
+ guestName.onkeydown = function(e1) {
+ if(guestName.value.length == 0) {
+ return;
+ }
+ if(e1.keyCode == 13) {
_gthis.send({ type : "Login", login : { clientName : guestName.value}});
}
return;
};
var chatLine = window.document.querySelector("#chatline");
- chatLine.onkeydown = function(e1) {
- switch(e1.keyCode) {
+ chatLine.onkeydown = function(e2) {
+ switch(e2.keyCode) {
case 13:
+ if(chatLine.value.length == 0) {
+ return;
+ }
_gthis.send({ type : "Message", message : { clientName : "", text : chatLine.value}});
_gthis.personalHistory.push(chatLine.value);
if(_gthis.personalHistory.length > 50) {
@@ -320,29 +374,33 @@ client_Main.prototype = {
};
client_MobileView.init();
var leaderBtn = window.document.querySelector("#leader_btn");
- leaderBtn.onclick = function(e2) {
+ leaderBtn.onclick = function(e3) {
if(_gthis.personal == null) {
return;
}
- leaderBtn.classList.toggle("label-success");
+ if(!_gthis.personal.isLeader) {
+ leaderBtn.classList.add("label-success");
+ } else {
+ leaderBtn.classList.remove("label-success");
+ }
_gthis.send({ type : "SetLeader", setLeader : { clientName : _gthis.personal.isLeader ? "" : _gthis.personal.name}});
return;
};
- window.document.querySelector("#showmediaurl").onclick = function(e3) {
+ window.document.querySelector("#showmediaurl").onclick = function(e4) {
window.document.querySelector("#showmediaurl").classList.toggle("collapsed");
window.document.querySelector("#showmediaurl").classList.toggle("active");
return window.document.querySelector("#addfromurl").classList.toggle("collapse");
};
- window.document.querySelector("#queue_next").onclick = function(e4) {
+ window.document.querySelector("#queue_next").onclick = function(e5) {
_gthis.addVideoUrl();
return;
};
- window.document.querySelector("#queue_end").onclick = function(e5) {
+ window.document.querySelector("#queue_end").onclick = function(e6) {
_gthis.addVideoUrl();
return;
};
- window.document.querySelector("#mediaurl").onkeydown = function(e6) {
- if(e6.keyCode == 13) {
+ window.document.querySelector("#mediaurl").onkeydown = function(e7) {
+ if(e7.keyCode == 13) {
_gthis.addVideoUrl();
}
};
@@ -371,7 +429,7 @@ client_Main.prototype = {
var video = window.document.createElement("video");
video.src = src;
video.onloadedmetadata = function() {
- haxe_Log.trace(video.duration,{ fileName : "src/client/Main.hx", lineNumber : 162, className : "client.Main", methodName : "getRemoteVideoDuration"});
+ haxe_Log.trace(video.duration,{ fileName : "src/client/Main.hx", lineNumber : 185, className : "client.Main", methodName : "getRemoteVideoDuration"});
player.removeChild(video);
callback(video.duration);
return;
@@ -389,7 +447,7 @@ client_Main.prototype = {
var data = JSON.parse(e.data);
var t = data.type;
var t1 = t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null);
- haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 178, className : "client.Main", methodName : "onMessage", customParams : [data[t1]]});
+ haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 201, className : "client.Main", methodName : "onMessage", customParams : [data[t1]]});
switch(data.type) {
case "AddVideo":
if(this.player.isListEmpty()) {
@@ -398,6 +456,7 @@ client_Main.prototype = {
this.player.addVideoItem(data.addVideo.item);
break;
case "Connected":
+ this.setConfig(data.connected.config);
if(data.connected.isUnknownClient) {
this.updateClients(data.connected.clients);
window.document.querySelector("#guestlogin").style.display = "block";
@@ -405,16 +464,27 @@ client_Main.prototype = {
} else {
this.onLogin(data.connected.clients,data.connected.clientName);
}
+ var guestName = window.document.querySelector("#guestname");
+ if(guestName.value.length > 0) {
+ this.send({ type : "Login", login : { clientName : guestName.value}});
+ }
+ var _g = 0;
+ var _g1 = data.connected.history;
+ while(_g < _g1.length) {
+ var message = _g1[_g];
+ ++_g;
+ this.addMessage(message.name,message.text,message.time);
+ }
var list = data.connected.videoList;
if(list.length == 0) {
return;
}
this.player.setVideo(list[0]);
- var _g = 0;
- var _g1 = data.connected.videoList;
- while(_g < _g1.length) {
- var video = _g1[_g];
- ++_g;
+ var _g2 = 0;
+ var _g3 = data.connected.videoList;
+ while(_g2 < _g3.length) {
+ var video = _g3[_g2];
+ ++_g2;
this.player.addVideoItem(video);
}
break;
@@ -433,7 +503,8 @@ client_Main.prototype = {
this.onLogin(data.login.clients,data.login.clientName);
break;
case "LoginError":
- this.serverMessage(4,Lang.get("usernameError"));
+ var text = StringTools.replace(Lang.get("usernameError"),"$MAX","" + this.config.maxLoginLength);
+ this.serverMessage(4,text);
break;
case "Logout":
this.updateClients(data.logout.clients);
@@ -491,6 +562,47 @@ client_Main.prototype = {
break;
}
}
+ ,setConfig: function(config) {
+ this.config = config;
+ this.pageTitle = config.channelName;
+ window.document.querySelector("#guestname").maxLength = config.maxLoginLength;
+ window.document.querySelector("#chatline").maxLength = config.maxMessageLength;
+ this.filters.length = 0;
+ var _g = 0;
+ var _g1 = config.filters;
+ while(_g < _g1.length) {
+ var filter = _g1[_g];
+ ++_g;
+ this.filters.push({ regex : new EReg(filter.regex,filter.flags), replace : filter.replace});
+ }
+ var _g2 = 0;
+ var _g3 = config.emotes;
+ while(_g2 < _g3.length) {
+ var emote = _g3[_g2];
+ ++_g2;
+ this.filters.push({ regex : new EReg(this.escapeRegExp(emote.name),"g"), replace : "<img class=\"channel-emote\" src=\"" + emote.image + "\" title=\"" + emote.name + "\"/>"});
+ }
+ var smilesWrap = window.document.querySelector("#smileswrap");
+ smilesWrap.onclick = function(e) {
+ var el = e.target;
+ var form = window.document.querySelector("#chatline");
+ form.value += " " + el.title;
+ form.focus();
+ return;
+ };
+ smilesWrap.innerHTML = "";
+ var _g4 = 0;
+ var _g5 = config.emotes;
+ while(_g4 < _g5.length) {
+ var emote1 = _g5[_g4];
+ ++_g4;
+ var img = window.document.createElement("img");
+ img.className = "smile-preview";
+ img.src = emote1.image;
+ img.title = emote1.name;
+ smilesWrap.appendChild(img);
+ }
+ }
,onLogin: function(data,clientName) {
this.updateClients(data);
this.personal = ClientTools.getByName(this.clients,clientName);
@@ -540,7 +652,7 @@ client_Main.prototype = {
}
,updateUserList: function() {
window.document.querySelector("#usercount").innerHTML = this.clients.length + " " + Lang.get("online");
- window.document.title = "" + this.pageTitle + " (" + this.clients.length + ")";
+ window.document.title = this.getPageTitle();
var list_b = "";
var _g = 0;
var _g1 = this.clients;
@@ -554,26 +666,59 @@ client_Main.prototype = {
}
window.document.querySelector("#userlist").innerHTML = list_b;
}
- ,addMessage: function(name,msg) {
+ ,getPageTitle: function() {
+ return "" + this.pageTitle + " (" + this.clients.length + ")";
+ }
+ ,addMessage: function(name,text,time) {
+ var _gthis = this;
var msgBuf = window.document.querySelector("#messagebuffer");
var userDiv = window.document.createElement("div");
userDiv.className = "chat-msg-" + name;
var tstamp = window.document.createElement("span");
tstamp.className = "timestamp";
- tstamp.innerHTML = "[" + new Date().toTimeString().split(" ")[0] + "] ";
+ if(time == null) {
+ time = "[" + new Date().toTimeString().split(" ")[0] + "] ";
+ }
+ tstamp.innerHTML = time;
var nameDiv = window.document.createElement("strong");
nameDiv.className = "username";
nameDiv.innerHTML = name + ": ";
var textDiv = window.document.createElement("span");
- textDiv.innerHTML = msg;
+ var _g = 0;
+ var _g1 = this.filters;
+ while(_g < _g1.length) {
+ var filter = _g1[_g];
+ ++_g;
+ text = text.replace(filter.regex.r,filter.replace);
+ }
+ textDiv.innerHTML = text;
var isInChatEnd = msgBuf.scrollHeight - msgBuf.scrollTop == msgBuf.clientHeight;
userDiv.appendChild(tstamp);
userDiv.appendChild(nameDiv);
userDiv.appendChild(textDiv);
msgBuf.appendChild(userDiv);
if(isInChatEnd) {
+ while(msgBuf.children.length > 200) msgBuf.removeChild(msgBuf.firstChild);
+ msgBuf.scrollTop = msgBuf.scrollHeight;
+ }
+ if(this.personal != null && this.personal.name == name) {
msgBuf.scrollTop = msgBuf.scrollHeight;
}
+ if(window.document.hidden && this.onBlinkTab == null) {
+ this.onBlinkTab = new haxe_Timer(1000);
+ this.onBlinkTab.run = function() {
+ if(StringTools.startsWith(window.document.title,_gthis.pageTitle)) {
+ return window.document.title = "*Chat*";
+ } else {
+ return window.document.title = _gthis.getPageTitle();
+ }
+ };
+ this.onBlinkTab.run();
+ }
+ }
+ ,escapeRegExp: function(regex) {
+ var _this_r = new RegExp("([.*+?^${}()|[\\]\\\\])","g".split("u").join(""));
+ return regex.replace(_this_r,"\\$1");
}
};
var client_MobileView = function() { };
@@ -822,25 +967,6 @@ haxe_Timer.prototype = {
,run: function() {
}
};
-var haxe_ds_StringMap = function() {
- this.h = { };
-};
-haxe_ds_StringMap.__name__ = true;
-haxe_ds_StringMap.prototype = {
- setReserved: function(key,value) {
- if(this.rh == null) {
- this.rh = { };
- }
- this.rh["$" + key] = value;
- }
- ,getReserved: function(key) {
- if(this.rh == null) {
- return null;
- } else {
- return this.rh["$" + key];
- }
- }
-};
var haxe_http_HttpBase = function(url) {
this.url = url;
this.headers = [];
@@ -1225,10 +1351,10 @@ js_Browser.createXMLHttpRequest = function() {
function $getIterator(o) { if( o instanceof Array ) return HxOverrides.iter(o); else return o.iterator(); }
function $bind(o,m) { if( m == null ) return null; if( m.__id__ == null ) m.__id__ = $global.$haxeUID++; var f; if( o.hx__closures__ == null ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == null ) { f = m.bind(o); o.hx__closures__[m.__id__] = f; } return f; }
$global.$haxeUID |= 0;
+var __map_reserved = {};
if( String.fromCodePoint == null ) String.fromCodePoint = function(c) { return c < 0x10000 ? String.fromCharCode(c) : String.fromCharCode((c>>10)+0xD7C0)+String.fromCharCode((c&0x3FF)+0xDC00); }
String.__name__ = true;
Array.__name__ = true;
-var __map_reserved = {};
Object.defineProperty(js__$Boot_HaxeError.prototype,"message",{ get : function() {
return String(this.val);
}});
diff --git a/build/server.js b/build/server.js
index 49e666c..14869f0 100644
--- a/build/server.js
+++ b/build/server.js
@@ -456,9 +456,9 @@ js_Boot.__string_rec = function(o,s) {
return String(o);
}
};
-var js_node_Dns = require("dns");
var js_node_Fs = require("fs");
var js_node_Http = require("http");
+var js_node_Os = require("os");
var js_node_Path = require("path");
var js_npm_ws_Server = require("ws").Server;
var server_HttpServer = function() { };
@@ -537,9 +537,12 @@ var server_Main = function(port,wsPort) {
port = 4200;
}
this.loadedClientsCount = 0;
+ this.messages = [];
this.videoTimer = new server_VideoTimer();
this.videoList = [];
this.clients = [];
+ this.rootDir = "" + __dirname + "/..";
+ this.config = this.getUserConfig();
this.wss = new js_npm_ws_Server({ port : wsPort});
this.wss.on("connection",$bind(this,this.onConnect));
var exit = function() {
@@ -548,19 +551,19 @@ var server_Main = function(port,wsPort) {
process.on("exit",exit);
process.on("SIGINT",exit);
process.on("uncaughtException",function(log) {
- haxe_Log.trace(log,{ fileName : "src/server/Main.hx", lineNumber : 34, className : "server.Main", methodName : "new"});
+ haxe_Log.trace(log,{ fileName : "src/server/Main.hx", lineNumber : 40, className : "server.Main", methodName : "new"});
return;
});
process.on("unhandledRejection",function(reason,promise) {
- haxe_Log.trace("Unhandled Rejection at:",{ fileName : "src/server/Main.hx", lineNumber : 37, className : "server.Main", methodName : "new", customParams : [reason]});
+ haxe_Log.trace("Unhandled Rejection at:",{ fileName : "src/server/Main.hx", lineNumber : 43, className : "server.Main", methodName : "new", customParams : [reason]});
return;
});
- this.getPublicIp(function(ip) {
- haxe_Log.trace("Local: http://127.0.0.1:" + port,{ fileName : "src/server/Main.hx", lineNumber : 41, className : "server.Main", methodName : "new"});
- haxe_Log.trace("Global: http://" + ip + ":" + port,{ fileName : "src/server/Main.hx", lineNumber : 42, className : "server.Main", methodName : "new"});
+ server_Utils.getGlobalIp(function(ip) {
+ haxe_Log.trace("Local: http://" + server_Utils.getLocalIp() + ":" + port,{ fileName : "src/server/Main.hx", lineNumber : 48, className : "server.Main", methodName : "new"});
+ haxe_Log.trace("Global: http://" + ip + ":" + port,{ fileName : "src/server/Main.hx", lineNumber : 49, className : "server.Main", methodName : "new"});
return;
});
- var dir = "" + __dirname + "/../res";
+ var dir = "" + this.rootDir + "/res";
server_HttpServer.init(dir);
Lang.init("" + dir + "/langs");
js_node_Http.createServer(function(req,res) {
@@ -573,37 +576,46 @@ server_Main.main = function() {
new server_Main();
};
server_Main.prototype = {
- getPublicIp: function(callback) {
- js_node_Dns.resolve("google.com",function(err,arr) {
- if(err != null) {
- callback("ERROR " + err.code);
- return;
+ getUserConfig: function() {
+ var config = JSON.parse(js_node_Fs.readFileSync("" + this.rootDir + "/default-config.json",{ encoding : "utf8"}));
+ var customPath = "" + this.rootDir + "/config.json";
+ if(!sys_FileSystem.exists(customPath)) {
+ return config;
+ }
+ var customConfig = JSON.parse(js_node_Fs.readFileSync(customPath,{ encoding : "utf8"}));
+ var _g = 0;
+ var _g1 = Reflect.fields(customConfig);
+ while(_g < _g1.length) {
+ var field = _g1[_g];
+ ++_g;
+ if(Reflect.field(config,field) == null) {
+ haxe_Log.trace("Warning: config field \"" + field + "\" is unknown",{ fileName : "src/server/Main.hx", lineNumber : 67, className : "server.Main", methodName : "getUserConfig"});
}
- js_node_Http.get("http://myexternalip.com/raw",function(r) {
- r.setEncoding("utf8");
- return r.on("data",callback);
- });
- });
+ config[field] = Reflect.field(customConfig,field);
+ }
+ return config;
}
,onConnect: function(ws,req) {
var _gthis = this;
- haxe_Log.trace("Client connected (" + req.connection.remoteAddress + ")",{ fileName : "src/server/Main.hx", lineNumber : 69, className : "server.Main", methodName : "onConnect"});
+ haxe_Log.trace("Client connected (" + req.connection.remoteAddress + ")",{ fileName : "src/server/Main.hx", lineNumber : 75, className : "server.Main", methodName : "onConnect"});
var client = new Client(ws,"Unknown",false);
this.clients.push(client);
+ var tmp = this.config;
+ var tmp1 = this.messages;
var client1 = client.name;
var _g = [];
var _g1 = 0;
var _g2 = this.clients;
while(_g1 < _g2.length) _g.push(_g2[_g1++].getData());
- this.send(client,{ type : "Connected", connected : { isUnknownClient : true, clientName : client1, clients : _g, videoList : this.videoList}});
+ this.send(client,{ type : "Connected", connected : { config : tmp, history : tmp1, isUnknownClient : true, clientName : client1, clients : _g, videoList : this.videoList}});
this.sendClientList();
ws.on("message",function(data) {
- var tmp = JSON.parse(data);
- _gthis.onMessage(client,tmp);
+ var tmp2 = JSON.parse(data);
+ _gthis.onMessage(client,tmp2);
return;
});
ws.on("close",function(err) {
- haxe_Log.trace("Client " + client.name + " disconnected",{ fileName : "src/server/Main.hx", lineNumber : 90, className : "server.Main", methodName : "onConnect"});
+ haxe_Log.trace("Client " + client.name + " disconnected",{ fileName : "src/server/Main.hx", lineNumber : 98, className : "server.Main", methodName : "onConnect"});
HxOverrides.remove(_gthis.clients,client);
_gthis.sendClientList();
if(client.isLeader) {
@@ -638,7 +650,7 @@ server_Main.prototype = {
break;
case "Login":
var name = data.login.clientName;
- if(name.length == 0 || name.length > 20 || ClientTools.getByName(this.clients,name) != null) {
+ if(name.length == 0 || name.length > this.config.maxLoginLength || ClientTools.getByName(this.clients,name) != null) {
this.send(client,{ type : "LoginError"});
return;
}
@@ -655,7 +667,20 @@ server_Main.prototype = {
this.sendClientList();
break;
case "Message":
+ var text = data.message.text;
+ if(text.length == 0) {
+ return;
+ }
+ if(text.length > this.config.maxMessageLength) {
+ text = HxOverrides.substr(text,0,this.config.maxMessageLength);
+ }
+ data.message.text = text;
data.message.clientName = client.name;
+ var time = "[" + new Date().toTimeString().split(" ")[0] + "] ";
+ this.messages.push({ text : text, name : client.name, time : time});
+ if(this.messages.length > this.config.serverChatHistory) {
+ this.messages.pop();
+ }
this.broadcast(data);
break;
case "Pause":
@@ -775,6 +800,32 @@ server_Main.prototype = {
this.videoTimer.start();
}
};
+var server_Utils = function() { };
+server_Utils.__name__ = true;
+server_Utils.getGlobalIp = function(callback) {
+ js_node_Http.get("http://myexternalip.com/raw",function(r) {
+ r.setEncoding("utf8");
+ return r.on("data",callback);
+ });
+};
+server_Utils.getLocalIp = function() {
+ var ifaces = js_node_Os.networkInterfaces();
+ var _g = 0;
+ var _g1 = Reflect.fields(ifaces);
+ while(_g < _g1.length) {
+ var type = Reflect.field(ifaces,_g1[_g++]);
+ var _g2 = 0;
+ var _g11 = Reflect.fields(type);
+ while(_g2 < _g11.length) {
+ var iface = Reflect.field(type,_g11[_g2++]);
+ if("IPv4" != iface.family || iface.internal != false) {
+ continue;
+ }
+ return iface.address;
+ }
+ }
+ return "127.0.0.1";
+};
var server_VideoTimer = function() {
this.pauseStartTime = 0.0;
this.startTime = 0.0;
@@ -824,6 +875,16 @@ server_VideoTimer.prototype = {
return Date.now() / 1000 - this.pauseStartTime;
}
};
+var sys_FileSystem = function() { };
+sys_FileSystem.__name__ = true;
+sys_FileSystem.exists = function(path) {
+ try {
+ js_node_Fs.accessSync(path);
+ return true;
+ } catch( _ ) {
+ return false;
+ }
+};
function $getIterator(o) { if( o instanceof Array ) return HxOverrides.iter(o); else return o.iterator(); }
var $_;
function $bind(o,m) { if( m == null ) return null; if( m.__id__ == null ) m.__id__ = $global.$haxeUID++; var f; if( o.hx__closures__ == null ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == null ) { f = m.bind(o); o.hx__closures__[m.__id__] = f; } return f; }
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage