// Generated by Haxe 4.0.5 (function ($global) { "use strict"; var $estr = function() { return js_Boot.__string_rec(this,''); },$hxEnums = $hxEnums || {},$_; function $extend(from, fields) { var proto = Object.create(from); for (var name in fields) proto[name] = fields[name]; if( fields.toString !== Object.prototype.toString ) proto.toString = fields.toString; return proto; } var ClientGroup = $hxEnums["ClientGroup"] = { __ename__ : true, __constructs__ : ["User","Leader","Admin"] ,User: {_hx_index:0,__enum__:"ClientGroup",toString:$estr} ,Leader: {_hx_index:1,__enum__:"ClientGroup",toString:$estr} ,Admin: {_hx_index:2,__enum__:"ClientGroup",toString:$estr} }; var Client = function(ws,req,id,name,group) { this.ws = ws; this.req = req; this.id = id; this.name = name; var i = group; if(group == null) { i = 0; } this.group = i; }; Client.__name__ = true; Client.prototype = { setGroupFlag: function(type,flag) { if(flag) { this.group |= 1 << type._hx_index; } else { this.group &= -1 - (1 << type._hx_index); } return flag; } ,getData: function() { return { name : this.name, group : this.group}; } }; var ClientTools = function() { }; ClientTools.__name__ = true; ClientTools.setLeader = function(clients,name) { var _g = 0; while(_g < clients.length) { var client = clients[_g]; ++_g; if(client.name == name) { client.setGroupFlag(ClientGroup.Leader,true); } else if((client.group & 2) != 0) { client.setGroupFlag(ClientGroup.Leader,false); } } }; ClientTools.hasLeader = function(clients) { var _g = 0; while(_g < clients.length) if((clients[_g++].group & 2) != 0) { return true; } return false; }; ClientTools.getByName = function(clients,name,def) { var _g = 0; while(_g < clients.length) { var client = clients[_g]; ++_g; if(client.name == name) { return client; } } return def; }; var DateTools = function() { }; DateTools.__name__ = true; DateTools.__format_get = function(d,e) { switch(e) { case "%": return "%"; case "A": return DateTools.DAY_NAMES[d.getDay()]; case "B": return DateTools.MONTH_NAMES[d.getMonth()]; case "C": return StringTools.lpad(Std.string(d.getFullYear() / 100 | 0),"0",2); case "D": return DateTools.__format(d,"%m/%d/%y"); case "F": return DateTools.__format(d,"%Y-%m-%d"); case "I":case "l": var hour = d.getHours() % 12; return StringTools.lpad(Std.string(hour == 0 ? 12 : hour),e == "I" ? "0" : " ",2); case "M": return StringTools.lpad(Std.string(d.getMinutes()),"0",2); case "R": return DateTools.__format(d,"%H:%M"); case "S": return StringTools.lpad(Std.string(d.getSeconds()),"0",2); case "T": return DateTools.__format(d,"%H:%M:%S"); case "Y": return Std.string(d.getFullYear()); case "a": return DateTools.DAY_SHORT_NAMES[d.getDay()]; case "b":case "h": return DateTools.MONTH_SHORT_NAMES[d.getMonth()]; case "d": return StringTools.lpad(Std.string(d.getDate()),"0",2); case "e": return Std.string(d.getDate()); case "H":case "k": return StringTools.lpad(Std.string(d.getHours()),e == "H" ? "0" : " ",2); case "m": return StringTools.lpad(Std.string(d.getMonth() + 1),"0",2); case "n": return "\n"; case "p": if(d.getHours() > 11) { return "PM"; } else { return "AM"; } break; case "r": return DateTools.__format(d,"%I:%M:%S %p"); case "s": return Std.string(d.getTime() / 1000 | 0); case "t": return "\t"; case "u": var t = d.getDay(); if(t == 0) { return "7"; } else if(t == null) { return "null"; } else { return "" + t; } break; case "w": return Std.string(d.getDay()); case "y": return StringTools.lpad(Std.string(d.getFullYear() % 100),"0",2); default: throw new js__$Boot_HaxeError("Date.format %" + e + "- not implemented yet."); } }; DateTools.__format = function(d,f) { var r_b = ""; var p = 0; while(true) { var np = f.indexOf("%",p); if(np < 0) { break; } var len = np - p; r_b += len == null ? HxOverrides.substr(f,p,null) : HxOverrides.substr(f,p,len); r_b += Std.string(DateTools.__format_get(d,HxOverrides.substr(f,np + 1,1))); p = np + 2; } var len1 = f.length - p; r_b += len1 == null ? HxOverrides.substr(f,p,null) : HxOverrides.substr(f,p,len1); return r_b; }; DateTools.format = function(d,f) { return DateTools.__format(d,f); }; var EReg = function(r,opt) { this.r = new RegExp(r,opt.split("u").join("")); }; EReg.__name__ = true; EReg.prototype = { match: function(s) { if(this.r.global) { this.r.lastIndex = 0; } this.r.m = this.r.exec(s); this.r.s = s; return this.r.m != null; } ,matched: function(n) { if(this.r.m != null && n >= 0 && n < this.r.m.length) { return this.r.m[n]; } else { throw new js__$Boot_HaxeError("EReg::matched"); } } ,matchedPos: function() { if(this.r.m == null) { throw new js__$Boot_HaxeError("No string matched"); } return { pos : this.r.m.index, len : this.r.m[0].length}; } ,matchSub: function(s,pos,len) { if(len == null) { len = -1; } if(this.r.global) { this.r.lastIndex = pos; this.r.m = this.r.exec(len < 0 ? s : HxOverrides.substr(s,0,pos + len)); var b = this.r.m != null; if(b) { this.r.s = s; } return b; } else { var b1 = this.match(len < 0 ? HxOverrides.substr(s,pos,null) : HxOverrides.substr(s,pos,len)); if(b1) { this.r.s = s; this.r.m.index += pos; } return b1; } } ,map: function(s,f) { var offset = 0; var buf_b = ""; while(true) { if(offset >= s.length) { break; } else if(!this.matchSub(s,offset)) { buf_b += Std.string(HxOverrides.substr(s,offset,null)); break; } var p = this.matchedPos(); buf_b += Std.string(HxOverrides.substr(s,offset,p.pos - offset)); buf_b += Std.string(f(this)); if(p.len == 0) { buf_b += Std.string(HxOverrides.substr(s,p.pos,1)); offset = p.pos + 1; } else { offset = p.pos + p.len; } if(!this.r.global) { break; } } if(!this.r.global && offset > 0 && offset < s.length) { buf_b += Std.string(HxOverrides.substr(s,offset,null)); } return buf_b; } }; var HxOverrides = function() { }; HxOverrides.__name__ = true; HxOverrides.dateStr = function(date) { var m = date.getMonth() + 1; var d = date.getDate(); var h = date.getHours(); var mi = date.getMinutes(); var s = date.getSeconds(); return date.getFullYear() + "-" + (m < 10 ? "0" + m : "" + m) + "-" + (d < 10 ? "0" + d : "" + d) + " " + (h < 10 ? "0" + h : "" + h) + ":" + (mi < 10 ? "0" + mi : "" + mi) + ":" + (s < 10 ? "0" + s : "" + s); }; HxOverrides.substr = function(s,pos,len) { if(len == null) { len = s.length; } else if(len < 0) { if(pos == 0) { len = s.length + len; } else { return ""; } } return s.substr(pos,len); }; HxOverrides.remove = function(a,obj) { var i = a.indexOf(obj); if(i == -1) { return false; } a.splice(i,1); return true; }; HxOverrides.iter = function(a) { return { cur : 0, arr : a, hasNext : function() { return this.cur < this.arr.length; }, next : function() { return this.arr[this.cur++]; }}; }; var Lambda = function() { }; Lambda.__name__ = true; Lambda.has = function(it,elt) { var x = $getIterator(it); while(x.hasNext()) if(x.next() == elt) { return true; } return false; }; Lambda.exists = function(it,f) { var x = $getIterator(it); while(x.hasNext()) if(f(x.next())) { return true; } return false; }; 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) { callback(js_node_Fs.readFileSync(path,{ encoding : "utf8"})); }; Lang.init = function(folderPath,callback) { var _this = Lang.langs; _this.h = { }; _this.rh = null; var count = 0; var _g = 0; var _g1 = Lang.ids; while(_g < _g1.length) { var name = [_g1[_g]]; ++_g; Lang.request("" + folderPath + "/" + name[0] + ".json",(function(name1) { return function(data) { var data1 = JSON.parse(data); var lang = new haxe_ds_StringMap(); var _g2 = 0; var _g11 = Reflect.fields(data1); while(_g2 < _g11.length) { var key = _g11[_g2]; ++_g2; var v = Reflect.field(data1,key); if(__map_reserved[key] != null) { lang.setReserved(key,v); } else { lang.h[key] = v; } } var id = haxe_io_Path.withoutExtension(name1[0]); var _this1 = Lang.langs; if(__map_reserved[id] != null) { _this1.setReserved(id,lang); } else { _this1.h[id] = lang; } count += 1; if(count == Lang.ids.length && callback != null) { callback(); } return; }; })(name)); } }; Lang.get = function(lang,key) { var _this = Lang.langs; if((__map_reserved[lang] != null ? _this.getReserved(lang) : _this.h[lang]) == null) { lang = "en"; } var _this1 = Lang.langs; var _this2 = __map_reserved[lang] != null ? _this1.getReserved(lang) : _this1.h[lang]; var text = __map_reserved[key] != null ? _this2.getReserved(key) : _this2.h[key]; if(text == null) { return key; } else { return text; } }; Math.__name__ = true; var Reflect = function() { }; Reflect.__name__ = true; Reflect.field = function(o,field) { try { return o[field]; } catch( e ) { return null; } }; Reflect.fields = function(o) { var a = []; if(o != null) { var hasOwnProperty = Object.prototype.hasOwnProperty; for( var f in o ) { if(f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o,f)) { a.push(f); } } } return a; }; var Std = function() { }; Std.__name__ = true; Std.string = function(s) { return js_Boot.__string_rec(s,""); }; Std.random = function(x) { if(x <= 0) { return 0; } else { return Math.floor(Math.random() * x); } }; 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.lpad = function(s,c,l) { if(c.length <= 0) { return s; } var buf_b = ""; l -= s.length; while(buf_b.length < l) buf_b += c == null ? "null" : "" + c; buf_b += s == null ? "null" : "" + s; return buf_b; }; StringTools.replace = function(s,sub,by) { return s.split(sub).join(by); }; StringTools.hex = function(n,digits) { var s = ""; while(true) { s = "0123456789ABCDEF".charAt(n & 15) + s; n >>>= 4; if(!(n > 0)) { break; } } if(digits != null) { while(s.length < digits) s = "0" + s; } return s; }; var _$VideoList_VideoList_$Impl_$ = {}; _$VideoList_VideoList_$Impl_$.__name__ = true; _$VideoList_VideoList_$Impl_$._new = function() { return []; }; _$VideoList_VideoList_$Impl_$.findIndex = function(this1,f) { var i = 0; var _g = 0; while(_g < this1.length) { if(f(this1[_g++])) { return i; } ++i; } return -1; }; _$VideoList_VideoList_$Impl_$.addItem = function(this1,item,atEnd,itemPos) { if(atEnd) { this1.push(item); } else { this1.splice(itemPos + 1,0,item); } }; _$VideoList_VideoList_$Impl_$.setNextItem = function(this1,pos,itemPos) { var next = this1[pos]; HxOverrides.remove(this1,next); this1.splice(itemPos + 1,0,next); }; _$VideoList_VideoList_$Impl_$.toggleItemType = function(this1,pos) { this1[pos].isTemp = !this1[pos].isTemp; }; _$VideoList_VideoList_$Impl_$.removeItem = function(this1,index,itemPos) { if(index < itemPos) { --itemPos; } HxOverrides.remove(this1,this1[index]); if(itemPos >= this1.length) { itemPos = 0; } return itemPos; }; _$VideoList_VideoList_$Impl_$.skipItem = function(this1,itemPos) { var item = this1[itemPos]; if(!item.isTemp) { ++itemPos; } else { HxOverrides.remove(this1,item); } if(itemPos >= this1.length) { itemPos = 0; } return itemPos; }; _$VideoList_VideoList_$Impl_$.itemsByUser = function(this1,client) { var i = 0; var _g = 0; while(_g < this1.length) if(this1[_g++].author == client.name) { ++i; } return i; }; var haxe_Log = function() { }; haxe_Log.__name__ = true; haxe_Log.formatOutput = function(v,infos) { var str = Std.string(v); if(infos == null) { return str; } var pstr = infos.fileName + ":" + infos.lineNumber; if(infos.customParams != null) { var _g = 0; var _g1 = infos.customParams; while(_g < _g1.length) str += ", " + Std.string(_g1[_g++]); } return pstr + ": " + str; }; haxe_Log.trace = function(v,infos) { var str = haxe_Log.formatOutput(v,infos); if(typeof(console) != "undefined" && console.log != null) { console.log(str); } }; var haxe_Timer = function(time_ms) { var me = this; this.id = setInterval(function() { me.run(); },time_ms); }; haxe_Timer.__name__ = true; haxe_Timer.delay = function(f,time_ms) { var t = new haxe_Timer(time_ms); t.run = function() { t.stop(); f(); }; return t; }; haxe_Timer.prototype = { stop: function() { if(this.id == null) { return; } clearInterval(this.id); this.id = null; } ,run: function() { } }; var haxe_crypto_Sha256 = function() { }; haxe_crypto_Sha256.__name__ = true; haxe_crypto_Sha256.encode = function(s) { var sh = new haxe_crypto_Sha256(); return sh.hex(sh.doEncode(haxe_crypto_Sha256.str2blks(s),s.length * 8)); }; haxe_crypto_Sha256.str2blks = function(s) { var s1 = haxe_io_Bytes.ofString(s); var nblk = (s1.length + 8 >> 6) + 1; var blks = []; var _g = 0; var _g1 = nblk * 16; while(_g < _g1) blks[_g++] = 0; var _g2 = 0; var _g3 = s1.length; while(_g2 < _g3) { var i = _g2++; blks[i >> 2] |= s1.b[i] << 24 - ((i & 3) << 3); } var i1 = s1.length; blks[i1 >> 2] |= 128 << 24 - ((i1 & 3) << 3); blks[nblk * 16 - 1] = s1.length * 8; return blks; }; haxe_crypto_Sha256.prototype = { doEncode: function(m,l) { var K = [1116352408,1899447441,-1245643825,-373957723,961987163,1508970993,-1841331548,-1424204075,-670586216,310598401,607225278,1426881987,1925078388,-2132889090,-1680079193,-1046744716,-459576895,-272742522,264347078,604807628,770255983,1249150122,1555081692,1996064986,-1740746414,-1473132947,-1341970488,-1084653625,-958395405,-710438585,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,-2117940946,-1838011259,-1564481375,-1474664885,-1035236496,-949202525,-778901479,-694614492,-200395387,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,-2067236844,-1933114872,-1866530822,-1538233109,-1090935817,-965641998]; var HASH = [1779033703,-1150833019,1013904242,-1521486534,1359893119,-1694144372,528734635,1541459225]; var W = []; W[64] = 0; var a; var b; var c; var d; var e; var f; var g; var h; var T1; var T2; m[l >> 5] |= 128 << 24 - l % 32; m[(l + 64 >> 9 << 4) + 15] = l; var i = 0; while(i < m.length) { a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3]; e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7]; var _g = 0; while(_g < 64) { var j = _g++; if(j < 16) { W[j] = m[j + i]; } else { var x = W[j - 2]; var x1 = (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ x >>> 10; var y = W[j - 7]; var lsw = (x1 & 65535) + (y & 65535); var x2 = (x1 >> 16) + (y >> 16) + (lsw >> 16) << 16 | lsw & 65535; var x3 = W[j - 15]; var y1 = (x3 >>> 7 | x3 << 25) ^ (x3 >>> 18 | x3 << 14) ^ x3 >>> 3; var lsw1 = (x2 & 65535) + (y1 & 65535); var x4 = (x2 >> 16) + (y1 >> 16) + (lsw1 >> 16) << 16 | lsw1 & 65535; var y2 = W[j - 16]; var lsw2 = (x4 & 65535) + (y2 & 65535); W[j] = (x4 >> 16) + (y2 >> 16) + (lsw2 >> 16) << 16 | lsw2 & 65535; } var y3 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7); var lsw3 = (h & 65535) + (y3 & 65535); var x5 = (h >> 16) + (y3 >> 16) + (lsw3 >> 16) << 16 | lsw3 & 65535; var y4 = e & f ^ ~e & g; var lsw4 = (x5 & 65535) + (y4 & 65535); var x6 = (x5 >> 16) + (y4 >> 16) + (lsw4 >> 16) << 16 | lsw4 & 65535; var y5 = K[j]; var lsw5 = (x6 & 65535) + (y5 & 65535); var x7 = (x6 >> 16) + (y5 >> 16) + (lsw5 >> 16) << 16 | lsw5 & 65535; var y6 = W[j]; var lsw6 = (x7 & 65535) + (y6 & 65535); T1 = (x7 >> 16) + (y6 >> 16) + (lsw6 >> 16) << 16 | lsw6 & 65535; var x8 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10); var y7 = a & b ^ a & c ^ b & c; var lsw7 = (x8 & 65535) + (y7 & 65535); T2 = (x8 >> 16) + (y7 >> 16) + (lsw7 >> 16) << 16 | lsw7 & 65535; h = g; g = f; f = e; var lsw8 = (d & 65535) + (T1 & 65535); e = (d >> 16) + (T1 >> 16) + (lsw8 >> 16) << 16 | lsw8 & 65535; d = c; c = b; b = a; var lsw9 = (T1 & 65535) + (T2 & 65535); a = (T1 >> 16) + (T2 >> 16) + (lsw9 >> 16) << 16 | lsw9 & 65535; } var y8 = HASH[0]; var lsw10 = (a & 65535) + (y8 & 65535); HASH[0] = (a >> 16) + (y8 >> 16) + (lsw10 >> 16) << 16 | lsw10 & 65535; var y9 = HASH[1]; var lsw11 = (b & 65535) + (y9 & 65535); HASH[1] = (b >> 16) + (y9 >> 16) + (lsw11 >> 16) << 16 | lsw11 & 65535; var y10 = HASH[2]; var lsw12 = (c & 65535) + (y10 & 65535); HASH[2] = (c >> 16) + (y10 >> 16) + (lsw12 >> 16) << 16 | lsw12 & 65535; var y11 = HASH[3]; var lsw13 = (d & 65535) + (y11 & 65535); HASH[3] = (d >> 16) + (y11 >> 16) + (lsw13 >> 16) << 16 | lsw13 & 65535; var y12 = HASH[4]; var lsw14 = (e & 65535) + (y12 & 65535); HASH[4] = (e >> 16) + (y12 >> 16) + (lsw14 >> 16) << 16 | lsw14 & 65535; var y13 = HASH[5]; var lsw15 = (f & 65535) + (y13 & 65535); HASH[5] = (f >> 16) + (y13 >> 16) + (lsw15 >> 16) << 16 | lsw15 & 65535; var y14 = HASH[6]; var lsw16 = (g & 65535) + (y14 & 65535); HASH[6] = (g >> 16) + (y14 >> 16) + (lsw16 >> 16) << 16 | lsw16 & 65535; var y15 = HASH[7]; var lsw17 = (h & 65535) + (y15 & 65535); HASH[7] = (h >> 16) + (y15 >> 16) + (lsw17 >> 16) << 16 | lsw17 & 65535; i += 16; } return HASH; } ,hex: function(a) { var str = ""; var _g = 0; while(_g < a.length) str += StringTools.hex(a[_g++],8); return str.toLowerCase(); } }; var haxe_io_Bytes = function(data) { this.length = data.byteLength; this.b = new Uint8Array(data); this.b.bufferValue = data; data.hxBytes = this; data.bytes = this.b; }; haxe_io_Bytes.__name__ = true; haxe_io_Bytes.ofString = function(s,encoding) { if(encoding == haxe_io_Encoding.RawNative) { var buf = new Uint8Array(s.length << 1); var _g = 0; var _g1 = s.length; while(_g < _g1) { var i = _g++; var c = s.charCodeAt(i); buf[i << 1] = c & 255; buf[i << 1 | 1] = c >> 8; } return new haxe_io_Bytes(buf.buffer); } var a = []; var i1 = 0; while(i1 < s.length) { var c1 = s.charCodeAt(i1++); if(55296 <= c1 && c1 <= 56319) { c1 = c1 - 55232 << 10 | s.charCodeAt(i1++) & 1023; } if(c1 <= 127) { a.push(c1); } else if(c1 <= 2047) { a.push(192 | c1 >> 6); a.push(128 | c1 & 63); } else if(c1 <= 65535) { a.push(224 | c1 >> 12); a.push(128 | c1 >> 6 & 63); a.push(128 | c1 & 63); } else { a.push(240 | c1 >> 18); a.push(128 | c1 >> 12 & 63); a.push(128 | c1 >> 6 & 63); a.push(128 | c1 & 63); } } return new haxe_io_Bytes(new Uint8Array(a).buffer); }; var haxe_io_Encoding = $hxEnums["haxe.io.Encoding"] = { __ename__ : true, __constructs__ : ["UTF8","RawNative"] ,UTF8: {_hx_index:0,__enum__:"haxe.io.Encoding",toString:$estr} ,RawNative: {_hx_index:1,__enum__:"haxe.io.Encoding",toString:$estr} }; var haxe_io_Path = function(path) { switch(path) { case ".":case "..": this.dir = path; this.file = ""; return; } var c1 = path.lastIndexOf("/"); var c2 = path.lastIndexOf("\\"); if(c1 < c2) { this.dir = HxOverrides.substr(path,0,c2); path = HxOverrides.substr(path,c2 + 1,null); this.backslash = true; } else if(c2 < c1) { this.dir = HxOverrides.substr(path,0,c1); path = HxOverrides.substr(path,c1 + 1,null); } else { this.dir = null; } var cp = path.lastIndexOf("."); if(cp != -1) { this.ext = HxOverrides.substr(path,cp + 1,null); this.file = HxOverrides.substr(path,0,cp); } else { this.ext = null; this.file = path; } }; haxe_io_Path.__name__ = true; haxe_io_Path.withoutExtension = function(path) { var s = new haxe_io_Path(path); s.ext = null; return s.toString(); }; haxe_io_Path.extension = function(path) { var s = new haxe_io_Path(path); if(s.ext == null) { return ""; } return s.ext; }; haxe_io_Path.addTrailingSlash = function(path) { if(path.length == 0) { return "/"; } var c1 = path.lastIndexOf("/"); var c2 = path.lastIndexOf("\\"); if(c1 < c2) { if(c2 != path.length - 1) { return path + "\\"; } else { return path; } } else if(c1 != path.length - 1) { return path + "/"; } else { return path; } }; haxe_io_Path.prototype = { toString: function() { return (this.dir == null ? "" : this.dir + (this.backslash ? "\\" : "/")) + this.file + (this.ext == null ? "" : "." + this.ext); } }; var js__$Boot_HaxeError = function(val) { Error.call(this); this.val = val; if(Error.captureStackTrace) { Error.captureStackTrace(this,js__$Boot_HaxeError); } }; js__$Boot_HaxeError.__name__ = true; js__$Boot_HaxeError.__super__ = Error; js__$Boot_HaxeError.prototype = $extend(Error.prototype,{ }); var js_Boot = function() { }; js_Boot.__name__ = true; js_Boot.__string_rec = function(o,s) { if(o == null) { return "null"; } if(s.length >= 5) { return "<...>"; } var t = typeof(o); if(t == "function" && (o.__name__ || o.__ename__)) { t = "object"; } switch(t) { case "function": return ""; case "object": if(o.__enum__) { var e = $hxEnums[o.__enum__]; var n = e.__constructs__[o._hx_index]; var con = e[n]; if(con.__params__) { s = s + "\t"; return n + "(" + ((function($this) { var $r; var _g = []; { var _g1 = 0; var _g2 = con.__params__; while(true) { if(!(_g1 < _g2.length)) { break; } var p = _g2[_g1]; _g1 = _g1 + 1; _g.push(js_Boot.__string_rec(o[p],s)); } } $r = _g; return $r; }(this))).join(",") + ")"; } else { return n; } } if(((o) instanceof Array)) { var str = "["; s += "\t"; var _g3 = 0; var _g11 = o.length; while(_g3 < _g11) { var i = _g3++; str += (i > 0 ? "," : "") + js_Boot.__string_rec(o[i],s); } str += "]"; return str; } var tostr; try { tostr = o.toString; } catch( e1 ) { var e2 = ((e1) instanceof js__$Boot_HaxeError) ? e1.val : e1; return "???"; } if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") { var s2 = o.toString(); if(s2 != "[object Object]") { return s2; } } var str1 = "{\n"; s += "\t"; var hasp = o.hasOwnProperty != null; var k = null; for( k in o ) { if(hasp && !o.hasOwnProperty(k)) { continue; } if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") { continue; } if(str1.length != 2) { str1 += ", \n"; } str1 += s + k + " : " + js_Boot.__string_rec(o[k],s); } s = s.substring(1); str1 += "\n" + s + "}"; return str1; case "string": return o; default: return String(o); } }; 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_node_Readline = require("readline"); var js_npm_ws_Server = require("ws").Server; var server_ConsoleInput = function(main) { this.main = main; }; server_ConsoleInput.__name__ = true; server_ConsoleInput.prototype = { initConsoleInput: function() { var _gthis = this; var rl = js_node_Readline.createInterface(process.stdin,process.stdout); haxe_Log.trace = function(msg,pos) { js_node_Readline.clearLine(process.stdout,0); js_node_Readline.cursorTo(process.stdout,0,null); console.log(msg); rl.prompt(true); return; }; rl.prompt(); rl.on("line",function(line) { _gthis.parseLine(line); rl.prompt(); return; }); } ,parseLine: function(line) { if(StringTools.startsWith(line,"/addAdmin")) { var args = line.split(" "); if(args.length != 3) { haxe_Log.trace("Wrong count of arguments",{ fileName : "src/server/ConsoleInput.hx", lineNumber : 36, className : "server.ConsoleInput", methodName : "parseLine"}); return; } var name = args[1]; var password = args[2]; if(this.main.badNickName(name)) { haxe_Log.trace(StringTools.replace(Lang.get("usernameError"),"$MAX","" + this.main.config.maxLoginLength),{ fileName : "src/server/ConsoleInput.hx", lineNumber : 44, className : "server.ConsoleInput", methodName : "parseLine"}); return; } this.main.addAdmin(name,password); } else if(line == "/exit") { this.main.exit(); return; } else { haxe_Log.trace("Unknown command \"" + line + "\". List:\n/addAdmin name password | Adds channel admin\n/exit | Exit process",{ fileName : "src/server/ConsoleInput.hx", lineNumber : 53, className : "server.ConsoleInput", methodName : "parseLine"}); } } }; var server_HttpServer = function() { }; server_HttpServer.__name__ = true; server_HttpServer.init = function(dir,customDir) { server_HttpServer.dir = dir; if(customDir == null) { return; } server_HttpServer.customDir = customDir; server_HttpServer.hasCustomRes = sys_FileSystem.exists(customDir); }; server_HttpServer.serveFiles = function(req,res) { var url = req.url; if(url == "/") { url = "/index.html"; } var filePath = server_HttpServer.dir + url; var tmp; if(req.connection.remoteAddress != req.connection.localAddress) { var _this = server_HttpServer.allowedLocalFiles; tmp = __map_reserved[url] != null ? _this.getReserved(url) : _this.h[url]; } else { tmp = true; } if(tmp) { if(server_HttpServer.serveLocalFile(res,url)) { return; } } if(!server_HttpServer.isChildOf(server_HttpServer.dir,filePath)) { res.statusCode = 500; var tmp1 = "Error getting the file: No access to " + js_node_Path.relative(server_HttpServer.dir,filePath) + "."; res.end(tmp1); return; } if(server_HttpServer.hasCustomRes) { var path = server_HttpServer.customDir + url; if(js_node_Fs.existsSync(path)) { filePath = path; if(sys_FileSystem.isDirectory(filePath)) { filePath = haxe_io_Path.addTrailingSlash(filePath) + "index.html"; } } } js_node_Fs.readFile(filePath,function(err,data) { if(err != null) { server_HttpServer.readFileError(err,res,filePath); return; } var ext = haxe_io_Path.extension(filePath).toLowerCase(); var tmp2 = server_HttpServer.getMimeType(ext); res.setHeader("Content-Type",tmp2); if(ext == "html") { data = server_HttpServer.localizeHtml(data.toString(),req.headers["accept-language"]); } res.end(data); return; }); }; server_HttpServer.readFileError = function(err,res,filePath) { if(err.code == "ENOENT") { res.statusCode = 404; res.end("File " + js_node_Path.relative(server_HttpServer.dir,filePath) + " not found."); } else { res.statusCode = 500; res.end("Error getting the file: " + Std.string(err) + "."); } }; server_HttpServer.serveLocalFile = function(res,filePath) { var ext = haxe_io_Path.extension(filePath).toLowerCase(); if(ext != "mp4" && ext != "mp3" && ext != "wav") { return false; } if(!js_node_Fs.existsSync(filePath)) { return false; } var _this = server_HttpServer.allowedLocalFiles; if(__map_reserved[filePath] != null) { _this.setReserved(filePath,true); } else { _this.h[filePath] = true; } js_node_Fs.readFile(filePath,function(err,data) { if(err != null) { server_HttpServer.readFileError(err,res,filePath); return; } var tmp = server_HttpServer.getMimeType(ext); res.setHeader("Content-Type",tmp); res.end(data); return; }); return true; }; server_HttpServer.localizeHtml = function(data,lang) { if(lang != null && server_HttpServer.matchLang.match(lang)) { lang = server_HttpServer.matchLang.matched(0); } else { lang = "en"; } data = server_HttpServer.matchVarString.map(data,function(regExp) { var key = regExp.matched(1); return Lang.get(lang,key); }); return data; }; server_HttpServer.isChildOf = function(parent,child) { var rel = js_node_Path.relative(parent,child); if(rel.length > 0 && !StringTools.startsWith(rel,"..")) { return !js_node_Path.isAbsolute(rel); } else { return false; } }; server_HttpServer.getMimeType = function(ext) { var _this = server_HttpServer.mimeTypes; var contentType = __map_reserved[ext] != null ? _this.getReserved(ext) : _this.h[ext]; if(contentType == null) { return "application/octet-stream"; } return contentType; }; var server_Main = function() { this.loadedClientsCount = 0; this.htmlChars = new EReg("[&^<>'\"]",""); this.itemPos = 0; this.isPlaylistOpen = true; this.messages = []; this.videoTimer = new server_VideoTimer(); this.videoList = _$VideoList_VideoList_$Impl_$._new(); this.freeIds = []; this.clients = []; this.rootDir = "" + __dirname + "/.."; var _gthis = this; this.verbose = Lambda.has(process.argv.slice(2),"--verbose"); this.statePath = "" + this.rootDir + "/user/state.json"; process.on("SIGINT",$bind(this,this.exit)); process.on("SIGUSR1",$bind(this,this.exit)); process.on("SIGUSR2",$bind(this,this.exit)); process.on("SIGTERM",$bind(this,this.exit)); process.on("uncaughtException",function(err) { _gthis.logError("uncaughtException",{ message : err.message, stack : err.stack}); _gthis.exit(); return; }); process.on("unhandledRejection",function(reason,promise) { _gthis.logError("unhandledRejection",reason); _gthis.exit(); return; }); this.consoleInput = new server_ConsoleInput(this); this.consoleInput.initConsoleInput(); this.initIntergationHandlers(); this.loadState(); this.config = this.loadUserConfig(); this.userList = this.loadUsers(); this.config.salt = this.generateConfigSalt(); this.localIp = server_Utils.getLocalIp(); this.globalIp = this.localIp; this.port = this.config.port; var envPort = process.env.PORT; if(envPort != null) { this.port = envPort; } server_Utils.getGlobalIp(function(ip) { _gthis.globalIp = ip; haxe_Log.trace("Local: http://" + _gthis.localIp + ":" + _gthis.port,{ fileName : "src/server/Main.hx", lineNumber : 82, className : "server.Main", methodName : "new"}); haxe_Log.trace("Global: http://" + _gthis.globalIp + ":" + _gthis.port,{ fileName : "src/server/Main.hx", lineNumber : 83, className : "server.Main", methodName : "new"}); return; }); var dir = "" + this.rootDir + "/res"; server_HttpServer.init(dir,"" + this.rootDir + "/user/res"); Lang.init("" + dir + "/langs"); var server1 = js_node_Http.createServer(function(req,res) { server_HttpServer.serveFiles(req,res); return; }); server1.listen(this.port); this.wss = new js_npm_ws_Server({ server : server1}); this.wss.on("connection",$bind(this,this.onConnect)); }; server_Main.__name__ = true; server_Main.main = function() { new server_Main(); }; server_Main.prototype = { exit: function() { this.saveState(); if(this.wss == null) { process.exit(); return; } this.wss.close(function() { process.exit(); return; }); } ,generateConfigSalt: function() { if(this.userList.salt == null) { var tmp = "" + Math.random(); this.userList.salt = haxe_crypto_Sha256.encode(tmp); } return this.userList.salt; } ,loadUserConfig: function() { var config = this.getUserConfig(); var groups = ["guest","user","leader","admin"]; var _g = 0; while(_g < groups.length) { var field = groups[_g]; ++_g; var group = Reflect.field(config.permissions,field); var _g1 = 0; while(_g1 < groups.length) { var type = groups[_g1]; ++_g1; if(type == field) { continue; } if(group.indexOf(type) == -1) { continue; } HxOverrides.remove(group,type); var _g2 = 0; var _g11 = Reflect.field(config.permissions,type); while(_g2 < _g11.length) group.push(_g11[_g2++]); } } return config; } ,getUserConfig: function() { var config = JSON.parse(js_node_Fs.readFileSync("" + this.rootDir + "/default-config.json",{ encoding : "utf8"})); var customPath = "" + this.rootDir + "/user/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 : 137, className : "server.Main", methodName : "getUserConfig"}); } config[field] = Reflect.field(customConfig,field); } var emoteCopies = new haxe_ds_StringMap(); var _g2 = 0; var _g3 = config.emotes; while(_g2 < _g3.length) { var emote = _g3[_g2]; ++_g2; var key = emote.name; if(__map_reserved[key] != null ? emoteCopies.getReserved(key) : emoteCopies.h[key]) { haxe_Log.trace("Warning: emote name \"" + emote.name + "\" has copy",{ fileName : "src/server/Main.hx", lineNumber : 142, className : "server.Main", methodName : "getUserConfig"}); } var k = emote.name; if(__map_reserved[k] != null) { emoteCopies.setReserved(k,true); } else { emoteCopies.h[k] = true; } if(!this.verbose) { continue; } var key1 = emote.image; if(__map_reserved[key1] != null ? emoteCopies.getReserved(key1) : emoteCopies.h[key1]) { haxe_Log.trace("Warning: emote url of name \"" + emote.name + "\" has copy",{ fileName : "src/server/Main.hx", lineNumber : 145, className : "server.Main", methodName : "getUserConfig"}); } var k1 = emote.image; if(__map_reserved[k1] != null) { emoteCopies.setReserved(k1,true); } else { emoteCopies.h[k1] = true; } } return config; } ,loadUsers: function() { var customPath = "" + this.rootDir + "/user/users.json"; if(!sys_FileSystem.exists(customPath)) { return { admins : []}; } return JSON.parse(js_node_Fs.readFileSync(customPath,{ encoding : "utf8"})); } ,writeUsers: function(users) { var folder = "" + this.rootDir + "/user"; if(!sys_FileSystem.exists(folder)) { sys_FileSystem.createDirectory(folder); } js_node_Fs.writeFileSync("" + folder + "/users.json",JSON.stringify(users,null,"\t")); } ,saveState: function() { haxe_Log.trace("Saving state...",{ fileName : "src/server/Main.hx", lineNumber : 169, className : "server.Main", methodName : "saveState"}); var json = JSON.stringify({ videoList : this.videoList, isPlaylistOpen : this.isPlaylistOpen, itemPos : this.itemPos, messages : this.messages, timer : { time : this.videoTimer.getTime(), paused : this.videoTimer.isPaused()}},null,"\t"); js_node_Fs.writeFileSync(this.statePath,json); } ,loadState: function() { if(!sys_FileSystem.exists(this.statePath)) { return; } haxe_Log.trace("Loading state...",{ fileName : "src/server/Main.hx", lineNumber : 186, className : "server.Main", methodName : "loadState"}); var data = JSON.parse(js_node_Fs.readFileSync(this.statePath,{ encoding : "utf8"})); this.videoList.length = 0; this.messages.length = 0; var _g = 0; var _g1 = data.videoList; while(_g < _g1.length) this.videoList.push(_g1[_g++]); this.isPlaylistOpen = data.isPlaylistOpen; this.itemPos = data.itemPos; var _g2 = 0; var _g3 = data.messages; while(_g2 < _g3.length) this.messages.push(_g3[_g2++]); this.videoTimer.start(); this.videoTimer.setTime(data.timer.time); this.videoTimer.pause(); } ,logError: function(type,data) { haxe_Log.trace(type,{ fileName : "src/server/Main.hx", lineNumber : 200, className : "server.Main", methodName : "logError", customParams : [data]}); var crashesFolder = "" + this.rootDir + "/user/crashes"; if(!sys_FileSystem.exists(crashesFolder)) { sys_FileSystem.createDirectory(crashesFolder); } js_node_Fs.writeFileSync("" + crashesFolder + "/" + (DateTools.format(new Date(),"%Y-%m-%d_%H_%M_%S") + "-" + type) + ".json",JSON.stringify(data,null,"\t")); } ,initIntergationHandlers: function() { var _gthis = this; if(process.env["_"] != null && process.env["_"].indexOf("heroku") != -1 && process.env["APP_URL"] != null) { new haxe_Timer(600000).run = function() { if(_gthis.clients.length == 0) { return; } var url = "http://" + process.env["APP_URL"]; haxe_Log.trace("Ping " + url,{ fileName : "src/server/Main.hx", lineNumber : 214, className : "server.Main", methodName : "initIntergationHandlers"}); js_node_Http.get(url,function(r) { return; }); }; } } ,addAdmin: function(name,password) { password += this.config.salt; var hash = haxe_crypto_Sha256.encode(password); if(this.userList.admins == null) { this.userList.admins = []; } this.userList.admins.push({ name : name, hash : hash}); this.writeUsers(this.userList); haxe_Log.trace("Admin " + name + " added.",{ fileName : "src/server/Main.hx", lineNumber : 229, className : "server.Main", methodName : "addAdmin"}); } ,onConnect: function(ws,req) { var _gthis = this; var ip = req.connection.remoteAddress; var id = this.freeIds.length > 0 ? this.freeIds.shift() : this.clients.length; var name = "Guest " + (id + 1); haxe_Log.trace("" + name + " connected (" + ip + ")",{ fileName : "src/server/Main.hx", lineNumber : 236, className : "server.Main", methodName : "onConnect"}); var client = new Client(ws,req,id,name,0); client.setGroupFlag(ClientGroup.Admin,req.connection.localAddress == ip); this.clients.push(client); if(this.clients.length == 1 && this.videoList.length > 0) { if(this.videoTimer.isPaused()) { this.videoTimer.play(); } } 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 : { config : tmp, history : tmp1, isUnknownClient : true, clientName : client1, clients : _g, videoList : this.videoList, isPlaylistOpen : this.isPlaylistOpen, itemPos : this.itemPos, globalIp : this.globalIp}}); this.sendClientList(); ws.on("message",function(data) { 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 : 266, className : "server.Main", methodName : "onConnect"}); server_Utils.sortedPush(_gthis.freeIds,client.id); HxOverrides.remove(_gthis.clients,client); _gthis.sendClientList(); if((client.group & 2) != 0) { if(_gthis.videoTimer.isPaused()) { _gthis.videoTimer.play(); } } if(_gthis.clients.length == 0) { if(_gthis.waitVideoStart != null) { _gthis.waitVideoStart.stop(); } _gthis.videoTimer.pause(); } return; }); } ,onMessage: function(client,data) { var _gthis = this; switch(data.type) { case "AddVideo": if(!this.checkPermission(client,"addVideo")) { return; } if(!this.isPlaylistOpen) { if(!this.checkPermission(client,"lockPlaylist")) { return; } } if(this.config.totalVideoLimit != 0 && this.videoList.length >= this.config.totalVideoLimit) { this.serverMessage(client,"totalVideoLimitError"); return; } if(this.config.userVideoLimit != 0 && _$VideoList_VideoList_$Impl_$.itemsByUser(this.videoList,client) >= this.config.userVideoLimit) { this.serverMessage(client,"videoLimitPerUserError"); return; } var item = data.addVideo.item; item.author = client.name; var local = "" + this.localIp + ":" + this.port; if(item.url.indexOf(local) != -1) { item.url = StringTools.replace(item.url,local,"" + this.globalIp + ":" + this.port); } if(Lambda.exists(this.videoList,function(i) { return i.url == item.url; })) { this.serverMessage(client,"videoAlreadyExistsError"); return; } _$VideoList_VideoList_$Impl_$.addItem(this.videoList,item,data.addVideo.atEnd,this.itemPos); this.broadcast(data); if(this.videoList.length == 1) { this.restartWaitTimer(); } break; case "ClearChat": if(!this.checkPermission(client,"clearChat")) { return; } this.messages.length = 0; this.broadcast(data); break; case "ClearPlaylist": if(!this.checkPermission(client,"removeVideo")) { return; } this.videoTimer.stop(); this.videoList.length = 0; this.itemPos = 0; this.broadcast(data); break; case "Connected": break; case "GetTime": if(this.videoList.length == 0) { return; } if(this.videoTimer.getTime() > this.videoList[this.itemPos].duration - 0.01) { this.videoTimer.stop(); this.onMessage(client,{ type : "SkipVideo", skipVideo : { url : this.videoList[this.itemPos].url}}); return; } var obj = { type : "GetTime", getTime : { time : this.videoTimer.getTime()}}; if(this.videoTimer.isPaused()) { obj.getTime.paused = true; } if(this.videoTimer.getRate() != 1) { if(!ClientTools.hasLeader(this.clients)) { this.videoTimer.setRate(1); } obj.getTime.rate = this.videoTimer.getRate(); } this.send(client,obj); break; case "Login": var name = data.login.clientName; if(this.badNickName(name) || name.length > this.config.maxLoginLength || ClientTools.getByName(this.clients,name) != null) { this.serverMessage(client,"usernameError"); this.send(client,{ type : "LoginError"}); return; } var hash = data.login.passHash; if(hash == null) { if(Lambda.exists(this.userList.admins,function(a) { return a.name == name; })) { this.send(client,{ type : "PasswordRequest"}); return; } } else if(Lambda.exists(this.userList.admins,function(a1) { if(a1.name == name) { return a1.hash == hash; } else { return false; } })) { client.setGroupFlag(ClientGroup.Admin,true); } else { this.serverMessage(client,"passwordMatchError"); this.send(client,{ type : "LoginError"}); return; } client.name = name; client.setGroupFlag(ClientGroup.User,true); this.send(client,{ type : data.type, login : { isUnknownClient : true, clientName : client.name, clients : this.clientList()}}); this.sendClientList(); break; case "LoginError": break; case "Logout": var oldName = client.name; client.name = "Guest " + (this.clients.indexOf(client) + 1); client.setGroupFlag(ClientGroup.User,false); this.send(client,{ type : data.type, logout : { oldClientName : oldName, clientName : client.name, clients : this.clientList()}}); this.sendClientList(); break; case "Message": if(!this.checkPermission(client,"writeChat")) { return; } 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 = "[" + HxOverrides.dateStr(new Date()).split(" ")[1] + "] "; this.messages.push({ text : text, name : client.name, time : time}); if(this.messages.length > this.config.serverChatHistory) { this.messages.shift(); } this.broadcast(data); break; case "PasswordRequest": break; case "Pause": if(this.videoList.length == 0) { return; } if((client.group & 2) == 0) { return; } this.videoTimer.setTime(data.pause.time); this.videoTimer.pause(); this.broadcast(data); break; case "Play": if(this.videoList.length == 0) { return; } if((client.group & 2) == 0) { return; } this.videoTimer.setTime(data.play.time); this.videoTimer.play(); this.broadcast(data); break; case "PlayItem": if(!this.checkPermission(client,"changeOrder")) { return; } this.itemPos = data.playItem.pos; this.restartWaitTimer(); this.broadcast(data); break; case "RemoveVideo": if(!this.checkPermission(client,"removeVideo")) { return; } if(this.videoList.length == 0) { return; } var url = data.removeVideo.url; var index = _$VideoList_VideoList_$Impl_$.findIndex(this.videoList,function(item1) { return item1.url == url; }); if(index == -1) { return; } var isCurrent = this.videoList[this.itemPos].url == url; this.itemPos = _$VideoList_VideoList_$Impl_$.removeItem(this.videoList,index,this.itemPos); if(isCurrent && this.videoList.length > 0) { haxe_Timer.delay(function() { _gthis.broadcast(data); _gthis.restartWaitTimer(); return; },1000); } else { this.broadcast(data); } break; case "Rewind": if(!this.checkPermission(client,"rewind")) { return; } if(this.videoList.length == 0) { return; } data.rewind.time += this.videoTimer.getTime(); if(data.rewind.time < 0) { data.rewind.time = 0; } this.videoTimer.setTime(data.rewind.time); this.broadcast(data); break; case "ServerMessage": break; case "SetLeader": var clientName = data.setLeader.clientName; if(client.name == clientName) { if(!this.checkPermission(client,"requestLeader")) { return; } } else if((client.group & 2) == 0 && clientName != "") { if(!this.checkPermission(client,"setLeader")) { return; } } ClientTools.setLeader(this.clients,clientName); this.broadcast({ type : "SetLeader", setLeader : { clientName : clientName}}); if(this.videoList.length == 0) { return; } if(!ClientTools.hasLeader(this.clients)) { if(this.videoTimer.isPaused()) { this.videoTimer.play(); } this.videoTimer.setRate(1); this.broadcast({ type : "Play", play : { time : this.videoTimer.getTime()}}); } break; case "SetNextItem": if(!this.checkPermission(client,"changeOrder")) { return; } var pos = data.setNextItem.pos; if(pos == this.itemPos || pos == this.itemPos + 1) { return; } _$VideoList_VideoList_$Impl_$.setNextItem(this.videoList,pos,this.itemPos); this.broadcast(data); break; case "SetRate": if(this.videoList.length == 0) { return; } if((client.group & 2) == 0) { return; } this.videoTimer.setRate(data.setRate.rate); this.broadcastExcept(client,data); break; case "SetTime": if(this.videoList.length == 0) { return; } if((client.group & 2) == 0) { return; } this.videoTimer.setTime(data.setTime.time); this.broadcastExcept(client,data); break; case "ShufflePlaylist": if(!this.checkPermission(client,"changeOrder")) { return; } if(this.videoList.length == 0) { return; } var current = this.videoList[this.itemPos]; HxOverrides.remove(this.videoList,current); server_Utils.shuffle(this.videoList); this.videoList.splice(this.itemPos,0,current); this.broadcast({ type : "UpdatePlaylist", updatePlaylist : { videoList : this.videoList}}); break; case "SkipVideo": if(!this.checkPermission(client,"removeVideo")) { return; } if(this.videoList.length == 0) { return; } if(this.videoList[this.itemPos].url != data.skipVideo.url) { return; } haxe_Timer.delay(function() { _gthis.itemPos = _$VideoList_VideoList_$Impl_$.skipItem(_gthis.videoList,_gthis.itemPos); if(_gthis.videoList.length > 0) { _gthis.restartWaitTimer(); } _gthis.broadcast(data); return; },1000); break; case "ToggleItemType": _$VideoList_VideoList_$Impl_$.toggleItemType(this.videoList,data.toggleItemType.pos); this.broadcast(data); break; case "TogglePlaylistLock": if(!this.checkPermission(client,"lockPlaylist")) { return; } this.isPlaylistOpen = !this.isPlaylistOpen; this.broadcast({ type : "TogglePlaylistLock", togglePlaylistLock : { isOpen : this.isPlaylistOpen}}); break; case "UpdateClients": this.sendClientList(); break; case "UpdatePlaylist": this.broadcast({ type : "UpdatePlaylist", updatePlaylist : { videoList : this.videoList}}); break; case "VideoLoaded": this.prepareVideoPlayback(); break; } } ,clientList: function() { var _g = []; var _g1 = 0; var _g2 = this.clients; while(_g1 < _g2.length) _g.push(_g2[_g1++].getData()); return _g; } ,sendClientList: function() { this.broadcast({ type : "UpdateClients", updateClients : { clients : this.clientList()}}); } ,serverMessage: function(client,textId) { this.send(client,{ type : "ServerMessage", serverMessage : { textId : textId}}); } ,send: function(client,data) { client.ws.send(JSON.stringify(data),null); } ,broadcast: function(data) { var json = JSON.stringify(data); var _g = 0; var _g1 = this.clients; while(_g < _g1.length) _g1[_g++].ws.send(json,null); } ,broadcastExcept: function(skipped,data) { var json = JSON.stringify(data); var _g = 0; var _g1 = this.clients; while(_g < _g1.length) { var client = _g1[_g]; ++_g; if(client == skipped) { continue; } client.ws.send(json,null); } } ,checkPermission: function(client,perm) { var state = this.hasPermission(client,perm); if(!state) { this.send(client,{ type : "ServerMessage", serverMessage : { textId : "accessError"}}); } return state; } ,hasPermission: function(client,perm) { var p = this.config.permissions; if((client.group & 4) != 0) { return p.admin.indexOf(perm) != -1; } if((client.group & 2) != 0) { return p.leader.indexOf(perm) != -1; } if((client.group & 1) != 0) { return p.user.indexOf(perm) != -1; } return p.guest.indexOf(perm) != -1; } ,badNickName: function(name) { if(name.length == 0) { return true; } if(this.htmlChars.match(name)) { return true; } return false; } ,restartWaitTimer: function() { this.videoTimer.stop(); if(this.waitVideoStart != null) { this.waitVideoStart.stop(); } this.waitVideoStart = haxe_Timer.delay($bind(this,this.startVideoPlayback),3000); } ,prepareVideoPlayback: function() { if(this.videoTimer.isStarted) { return; } this.loadedClientsCount++; if(this.loadedClientsCount == 1) { this.restartWaitTimer(); } if(this.loadedClientsCount >= this.clients.length) { this.startVideoPlayback(); } } ,startVideoPlayback: function() { if(this.waitVideoStart != null) { this.waitVideoStart.stop(); } this.loadedClientsCount = 0; this.broadcast({ type : "VideoLoaded"}); 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); }).on("error",function(e) { haxe_Log.trace("Warning: connection error, server is local.",{ fileName : "src/server/Utils.hx", lineNumber : 13, className : "server.Utils", methodName : "getGlobalIp"}); callback("127.0.0.1"); return; }); }; 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"; }; server_Utils.sortedPush = function(ids,id) { var _g = 0; var _g1 = ids.length; while(_g < _g1) { var i = _g++; if(id < ids[i]) { ids.splice(i,0,id); return; } } ids.push(id); }; server_Utils.shuffle = function(arr) { var _g = 0; var _g1 = arr.length; while(_g < _g1) { var i = _g++; var n = Std.random(arr.length); var a = arr[i]; arr[i] = arr[n]; arr[n] = a; } }; var server_VideoTimer = function() { this.rate = 1.0; this.rateStartTime = 0.0; this.pauseStartTime = 0.0; this.startTime = 0.0; this.isStarted = false; }; server_VideoTimer.__name__ = true; server_VideoTimer.prototype = { start: function() { this.isStarted = true; this.startTime = Date.now() / 1000; this.pauseStartTime = 0; this.rateStartTime = Date.now() / 1000; } ,stop: function() { this.isStarted = false; this.startTime = 0; this.pauseStartTime = 0; } ,pause: function() { this.startTime += this.rateTime() - this.rateTime() * this.rate; this.pauseStartTime = Date.now() / 1000; this.rateStartTime = 0; } ,play: function() { if(!this.isStarted) { this.start(); } this.startTime += this.pauseTime(); this.rateStartTime = Date.now() / 1000; this.pauseStartTime = 0; } ,getTime: function() { if(this.startTime == 0) { return 0; } return Date.now() / 1000 - this.startTime - this.rateTime() + this.rateTime() * this.rate - this.pauseTime(); } ,setTime: function(secs) { this.startTime = Date.now() / 1000 - secs; if(this.isPaused()) { this.pause(); } } ,isPaused: function() { if(!(!this.isStarted)) { return this.pauseStartTime != 0; } else { return true; } } ,getRate: function() { return this.rate; } ,setRate: function(rate) { if(!this.isPaused()) { this.startTime += this.rateTime() - this.rateTime() * this.rate; this.rateStartTime = Date.now() / 1000; } this.rate = rate; } ,pauseTime: function() { if(this.pauseStartTime == 0) { return 0; } return Date.now() / 1000 - this.pauseStartTime; } ,rateTime: function() { if(this.rateStartTime == 0) { return 0; } return Date.now() / 1000 - this.rateStartTime - this.pauseTime(); } }; var sys_FileSystem = function() { }; sys_FileSystem.__name__ = true; sys_FileSystem.exists = function(path) { try { js_node_Fs.accessSync(path); return true; } catch( _ ) { return false; } }; sys_FileSystem.isDirectory = function(path) { try { return js_node_Fs.statSync(path).isDirectory(); } catch( e ) { return false; } }; sys_FileSystem.createDirectory = function(path) { try { js_node_Fs.mkdirSync(path); } catch( e ) { var e1 = ((e) instanceof js__$Boot_HaxeError) ? e.val : e; if(e1.code == "ENOENT") { sys_FileSystem.createDirectory(js_node_Path.dirname(path)); js_node_Fs.mkdirSync(path); } else { var stat; try { stat = js_node_Fs.statSync(path); } catch( _ ) { throw e1; } if(!stat.isDirectory()) { throw e1; } } } }; 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 = {}; String.__name__ = true; Array.__name__ = true; Date.__name__ = "Date"; Object.defineProperty(js__$Boot_HaxeError.prototype,"message",{ get : function() { return String(this.val); }}); js_Boot.__toStr = ({ }).toString; DateTools.DAY_SHORT_NAMES = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]; DateTools.DAY_NAMES = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; DateTools.MONTH_SHORT_NAMES = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; DateTools.MONTH_NAMES = ["January","February","March","April","May","June","July","August","September","October","November","December"]; Lang.langs = new haxe_ds_StringMap(); Lang.ids = ["en","ru"]; server_HttpServer.mimeTypes = (function($this) { var $r; var _g = new haxe_ds_StringMap(); if(__map_reserved["html"] != null) { _g.setReserved("html","text/html"); } else { _g.h["html"] = "text/html"; } if(__map_reserved["js"] != null) { _g.setReserved("js","text/javascript"); } else { _g.h["js"] = "text/javascript"; } if(__map_reserved["css"] != null) { _g.setReserved("css","text/css"); } else { _g.h["css"] = "text/css"; } if(__map_reserved["json"] != null) { _g.setReserved("json","application/json"); } else { _g.h["json"] = "application/json"; } if(__map_reserved["png"] != null) { _g.setReserved("png","image/png"); } else { _g.h["png"] = "image/png"; } if(__map_reserved["jpg"] != null) { _g.setReserved("jpg","image/jpg"); } else { _g.h["jpg"] = "image/jpg"; } if(__map_reserved["gif"] != null) { _g.setReserved("gif","image/gif"); } else { _g.h["gif"] = "image/gif"; } if(__map_reserved["svg"] != null) { _g.setReserved("svg","image/svg+xml"); } else { _g.h["svg"] = "image/svg+xml"; } if(__map_reserved["ico"] != null) { _g.setReserved("ico","image/x-icon"); } else { _g.h["ico"] = "image/x-icon"; } if(__map_reserved["wav"] != null) { _g.setReserved("wav","audio/wav"); } else { _g.h["wav"] = "audio/wav"; } if(__map_reserved["mp3"] != null) { _g.setReserved("mp3","audio/mpeg"); } else { _g.h["mp3"] = "audio/mpeg"; } if(__map_reserved["mp4"] != null) { _g.setReserved("mp4","video/mp4"); } else { _g.h["mp4"] = "video/mp4"; } if(__map_reserved["woff"] != null) { _g.setReserved("woff","application/font-woff"); } else { _g.h["woff"] = "application/font-woff"; } if(__map_reserved["ttf"] != null) { _g.setReserved("ttf","application/font-ttf"); } else { _g.h["ttf"] = "application/font-ttf"; } if(__map_reserved["eot"] != null) { _g.setReserved("eot","application/vnd.ms-fontobject"); } else { _g.h["eot"] = "application/vnd.ms-fontobject"; } if(__map_reserved["otf"] != null) { _g.setReserved("otf","application/font-otf"); } else { _g.h["otf"] = "application/font-otf"; } if(__map_reserved["wasm"] != null) { _g.setReserved("wasm","application/wasm"); } else { _g.h["wasm"] = "application/wasm"; } $r = _g; return $r; }(this)); server_HttpServer.hasCustomRes = false; server_HttpServer.allowedLocalFiles = new haxe_ds_StringMap(); server_HttpServer.matchLang = new EReg("^[A-z]+",""); server_HttpServer.matchVarString = new EReg("\\${([A-z_]+)}","g"); server_Main.main(); })(typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this);