diff options
| author | RblSb <msrblsb@gmail.com> | 2021-01-17 22:50:39 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2021-01-17 22:50:39 +0300 |
| commit | 3444b413ab12783c85ce73df9931142fea11b749 (patch) | |
| tree | 97e128323033cedb0cf6e6c713385960b339c830 | |
| parent | 266c0cbe76d345afe49759ba8be9ba7aadc4760d (diff) | |
requestLeaderOnPause option
closes #13
| -rw-r--r-- | build/server.js | 11 | ||||
| -rw-r--r-- | default-config.json | 1 | ||||
| -rw-r--r-- | package-lock.json | 6 | ||||
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | res/client.js | 50 | ||||
| -rw-r--r-- | src/Types.hx | 1 | ||||
| -rw-r--r-- | src/client/Buttons.hx | 4 | ||||
| -rw-r--r-- | src/client/Main.hx | 40 | ||||
| -rw-r--r-- | src/client/Player.hx | 19 |
9 files changed, 105 insertions, 29 deletions
diff --git a/build/server.js b/build/server.js index 764c7f6..df9604e 100644 --- a/build/server.js +++ b/build/server.js @@ -1,4 +1,4 @@ -// Generated by Haxe 4.1.4 +// Generated by Haxe 4.1.5 (function ($global) { "use strict"; var $estr = function() { return js_Boot.__string_rec(this,''); },$hxEnums = $hxEnums || {},$_; function $extend(from, fields) { @@ -1437,7 +1437,7 @@ JsonParser_$52.__name__ = true; JsonParser_$52.__super__ = json2object_reader_BaseParser; JsonParser_$52.prototype = $extend(json2object_reader_BaseParser.prototype,{ onIncorrectType: function(pos,variable) { - this.errors.push(json2object_Error.IncorrectType(variable,"{ youtubePlaylistLimit : Int, youtubeApiKey : String, userVideoLimit : Int, totalVideoLimit : Int, templateUrl : String, serverChatHistory : Int, ?salt : Null<String>, port : Int, permissions : { user : Array<Permission>, leader : Array<Permission>, guest : Array<Permission>, admin : Array<Permission> }, maxMessageLength : Int, maxLoginLength : Int, localAdmins : Bool, ?isVerbose : Null<Bool>, filters : Array<Filter>, emotes : Array<Emote>, channelName : String }",pos)); + this.errors.push(json2object_Error.IncorrectType(variable,"{ youtubePlaylistLimit : Int, youtubeApiKey : String, userVideoLimit : Int, totalVideoLimit : Int, templateUrl : String, serverChatHistory : Int, ?salt : Null<String>, requestLeaderOnPause : Bool, port : Int, permissions : { user : Array<Permission>, leader : Array<Permission>, guest : Array<Permission>, admin : Array<Permission> }, maxMessageLength : Int, maxLoginLength : Int, localAdmins : Bool, ?isVerbose : Null<Bool>, filters : Array<Filter>, emotes : Array<Emote>, channelName : String }",pos)); json2object_reader_BaseParser.prototype.onIncorrectType.call(this,pos,variable); } ,loadJsonNull: function(pos,variable) { @@ -1445,7 +1445,7 @@ JsonParser_$52.prototype = $extend(json2object_reader_BaseParser.prototype,{ } ,loadJsonObject: function(o,pos,variable) { var assigned = new haxe_ds_StringMap(); - this.objectSetupAssign(assigned,["channelName","emotes","filters","isVerbose","localAdmins","maxLoginLength","maxMessageLength","permissions","port","salt","serverChatHistory","templateUrl","totalVideoLimit","userVideoLimit","youtubeApiKey","youtubePlaylistLimit"],[false,false,false,true,false,false,false,false,false,true,false,false,false,false,false,false]); + this.objectSetupAssign(assigned,["channelName","emotes","filters","isVerbose","localAdmins","maxLoginLength","maxMessageLength","permissions","port","requestLeaderOnPause","salt","serverChatHistory","templateUrl","totalVideoLimit","userVideoLimit","youtubeApiKey","youtubePlaylistLimit"],[false,false,false,true,false,false,false,false,false,false,true,false,false,false,false,false,false]); this.value = this.getAuto(); var _g = 0; while(_g < o.length) { @@ -1479,6 +1479,9 @@ JsonParser_$52.prototype = $extend(json2object_reader_BaseParser.prototype,{ case "port": this.value.port = this.loadObjectField(($_=new JsonParser_$42(this.errors,this.putils,1),$bind($_,$_.loadJson)),field,"port",assigned,this.value.port,pos); break; + case "requestLeaderOnPause": + this.value.requestLeaderOnPause = this.loadObjectField(($_=new JsonParser_$38(this.errors,this.putils,1),$bind($_,$_.loadJson)),field,"requestLeaderOnPause",assigned,this.value.requestLeaderOnPause,pos); + break; case "salt": this.value.salt = this.loadObjectField(($_=new JsonParser_$48(this.errors,this.putils,1),$bind($_,$_.loadJson)),field,"salt",assigned,this.value.salt,pos); break; @@ -1507,7 +1510,7 @@ JsonParser_$52.prototype = $extend(json2object_reader_BaseParser.prototype,{ this.objectErrors(assigned,pos); } ,getAuto: function() { - return { channelName : new JsonParser_$36([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), emotes : new JsonParser_$56([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), filters : new JsonParser_$57([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), isVerbose : new JsonParser_$46([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), localAdmins : new JsonParser_$38([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), maxLoginLength : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), maxMessageLength : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), permissions : new JsonParser_$58([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), port : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), salt : new JsonParser_$48([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), serverChatHistory : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), templateUrl : new JsonParser_$36([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), totalVideoLimit : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), userVideoLimit : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), youtubeApiKey : new JsonParser_$36([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), youtubePlaylistLimit : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1)))}; + return { channelName : new JsonParser_$36([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), emotes : new JsonParser_$56([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), filters : new JsonParser_$57([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), isVerbose : new JsonParser_$46([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), localAdmins : new JsonParser_$38([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), maxLoginLength : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), maxMessageLength : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), permissions : new JsonParser_$58([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), port : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), requestLeaderOnPause : new JsonParser_$38([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), salt : new JsonParser_$48([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), serverChatHistory : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), templateUrl : new JsonParser_$36([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), totalVideoLimit : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), userVideoLimit : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), youtubeApiKey : new JsonParser_$36([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1))), youtubePlaylistLimit : new JsonParser_$42([],this.putils,0).loadJson(new hxjsonast_Json(hxjsonast_JsonValue.JNull,new hxjsonast_Position("",0,1)))}; } ,__class__: JsonParser_$52 }); diff --git a/default-config.json b/default-config.json index 3dc1b2f..bc4c9c0 100644 --- a/default-config.json +++ b/default-config.json @@ -6,6 +6,7 @@ "serverChatHistory": 50, "totalVideoLimit": 0, "userVideoLimit": 0, + "requestLeaderOnPause": false, "localAdmins": true, "templateUrl": "https://youtube.com/playlist?list=PL9FiZUDVMu9tc_85frYognMOVFC_-VkSX", "youtubeApiKey": "AIzaSyDTk1OPRI9cDkAK_BKsBcv10DQCHse-QaA", diff --git a/package-lock.json b/package-lock.json index e7de39d..195628c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,9 +5,9 @@ "requires": true, "dependencies": { "ws": { - "version": "7.2.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.1.tgz", - "integrity": "sha512-sucePNSafamSKoOqoNfBd8V0StlkzJKL2ZAhGQinCfNQ+oacw+Pk7lcdAElecBF2VkLNZRiIb5Oi1Q5lVUVt2A==" + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.2.tgz", + "integrity": "sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA==" } } } diff --git a/package.json b/package.json index 36855db..ef9be54 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,6 @@ }, "homepage": "https://github.com/RblSb/SyncTube#readme", "dependencies": { - "ws": "^7.2.0" + "ws": "^7.4.2" } } diff --git a/res/client.js b/res/client.js index ed6c43a..1a0f9d3 100644 --- a/res/client.js +++ b/res/client.js @@ -1,4 +1,4 @@ -// Generated by Haxe 4.1.4 +// Generated by Haxe 4.1.5 (function ($hx_exports, $global) { "use strict"; $hx_exports["client"] = $hx_exports["client"] || {}; $hx_exports["client"]["JsApi"] = $hx_exports["client"]["JsApi"] || {}; @@ -50,6 +50,13 @@ ClientTools.setLeader = function(clients,name) { } } }; +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) { @@ -681,7 +688,7 @@ client_Buttons.initHotkeys = function(main,player) { window.document.querySelector("#fullscreenbtn").onclick(); break; case 76: - window.document.querySelector("#leader_btn").onclick(); + main.toggleLeader(); break; case 80: if((main.personal.group & 2) == 0) { @@ -691,7 +698,7 @@ client_Buttons.initHotkeys = function(main,player) { } }); } - window.document.querySelector("#leader_btn").onclick(); + main.toggleLeader(); break; case 82: window.document.querySelector("#mediarefresh").onclick(); @@ -996,10 +1003,7 @@ client_Main.prototype = { ,initListeners: function() { var _gthis = this; client_Buttons.init(this); - window.document.querySelector("#leader_btn").onclick = function(e) { - _gthis.setLeaderButton((_gthis.personal.group & 2) == 0); - _gthis.send({ type : "SetLeader", setLeader : { clientName : (_gthis.personal.group & 2) != 0 ? "" : _gthis.personal.name}}); - }; + window.document.querySelector("#leader_btn").onclick = $bind(this,this.toggleLeader); window.document.querySelector("#voteskip").onclick = function(e) { if(client_Utils.isTouch() && !window.confirm(Lang.get("skipItemConfirm"))) { return; @@ -1182,7 +1186,7 @@ client_Main.prototype = { var data = JSON.parse(e.data); if(this.config != null && this.config.isVerbose) { var t = data.type; - haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 342, className : "client.Main", methodName : "onMessage", customParams : [Reflect.field(data,t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null))]}); + haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 334, className : "client.Main", methodName : "onMessage", customParams : [Reflect.field(data,t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null))]}); } client_JsApi.fireOnceEvent(data); switch(data.type) { @@ -1704,6 +1708,19 @@ client_Main.prototype = { this.settings.synchThreshold = s; client_Settings.write(this.settings); } + ,hasPermission: function(group,permission) { + return Reflect.field(this.config.permissions,$hxEnums[group.__enum__].__constructs__[group._hx_index].toLowerCase()).indexOf(permission) != -1; + } + ,toggleLeader: function() { + this.setLeaderButton((this.personal.group & 2) == 0); + this.send({ type : "SetLeader", setLeader : { clientName : (this.personal.group & 2) != 0 ? "" : this.personal.name}}); + } + ,hasLeader: function() { + return ClientTools.hasLeader(this.clients); + } + ,hasLeaderOnPauseRequest: function() { + return this.config.requestLeaderOnPause; + } ,getTemplateUrl: function() { return this.config.templateUrl; } @@ -1853,8 +1870,25 @@ client_Player.prototype = { return; } this.main.send({ type : "Play", play : { time : this.getTime()}}); + if(this.main.hasLeaderOnPauseRequest()) { + if(this.main.hasPermission((this.main.personal.group & 4) != 0 ? ClientGroup.Admin : ClientGroup.User,"requestLeader")) { + this.main.toggleLeader(); + } + } } ,onPause: function() { + var _gthis = this; + if(this.main.hasLeaderOnPauseRequest() && !this.main.hasLeader()) { + client_JsApi.once("SetLeader",function(event) { + if(event.setLeader.clientName != _gthis.main.personal.name) { + return; + } + _gthis.main.send({ type : "Pause", pause : { time : _gthis.getTime()}}); + _gthis.player.pause(); + }); + this.main.toggleLeader(); + return; + } if((this.main.personal.group & 2) == 0) { return; } diff --git a/src/Types.hx b/src/Types.hx index 76e811b..4061b09 100644 --- a/src/Types.hx +++ b/src/Types.hx @@ -22,6 +22,7 @@ typedef Config = { serverChatHistory:Int, totalVideoLimit:Int, userVideoLimit:Int, + requestLeaderOnPause:Bool, localAdmins:Bool, templateUrl:String, youtubeApiKey:String, diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx index 5eb1baf..cdc9780 100644 --- a/src/client/Buttons.hx +++ b/src/client/Buttons.hx @@ -270,7 +270,7 @@ class Buttons { case S: ge("#voteskip").onclick(); case C: ge("#getplaylist").onclick(); case F: ge("#fullscreenbtn").onclick(); - case L: ge("#leader_btn").onclick(); + case L: main.toggleLeader(); case P: if (!main.isLeader()) { JsApi.once(SetLeader, event -> { @@ -278,7 +278,7 @@ class Buttons { if (name == main.getName()) player.pause(); }); } - ge("#leader_btn").onclick(); + main.toggleLeader(); default: return; } e.preventDefault(); diff --git a/src/client/Main.hx b/src/client/Main.hx index d567d92..5c29d29 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -17,6 +17,8 @@ import Client.ClientData; import Types.VideoDataRequest; import Types.VideoData; import Types.Config; +import Types.Permission; +import Client.ClientGroup; import Types.WsEvent; using StringTools; using ClientTools; @@ -123,17 +125,7 @@ class Main { function initListeners():Void { Buttons.init(this); - ge("#leader_btn").onclick = e -> { - // change button style before answer - setLeaderButton(!personal.isLeader); - final name = personal.isLeader ? "" : personal.name; - send({ - type: SetLeader, - setLeader: { - clientName: name - } - }); - } + ge("#leader_btn").onclick = toggleLeader; final voteSkip = ge("#voteskip"); voteSkip.onclick = e -> { if (Utils.isTouch() && !window.confirm(Lang.get("skipItemConfirm"))) return; @@ -829,6 +821,32 @@ class Main { Settings.write(settings); } + public function hasPermission(group:ClientGroup, permission:Permission):Bool { + final id = group.getName().toLowerCase(); + final arr:Array<Permission> = Reflect.field(config.permissions, id); + return arr.contains(permission); + } + + public function toggleLeader():Void { + // change button style before answer + setLeaderButton(!personal.isLeader); + final name = personal.isLeader ? "" : personal.name; + send({ + type: SetLeader, + setLeader: { + clientName: name + } + }); + } + + public function hasLeader():Bool { + return clients.hasLeader(); + } + + public function hasLeaderOnPauseRequest():Bool { + return config.requestLeaderOnPause; + } + public function getTemplateUrl():String { return config.templateUrl; } diff --git a/src/client/Player.hx b/src/client/Player.hx index 8fe42b3..59ca11f 100644 --- a/src/client/Player.hx +++ b/src/client/Player.hx @@ -170,9 +170,28 @@ class Player { time: getTime() } }); + if (main.hasLeaderOnPauseRequest()) { + // do not remove leader if user cannot request it back + final group:Client.ClientGroup = main.isAdmin() ? Admin : User; + if (main.hasPermission(group, RequestLeaderPerm)) main.toggleLeader(); + } } public function onPause():Void { + if (main.hasLeaderOnPauseRequest() && !main.hasLeader()) { + JsApi.once(SetLeader, event -> { + final name = event.setLeader.clientName; + if (name != main.getName()) return; + main.send({ + type: Pause, pause: { + time: getTime() + } + }); + player.pause(); + }); + main.toggleLeader(); + return; + } if (!main.isLeader()) return; main.send({ type: Pause, pause: { |
