diff options
Diffstat (limited to 'build')
| -rw-r--r-- | build/client.js | 1240 | ||||
| -rw-r--r-- | build/server.js | 933 |
2 files changed, 2173 insertions, 0 deletions
diff --git a/build/client.js b/build/client.js new file mode 100644 index 0000000..9ceba8f --- /dev/null +++ b/build/client.js @@ -0,0 +1,1240 @@ +// 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 Client = function(ws,name,isLeader) { + if(isLeader == null) { + isLeader = false; + } + this.ws = ws; + this.name = name; + this.isLeader = isLeader; +}; +Client.__name__ = true; +Client.fromData = function(data) { + return new Client(null,data.name,data.isLeader); +}; +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.isLeader = true; + } else if(client.isLeader) { + client.isLeader = false; + } + } +}; +ClientTools.getByName = function(clients,name) { + var _g = 0; + while(_g < clients.length) { + var client = clients[_g]; + ++_g; + if(client.name == name) { + return client; + } + } + return null; +}; +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; + } +}; +var HxOverrides = function() { }; +HxOverrides.__name__ = true; +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.exists = function(it,f) { + var x = $getIterator(it); + while(x.hasNext()) if(f(x.next())) { + return true; + } + return false; +}; +Lambda.find = function(it,f) { + var v = $getIterator(it); + while(v.hasNext()) { + var v1 = v.next(); + if(f(v1)) { + return v1; + } + } + return null; +}; +var Lang = function() { }; +Lang.__name__ = true; +Lang.request = function(path,callback) { + var http = new haxe_http_HttpJs(path); + http.onData = callback; + http.request(); +}; +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(key) { + var key1 = Lang.lang; + var _this = Lang.langs; + if((__map_reserved[key1] != null ? _this.getReserved(key1) : _this.h[key1]) == null) { + Lang.lang = "en"; + } + var key2 = Lang.lang; + var _this1 = Lang.langs; + var _this2 = __map_reserved[key2] != null ? _this1.getReserved(key2) : _this1.h[key2]; + 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; +}; +Reflect.isFunction = function(f) { + if(typeof(f) == "function") { + return !(f.__name__ || f.__ename__); + } else { + return false; + } +}; +Reflect.compareMethods = function(f1,f2) { + if(f1 == f2) { + return true; + } + if(!Reflect.isFunction(f1) || !Reflect.isFunction(f2)) { + return false; + } + if(f1.scope == f2.scope && f1.method == f2.method) { + return f1.method != null; + } else { + return false; + } +}; +var Std = function() { }; +Std.__name__ = true; +Std.string = function(s) { + return js_Boot.__string_rec(s,""); +}; +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.personalHistory = []; + this.clients = []; + var _gthis = this; + this.player = new client_Player(this); + if(host == null) { + host = window.location.hostname; + } + if(host == "") { + host = "localhost"; + } + this.initListeners(); + this.onTimeGet.run = function() { + _gthis.send({ type : "GetTime"}); + return; + }; + Lang.init("langs",function() { + _gthis.openWebSocket(host,port); + return; + }); +}; +client_Main.__name__ = true; +client_Main.main = function() { + new client_Main(); +}; +client_Main.prototype = { + openWebSocket: function(host,port) { + var _gthis = this; + this.ws = new WebSocket("ws://" + host + ":" + port); + this.ws.onmessage = $bind(this,this.onMessage); + this.ws.onopen = function() { + _gthis.serverMessage(1); + return _gthis.isConnected = true; + }; + this.ws.onclose = function() { + if(_gthis.isConnected) { + _gthis.serverMessage(2); + } + _gthis.isConnected = false; + _gthis.player.pause(); + return haxe_Timer.delay(function() { + _gthis.openWebSocket(host,port); + return; + },2000); + }; + } + ,initListeners: function() { + var _gthis = this; + var guestName = window.document.querySelector("#guestname"); + guestName.onkeydown = function(e) { + if(e.keyCode == 13) { + _gthis.send({ type : "Login", login : { clientName : guestName.value}}); + } + return; + }; + var chatLine = window.document.querySelector("#chatline"); + chatLine.onkeydown = function(e1) { + switch(e1.keyCode) { + case 13: + _gthis.send({ type : "Message", message : { clientName : "", text : chatLine.value}}); + _gthis.personalHistory.push(chatLine.value); + if(_gthis.personalHistory.length > 50) { + _gthis.personalHistory.shift(); + } + _gthis.personalHistoryId = -1; + chatLine.value = ""; + break; + case 38: + _gthis.personalHistoryId--; + if(_gthis.personalHistoryId == -2) { + _gthis.personalHistoryId = _gthis.personalHistory.length - 1; + if(_gthis.personalHistoryId == -1) { + return; + } + } else if(_gthis.personalHistoryId == -1) { + _gthis.personalHistoryId++; + } + chatLine.value = _gthis.personalHistory[_gthis.personalHistoryId]; + break; + case 40: + if(_gthis.personalHistoryId == -1) { + return; + } + _gthis.personalHistoryId++; + if(_gthis.personalHistoryId > _gthis.personalHistory.length - 1) { + _gthis.personalHistoryId = -1; + chatLine.value = ""; + return; + } + chatLine.value = _gthis.personalHistory[_gthis.personalHistoryId]; + break; + } + }; + client_MobileView.init(); + var leaderBtn = window.document.querySelector("#leader_btn"); + leaderBtn.onclick = function(e2) { + if(_gthis.personal == null) { + return; + } + leaderBtn.classList.toggle("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").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) { + _gthis.addVideoUrl(); + return; + }; + window.document.querySelector("#queue_end").onclick = function(e5) { + _gthis.addVideoUrl(); + return; + }; + window.document.querySelector("#mediaurl").onkeydown = function(e6) { + if(e6.keyCode == 13) { + _gthis.addVideoUrl(); + } + }; + } + ,isLeader: function() { + if(this.personal != null) { + return this.personal.isLeader; + } else { + return false; + } + } + ,addVideoUrl: function() { + var _gthis = this; + var mediaUrl = window.document.querySelector("#mediaurl"); + var url = mediaUrl.value; + var name = this.personal == null ? "Unknown" : this.personal.name; + this.getRemoteVideoDuration(mediaUrl.value,function(duration) { + var tmp = Lang.get("rawVideo"); + _gthis.send({ type : "AddVideo", addVideo : { item : { url : url, title : tmp, author : name, duration : duration}}}); + return; + }); + mediaUrl.value = ""; + } + ,getRemoteVideoDuration: function(src,callback) { + var player = window.document.querySelector("#ytapiplayer"); + 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"}); + player.removeChild(video); + callback(video.duration); + return; + }; + this.prepend(player,video); + } + ,prepend: function(parent,child) { + if(parent.firstChild == null) { + parent.appendChild(child); + } else { + parent.insertBefore(child,parent.firstChild); + } + } + ,onMessage: function(e) { + 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]]}); + switch(data.type) { + case "AddVideo": + if(this.player.isListEmpty()) { + this.player.setVideo(data.addVideo.item); + } + this.player.addVideoItem(data.addVideo.item); + break; + case "Connected": + if(data.connected.isUnknownClient) { + this.updateClients(data.connected.clients); + window.document.querySelector("#guestlogin").style.display = "block"; + window.document.querySelector("#chatline").style.display = "none"; + } else { + this.onLogin(data.connected.clients,data.connected.clientName); + } + 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; + this.player.addVideoItem(video); + } + break; + case "GetTime": + var newTime = data.getTime.time; + var time = this.player.getTime(); + if(Math.abs(time - newTime) < 2) { + return; + } + this.player.setTime(newTime); + if(!data.getTime.paused) { + this.player.play(); + } + break; + case "Login": + this.onLogin(data.login.clients,data.login.clientName); + break; + case "LoginError": + this.serverMessage(4,Lang.get("usernameError")); + break; + case "Logout": + this.updateClients(data.logout.clients); + this.personal = null; + window.document.querySelector("#guestlogin").style.display = "block"; + window.document.querySelector("#chatline").style.display = "none"; + break; + case "Message": + this.addMessage(data.message.clientName,data.message.text); + break; + case "Pause": + this.player.pause(); + this.player.setTime(data.pause.time); + break; + case "Play": + this.player.setTime(data.play.time); + this.player.play(); + break; + case "RemoveVideo": + this.player.removeItem(data.removeVideo.url); + if(this.player.isListEmpty()) { + this.player.pause(); + } + break; + case "SetLeader": + ClientTools.setLeader(this.clients,data.setLeader.clientName); + this.updateUserList(); + if(this.personal == null) { + return; + } + var leaderBtn = window.document.querySelector("#leader_btn"); + if(this.personal.isLeader) { + leaderBtn.classList.add("label-success"); + } else { + leaderBtn.classList.remove("label-success"); + } + break; + case "SetTime": + var newTime1 = data.setTime.time; + var time1 = this.player.getTime(); + if(Math.abs(time1 - newTime1) < 2) { + return; + } + this.player.setTime(newTime1); + break; + case "UpdateClients": + this.updateClients(data.updateClients.clients); + if(this.personal != null) { + this.personal = ClientTools.getByName(this.clients,this.personal.name); + } + break; + case "VideoLoaded": + this.player.setTime(0); + this.player.play(); + break; + } + } + ,onLogin: function(data,clientName) { + this.updateClients(data); + this.personal = ClientTools.getByName(this.clients,clientName); + if(this.personal == null) { + return; + } + window.document.querySelector("#guestlogin").style.display = "none"; + window.document.querySelector("#chatline").style.display = "block"; + } + ,updateClients: function(newClients) { + this.clients.length = 0; + var _g = 0; + while(_g < newClients.length) this.clients.push(Client.fromData(newClients[_g++])); + this.updateUserList(); + } + ,send: function(data) { + if(!this.isConnected) { + return; + } + this.ws.send(JSON.stringify(data)); + } + ,serverMessage: function(type,text) { + var msgBuf = window.document.querySelector("#messagebuffer"); + var div = window.document.createElement("div"); + var time = "[" + new Date().toTimeString().split(" ")[0] + "] "; + switch(type) { + case 1: + div.className = "server-msg-reconnect"; + div.innerHTML = Lang.get("msgConnected"); + break; + case 2: + div.className = "server-msg-disconnect"; + div.innerHTML = Lang.get("msgDisconnected"); + break; + case 3: + div.className = "server-whisper"; + div.innerHTML = time + text + " " + Lang.get("entered"); + break; + case 4: + div.className = "server-whisper"; + div.innerHTML = time + text; + break; + default: + } + msgBuf.appendChild(div); + msgBuf.scrollTop = msgBuf.scrollHeight; + } + ,updateUserList: function() { + window.document.querySelector("#usercount").innerHTML = this.clients.length + " " + Lang.get("online"); + window.document.title = "" + this.pageTitle + " (" + this.clients.length + ")"; + var list_b = ""; + var _g = 0; + var _g1 = this.clients; + while(_g < _g1.length) { + var client1 = _g1[_g]; + ++_g; + if(client1.isLeader) { + list_b += "<span class=\"glyphicon glyphicon-star-empty\"></span>"; + } + list_b += Std.string("<span class=\"" + "userlist_item" + "\">" + client1.name + "</span></br>"); + } + window.document.querySelector("#userlist").innerHTML = list_b; + } + ,addMessage: function(name,msg) { + 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] + "] "; + var nameDiv = window.document.createElement("strong"); + nameDiv.className = "username"; + nameDiv.innerHTML = name + ": "; + var textDiv = window.document.createElement("span"); + textDiv.innerHTML = msg; + var isInChatEnd = msgBuf.scrollHeight - msgBuf.scrollTop == msgBuf.clientHeight; + userDiv.appendChild(tstamp); + userDiv.appendChild(nameDiv); + userDiv.appendChild(textDiv); + msgBuf.appendChild(userDiv); + if(isInChatEnd) { + msgBuf.scrollTop = msgBuf.scrollHeight; + } + } +}; +var client_MobileView = function() { }; +client_MobileView.__name__ = true; +client_MobileView.init = function() { + var mvbtn = window.document.querySelector("#mv_btn"); + mvbtn.onclick = function(e) { + if(client_MobileView.toggleFullScreen()) { + window.document.body.classList.add("mobile-view"); + mvbtn.classList.add("label-success"); + var vwrap = window.document.querySelector("#videowrap"); + if(vwrap.children[0] == window.document.querySelector("currenttitle")) { + vwrap.appendChild(vwrap.children[0]); + } + } else { + window.document.body.classList.remove("mobile-view"); + mvbtn.classList.remove("label-success"); + var vwrap1 = window.document.querySelector("videowrap"); + if(vwrap1.children[0] != window.document.querySelector("currenttitle")) { + vwrap1.insertBefore(vwrap1.children[1],vwrap1.children[0]); + } + } + return; + }; +}; +client_MobileView.toggleFullScreen = function() { + var state = true; + var doc = window.document; + if(window.document.fullscreenElement == null && doc.mozFullScreenElement == null && doc.webkitFullscreenElement == null) { + if(window.document.documentElement.requestFullscreen != null) { + window.document.documentElement.requestFullscreen(); + } else if(doc.documentElement.mozRequestFullScreen != null) { + doc.documentElement.mozRequestFullScreen(); + } else if(doc.documentElement.webkitRequestFullscreen != null) { + doc.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); + } else { + state = false; + } + } else { + if(doc.cancelFullScreen != null) { + doc.cancelFullScreen(); + } else if(doc.mozCancelFullScreen != null) { + doc.mozCancelFullScreen(); + } else if(doc.webkitCancelFullScreen != null) { + doc.webkitCancelFullScreen(); + } + state = false; + } + return state; +}; +var client_Player = function(main) { + this.skipSetTime = false; + this.isLoaded = false; + this.player = window.document.querySelector("#ytapiplayer"); + this.videoItemsEl = window.document.querySelector("#queue"); + this.items = []; + this.main = main; +}; +client_Player.__name__ = true; +client_Player.prototype = { + setVideo: function(item) { + var _gthis = this; + this.isLoaded = false; + this.video = window.document.createElement("video"); + this.video.id = "videoplayer"; + this.video.src = item.url; + this.video.controls = true; + this.video.oncanplaythrough = function(e) { + if(!_gthis.isLoaded) { + _gthis.main.send({ type : "VideoLoaded"}); + } + return _gthis.isLoaded = true; + }; + this.video.ontimeupdate = function(e1) { + if(_gthis.skipSetTime) { + _gthis.skipSetTime = false; + return; + } + if(!_gthis.main.isLeader()) { + return; + } + _gthis.main.send({ type : "SetTime", setTime : { time : _gthis.video.currentTime}}); + return; + }; + this.video.onpause = function(e2) { + if(!_gthis.main.isLeader()) { + return; + } + _gthis.main.send({ type : "Pause", pause : { time : _gthis.video.currentTime}}); + return; + }; + this.video.onplay = function(e3) { + if(!_gthis.main.isLeader()) { + return; + } + _gthis.main.send({ type : "Play", play : { time : _gthis.video.currentTime}}); + return; + }; + this.player.innerHTML = ""; + this.player.appendChild(this.video); + } + ,addVideoItem: function(item) { + var _gthis = this; + this.items.push(item); + var itemEl = this.nodeFromString("<li class=\"queue_entry pluid-0 queue_temp queue_active\" title=\"" + Lang.get("addedBy") + ": " + item.author + "\">\n\t\t\t\t<a class=\"qe_title\" href=\"" + item.url + "\" target=\"_blank\">" + item.title + "</a>\n\t\t\t\t<span class=\"qe_time\">" + this.duration(item.duration) + "</span>\n\t\t\t\t<div class=\"qe_clear\"></div>\n\t\t\t\t<div class=\"btn-group\" style=\"display: inline-block;\">\n\t\t\t\t\t<button class=\"btn btn-xs btn-default qbtn-play\">\n\t\t\t\t\t\t<span class=\"glyphicon glyphicon-play\"></span>" + Lang.get("play") + "\n\t\t\t\t\t</button>\n\t\t\t\t\t<button class=\"btn btn-xs btn-default qbtn-next\">\n\t\t\t\t\t\t<span class=\"glyphicon glyphicon-share-alt\"></span>" + Lang.get("skip") + "\n\t\t\t\t\t</button>\n\t\t\t\t\t<button class=\"btn btn-xs btn-default qbtn-tmp\">\n\t\t\t\t\t\t<span class=\"glyphicon glyphicon-flag\"></span>" + Lang.get("makePermanent") + "\n\t\t\t\t\t</button>\n\t\t\t\t\t<button class=\"btn btn-xs btn-default qbtn-delete\" id=\"btn-delete\">\n\t\t\t\t\t\t<span class=\"glyphicon glyphicon-trash\"></span>" + Lang.get("delete") + "\n\t\t\t\t\t</button>\n\t\t\t\t</div>\n\t\t\t</li>"); + itemEl.querySelector("#btn-delete").onclick = function(e) { + _gthis.main.send({ type : "RemoveVideo", removeVideo : { url : itemEl.querySelector(".qe_title").getAttribute("href")}}); + return; + }; + this.videoItemsEl.appendChild(itemEl); + var tmp = "" + this.items.length + " "; + var tmp1 = Lang.get("videos"); + window.document.querySelector("#plcount").innerHTML = tmp + tmp1; + window.document.querySelector("#pllength").innerHTML = this.totalDuration(); + } + ,removeItem: function(url) { + var list = window.document.querySelector("#queue"); + var _g = 0; + var _g1 = list.children; + while(_g < _g1.length) { + var child = _g1[_g]; + ++_g; + if(child.querySelector(".qe_title").getAttribute("href") == url) { + list.removeChild(child); + break; + } + } + HxOverrides.remove(this.items,Lambda.find(this.items,function(item) { + return item.url == url; + })); + if(this.video.src == url) { + if(this.items.length > 0) { + this.setVideo(this.items[0]); + } + } + var tmp = "" + this.items.length + " "; + var tmp1 = Lang.get("videos"); + window.document.querySelector("#plcount").innerHTML = tmp + tmp1; + window.document.querySelector("#pllength").innerHTML = this.totalDuration(); + } + ,duration: function(time) { + var h = time / 60 / 60 | 0; + var m = time / 60 | 0; + var s = time % 60 | 0; + var time1 = "" + m + ":"; + if(m < 10) { + time1 = "0" + time1; + } + if(h > 0) { + time1 = "" + h + ":" + time1; + } + if(s < 10) { + time1 += "0"; + } + time1 += s; + return time1; + } + ,totalDuration: function() { + var time = 0.0; + var _g = 0; + var _g1 = this.items; + while(_g < _g1.length) time += _g1[_g++].duration; + return this.duration(time); + } + ,nodeFromString: function(div) { + var wrapper = window.document.createElement("div"); + wrapper.innerHTML = div; + return wrapper.firstElementChild; + } + ,isListEmpty: function() { + return this.items.length == 0; + } + ,pause: function() { + if(this.video == null) { + return; + } + this.video.pause(); + } + ,play: function() { + if(this.video == null) { + return; + } + this.video.play(); + } + ,setTime: function(time,isLocal) { + if(isLocal == null) { + isLocal = true; + } + if(this.video == null) { + return; + } + this.skipSetTime = isLocal; + this.video.currentTime = time; + } + ,getTime: function() { + if(this.video == null) { + return 0; + } + return this.video.currentTime; + } +}; +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_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 = []; + this.params = []; + this.emptyOnData = $bind(this,this.onData); +}; +haxe_http_HttpBase.__name__ = true; +haxe_http_HttpBase.prototype = { + onData: function(data) { + } + ,onBytes: function(data) { + } + ,onError: function(msg) { + } + ,onStatus: function(status) { + } + ,hasOnData: function() { + return !Reflect.compareMethods($bind(this,this.onData),this.emptyOnData); + } + ,success: function(data) { + this.responseBytes = data; + this.responseAsString = null; + if(this.hasOnData()) { + this.onData(this.get_responseData()); + } + this.onBytes(this.responseBytes); + } + ,get_responseData: function() { + if(this.responseAsString == null && this.responseBytes != null) { + this.responseAsString = this.responseBytes.getString(0,this.responseBytes.length,haxe_io_Encoding.UTF8); + } + return this.responseAsString; + } +}; +var haxe_http_HttpJs = function(url) { + this.async = true; + this.withCredentials = false; + haxe_http_HttpBase.call(this,url); +}; +haxe_http_HttpJs.__name__ = true; +haxe_http_HttpJs.__super__ = haxe_http_HttpBase; +haxe_http_HttpJs.prototype = $extend(haxe_http_HttpBase.prototype,{ + request: function(post) { + var _gthis = this; + this.responseAsString = null; + this.responseBytes = null; + var r = this.req = js_Browser.createXMLHttpRequest(); + var onreadystatechange = function(_) { + if(r.readyState != 4) { + return; + } + var s; + try { + s = r.status; + } catch( e ) { + s = null; + } + if(s == 0 && typeof(window) != "undefined") { + var protocol = window.location.protocol.toLowerCase(); + if(new EReg("^(?:about|app|app-storage|.+-extension|file|res|widget):$","").match(protocol)) { + s = r.response != null ? 200 : 404; + } + } + if(s == undefined) { + s = null; + } + if(s != null) { + _gthis.onStatus(s); + } + if(s != null && s >= 200 && s < 400) { + _gthis.req = null; + var onreadystatechange1 = haxe_io_Bytes.ofData(r.response); + _gthis.success(onreadystatechange1); + } else if(s == null) { + _gthis.req = null; + _gthis.onError("Failed to connect or resolve host"); + } else if(s == null) { + _gthis.req = null; + _gthis.responseBytes = haxe_io_Bytes.ofData(r.response); + _gthis.onError("Http Error #" + r.status); + } else { + switch(s) { + case 12007: + _gthis.req = null; + _gthis.onError("Unknown host"); + break; + case 12029: + _gthis.req = null; + _gthis.onError("Failed to connect to host"); + break; + default: + _gthis.req = null; + _gthis.responseBytes = haxe_io_Bytes.ofData(r.response); + _gthis.onError("Http Error #" + r.status); + } + } + }; + if(this.async) { + r.onreadystatechange = onreadystatechange; + } + var _g = this.postBytes; + var _g1 = this.postData; + var uri = _g1 == null ? _g == null ? null : new Blob([_g.b.bufferValue]) : _g == null ? _g1 : null; + if(uri != null) { + post = true; + } else { + var _g2 = 0; + var _g3 = this.params; + while(_g2 < _g3.length) { + var p = _g3[_g2]; + ++_g2; + if(uri == null) { + uri = ""; + } else { + uri = Std.string(uri) + "&"; + } + var s1 = p.name; + var value = Std.string(uri) + encodeURIComponent(s1) + "="; + var s2 = p.value; + uri = value + encodeURIComponent(s2); + } + } + try { + if(post) { + r.open("POST",this.url,this.async); + } else if(uri != null) { + r.open("GET",this.url + (this.url.split("?").length <= 1 ? "?" : "&") + Std.string(uri),this.async); + uri = null; + } else { + r.open("GET",this.url,this.async); + } + r.responseType = "arraybuffer"; + } catch( e1 ) { + var e2 = ((e1) instanceof js__$Boot_HaxeError) ? e1.val : e1; + this.req = null; + this.onError(e2.toString()); + return; + } + r.withCredentials = this.withCredentials; + if(!Lambda.exists(this.headers,function(h) { + return h.name == "Content-Type"; + }) && post && this.postData == null) { + r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); + } + var _g21 = 0; + var _g31 = this.headers; + while(_g21 < _g31.length) { + var h1 = _g31[_g21]; + ++_g21; + r.setRequestHeader(h1.name,h1.value); + } + r.send(uri); + if(!this.async) { + onreadystatechange(null); + } + } +}); +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.ofData = function(b) { + var hb = b.hxBytes; + if(hb != null) { + return hb; + } + return new haxe_io_Bytes(b); +}; +haxe_io_Bytes.prototype = { + getString: function(pos,len,encoding) { + if(pos < 0 || len < 0 || pos + len > this.length) { + throw new js__$Boot_HaxeError(haxe_io_Error.OutsideBounds); + } + if(encoding == null) { + encoding = haxe_io_Encoding.UTF8; + } + var s = ""; + var b = this.b; + var i = pos; + var max = pos + len; + switch(encoding._hx_index) { + case 0: + while(i < max) { + var c = b[i++]; + if(c < 128) { + if(c == 0) { + break; + } + s += String.fromCodePoint(c); + } else if(c < 224) { + var code = (c & 63) << 6 | b[i++] & 127; + s += String.fromCodePoint(code); + } else if(c < 240) { + var code1 = (c & 31) << 12 | (b[i++] & 127) << 6 | b[i++] & 127; + s += String.fromCodePoint(code1); + } else { + var u = (c & 15) << 18 | (b[i++] & 127) << 12 | (b[i++] & 127) << 6 | b[i++] & 127; + s += String.fromCodePoint(u); + } + } + break; + case 1: + while(i < max) { + var c1 = b[i++] | b[i++] << 8; + s += String.fromCodePoint(c1); + } + break; + } + return s; + } +}; +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_Error = $hxEnums["haxe.io.Error"] = { __ename__ : true, __constructs__ : ["Blocked","Overflow","OutsideBounds","Custom"] + ,Blocked: {_hx_index:0,__enum__:"haxe.io.Error",toString:$estr} + ,Overflow: {_hx_index:1,__enum__:"haxe.io.Error",toString:$estr} + ,OutsideBounds: {_hx_index:2,__enum__:"haxe.io.Error",toString:$estr} + ,Custom: ($_=function(e) { return {_hx_index:3,e:e,__enum__:"haxe.io.Error",toString:$estr}; },$_.__params__ = ["e"],$_) +}; +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.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 "<function>"; + 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_Browser = function() { }; +js_Browser.__name__ = true; +js_Browser.createXMLHttpRequest = function() { + if(typeof XMLHttpRequest != "undefined") { + return new XMLHttpRequest(); + } + if(typeof ActiveXObject != "undefined") { + return new ActiveXObject("Microsoft.XMLHTTP"); + } + throw new js__$Boot_HaxeError("Unable to create XMLHttpRequest object."); +}; +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; +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); +}}); +js_Boot.__toStr = ({ }).toString; +Lang.ids = ["en","ru"]; +Lang.langs = new haxe_ds_StringMap(); +Lang.lang = HxOverrides.substr(window.navigator.language,0,2).toLowerCase(); +client_Main.main(); +})(typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this); diff --git a/build/server.js b/build/server.js new file mode 100644 index 0000000..49e666c --- /dev/null +++ b/build/server.js @@ -0,0 +1,933 @@ +// Generated by Haxe 4.0.5 +(function ($global) { "use strict"; +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 Client = function(ws,name,isLeader) { + if(isLeader == null) { + isLeader = false; + } + this.ws = ws; + this.name = name; + this.isLeader = isLeader; +}; +Client.__name__ = true; +Client.prototype = { + getData: function() { + return { name : this.name, isLeader : this.isLeader}; + } +}; +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.isLeader = true; + } else if(client.isLeader) { + client.isLeader = false; + } + } +}; +ClientTools.hasLeader = function(clients) { + var _g = 0; + while(_g < clients.length) if(clients[_g++].isLeader) { + return true; + } + return false; +}; +ClientTools.getByName = function(clients,name) { + var _g = 0; + while(_g < clients.length) { + var client = clients[_g]; + ++_g; + if(client.name == name) { + return client; + } + } + return null; +}; +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.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.find = function(it,f) { + var v = $getIterator(it); + while(v.hasNext()) { + var v1 = v.next(); + if(f(v1)) { + return v1; + } + } + 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) { + 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,""); +}; +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; + } +}; +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_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.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 "<function>"; + case "object": + 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_Dns = require("dns"); +var js_node_Fs = require("fs"); +var js_node_Http = require("http"); +var js_node_Path = require("path"); +var js_npm_ws_Server = require("ws").Server; +var server_HttpServer = function() { }; +server_HttpServer.__name__ = true; +server_HttpServer.init = function(directory) { + server_HttpServer.dir = directory; +}; +server_HttpServer.serveFiles = function(req,res) { + var filePath = server_HttpServer.dir + req.url; + if(req.url == "/") { + filePath = "" + server_HttpServer.dir + "/index.html"; + } + var extension = haxe_io_Path.extension(filePath).toLowerCase(); + var contentType = server_HttpServer.getMimeType(extension); + if(!server_HttpServer.isChildOf(server_HttpServer.dir,filePath)) { + res.statusCode = 500; + var tmp = "Error getting the file: No access to " + js_node_Path.relative(server_HttpServer.dir,filePath) + "."; + res.end(tmp); + return; + } + if(filePath == "" + server_HttpServer.dir + "/client.js") { + filePath = "" + __dirname + "/client.js"; + } + js_node_Fs.readFile(filePath,function(err,data) { + if(err != null) { + if(err.code == "ENOENT") { + res.statusCode = 404; + var tmp1 = "File " + js_node_Path.relative(server_HttpServer.dir,filePath) + " not found."; + res.end(tmp1); + } else { + res.statusCode = 500; + res.end("Error getting the file: " + Std.string(err) + "."); + } + return; + } + res.setHeader("Content-Type",contentType); + if(extension == "html") { + data = server_HttpServer.localizeHtml(data.toString(),req.headers["accept-language"]); + } + res.end(data); + }); +}; +server_HttpServer.localizeHtml = function(data,lang) { + if(lang != null && server_HttpServer.matchLang.match(lang)) { + lang = server_HttpServer.matchLang.matched(0); + } else { + lang = "en"; + } + data = new EReg("\\${([A-z_]+)}","g").map(data,function(regExp) { + var key = regExp.matched(1); + return Lang.get(lang,key); + }); + return data; +}; +server_HttpServer.isChildOf = function(parent,child) { + var relative = js_node_Path.relative(parent,child); + if(relative.length > 0 && !StringTools.startsWith(relative,"..")) { + return !js_node_Path.isAbsolute(relative); + } 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) { + contentType = "application/octet-stream"; + } + return contentType; +}; +var server_Main = function(port,wsPort) { + if(wsPort == null) { + wsPort = 4201; + } + if(port == null) { + port = 4200; + } + this.loadedClientsCount = 0; + this.videoTimer = new server_VideoTimer(); + this.videoList = []; + this.clients = []; + this.wss = new js_npm_ws_Server({ port : wsPort}); + this.wss.on("connection",$bind(this,this.onConnect)); + var exit = function() { + process.exit(); + }; + 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"}); + 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]}); + 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"}); + return; + }); + var dir = "" + __dirname + "/../res"; + server_HttpServer.init(dir); + Lang.init("" + dir + "/langs"); + js_node_Http.createServer(function(req,res) { + server_HttpServer.serveFiles(req,res); + return; + }).listen(port); +}; +server_Main.__name__ = true; +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; + } + js_node_Http.get("http://myexternalip.com/raw",function(r) { + r.setEncoding("utf8"); + return r.on("data",callback); + }); + }); + } + ,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"}); + var client = new Client(ws,"Unknown",false); + this.clients.push(client); + 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.sendClientList(); + ws.on("message",function(data) { + var tmp = JSON.parse(data); + _gthis.onMessage(client,tmp); + 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"}); + HxOverrides.remove(_gthis.clients,client); + _gthis.sendClientList(); + if(client.isLeader) { + if(_gthis.videoTimer.isPaused()) { + _gthis.videoTimer.play(); + } + } + return; + }); + } + ,onMessage: function(client,data) { + switch(data.type) { + case "AddVideo": + this.videoList.push(data.addVideo.item); + this.broadcast(data); + if(this.videoList.length == 1) { + this.waitVideoStart = haxe_Timer.delay($bind(this,this.startVideoPlayback),3000); + } + break; + case "Connected": + break; + case "GetTime": + if(this.videoList.length == 0) { + return; + } + if(this.videoTimer.getTime() > this.videoList[0].duration) { + this.videoTimer.stop(); + this.onMessage(client,{ type : "RemoveVideo", removeVideo : { url : this.videoList[0].url}}); + return; + } + this.send(client,{ type : "GetTime", getTime : { time : this.videoTimer.getTime(), paused : this.videoTimer.isPaused()}}); + break; + case "Login": + var name = data.login.clientName; + if(name.length == 0 || name.length > 20 || ClientTools.getByName(this.clients,name) != null) { + this.send(client,{ type : "LoginError"}); + return; + } + client.name = data.login.clientName; + 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 = "Unknown"; + this.send(client,{ type : data.type, logout : { clientName : oldName, clients : this.clientList()}}); + this.sendClientList(); + break; + case "Message": + data.message.clientName = client.name; + this.broadcast(data); + break; + case "Pause": + if(this.videoList.length == 0) { + return; + } + if(!client.isLeader) { + return; + } + this.videoTimer.pause(); + this.broadcast(data); + break; + case "Play": + if(this.videoList.length == 0) { + return; + } + if(!client.isLeader) { + return; + } + this.videoTimer.play(); + this.broadcast(data); + break; + case "RemoveVideo": + if(this.videoList.length == 0) { + return; + } + var url = data.removeVideo.url; + if(this.videoList[0].url == url) { + this.videoTimer.stop(); + } + HxOverrides.remove(this.videoList,Lambda.find(this.videoList,function(item) { + return item.url == url; + })); + this.broadcast(data); + break; + case "SetLeader": + ClientTools.setLeader(this.clients,data.setLeader.clientName); + this.sendClientList(); + if(this.videoList.length == 0) { + return; + } + if(!ClientTools.hasLeader(this.clients)) { + if(this.videoTimer.isPaused()) { + this.videoTimer.play(); + } + this.broadcast({ type : "Play", play : { time : this.videoTimer.getTime()}}); + } + break; + case "SetTime": + if(this.videoList.length == 0) { + return; + } + if(!client.isLeader) { + return; + } + this.videoTimer.setTime(data.setTime.time); + this.broadcastExcept(client,data); + break; + case "UpdateClients": + this.sendClientList(); + 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()}}); + } + ,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); + } + } + ,prepareVideoPlayback: function() { + if(this.videoTimer.isStarted) { + return; + } + this.loadedClientsCount++; + if(this.loadedClientsCount == 1) { + this.waitVideoStart = haxe_Timer.delay($bind(this,this.startVideoPlayback),3000); + } + 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_VideoTimer = function() { + 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; + } + ,stop: function() { + this.isStarted = false; + this.startTime = 0.0; + this.pauseStartTime = 0.0; + } + ,pause: function() { + this.pauseStartTime = Date.now() / 1000; + } + ,play: function() { + if(!this.isStarted) { + this.start(); + } + this.startTime += this.pauseTime(); + this.pauseStartTime = 0; + } + ,getTime: function() { + if(this.startTime == 0) { + return 0; + } + return Date.now() / 1000 - this.startTime - this.pauseTime(); + } + ,setTime: function(secs) { + this.startTime = Date.now() / 1000 - secs; + if(this.isPaused()) { + this.pause(); + } + } + ,isPaused: function() { + return this.pauseStartTime != 0; + } + ,pauseTime: function() { + if(!this.isPaused()) { + return 0; + } + return Date.now() / 1000 - this.pauseStartTime; + } +}; +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; } +$global.$haxeUID |= 0; +var __map_reserved = {}; +String.__name__ = true; +Array.__name__ = true; +Object.defineProperty(js__$Boot_HaxeError.prototype,"message",{ get : function() { + return String(this.val); +}}); +js_Boot.__toStr = ({ }).toString; +Lang.ids = ["en","ru"]; +Lang.langs = new haxe_ds_StringMap(); +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.matchLang = new EReg("^[A-z]+",""); +server_Main.main(); +})(typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this); |
