From ede45cea8706eb8540e466df9861c2af8ebf9c44 Mon Sep 17 00:00:00 2001 From: RblSb Date: Sun, 4 Jul 2021 03:59:50 +0300 Subject: Reformat --- src/client/Buttons.hx | 43 +++++++++++-------- src/client/IPlayer.hx | 4 +- src/client/InputWithHistory.hx | 12 +++--- src/client/JsApi.hx | 23 +++++----- src/client/Main.hx | 97 +++++++++++++++++++++++++----------------- src/client/Player.hx | 47 +++++++++++--------- src/client/Settings.hx | 6 +-- src/client/Utils.hx | 11 ++--- src/client/players/Iframe.hx | 15 +++---- src/client/players/Raw.hx | 19 ++++----- src/client/players/Youtube.hx | 21 +++++---- 11 files changed, 161 insertions(+), 137 deletions(-) (limited to 'src/client') diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx index 8ed259a..ee42f44 100644 --- a/src/client/Buttons.hx +++ b/src/client/Buttons.hx @@ -1,17 +1,17 @@ package client; -import js.html.ImageElement; -import haxe.Timer; -import js.html.KeyboardEvent; -import js.html.InputElement; -import js.html.Element; import client.Main.ge; -import js.Browser.window; +import haxe.Timer; import js.Browser.document; +import js.Browser.window; +import js.html.Element; +import js.html.ImageElement; +import js.html.InputElement; +import js.html.KeyboardEvent; + using StringTools; class Buttons { - static inline var CHAT_MIN_SIZE = 200; static var split:Split; static var settings:ClientSettings; @@ -59,8 +59,9 @@ class Buttons { if (!main.isAdmin()) return; var el:Element = cast e.target; if (userList == el) return; - if (!el.classList.contains("userlist_item")) + if (!el.classList.contains("userlist_item")) { el = el.parentElement; + } var name = ""; if (el.children.length == 1) { name = el.lastElementChild.innerText; @@ -126,7 +127,7 @@ class Buttons { final icon = getPlaylist.firstElementChild; icon.setAttribute("name", "checkmark"); Timer.delay(() -> { - icon.setAttribute("name", "link"); + icon.setAttribute("name", "link"); }, 2000); } final clearPlaylist = ge("#clearplaylist"); @@ -154,7 +155,8 @@ class Buttons { final mediaUrl:InputElement = cast ge("#mediaurl"); mediaUrl.oninput = () -> { final value = mediaUrl.value; - final isRawSingleVideo = value != "" && main.isRawPlayerLink(value) && main.isSingleVideoLink(value); + final isRawSingleVideo = value != "" && main.isRawPlayerLink(value) + && main.isSingleVideoLink(value); ge("#mediatitleblock").style.display = isRawSingleVideo ? "" : "none"; if (JsApi.hasSubtitleSupport()) { ge("#subsurlblock").style.display = isRawSingleVideo ? "" : "none"; @@ -228,7 +230,7 @@ class Buttons { document.body.style.gridTemplateColumns = sizes.join(" "); } - static function saveSplitSize():Void { + static function saveSplitSize():Void { final sizes = document.body.style.gridTemplateColumns.split(" "); if (settings.isSwapped) sizes.reverse(); settings.chatSize = Std.parseFloat(sizes[sizes.length - 1]); @@ -277,11 +279,16 @@ class Buttons { if (key == Backspace) e.preventDefault(); if (!e.altKey) return; switch (key) { - case R: ge("#mediarefresh").onclick(); - case S: ge("#voteskip").onclick(); - case C: ge("#getplaylist").onclick(); - case F: ge("#fullscreenbtn").onclick(); - case L: main.toggleLeader(); + case R: + ge("#mediarefresh").onclick(); + case S: + ge("#voteskip").onclick(); + case C: + ge("#getplaylist").onclick(); + case F: + ge("#fullscreenbtn").onclick(); + case L: + main.toggleLeader(); case P: if (!main.isLeader()) { JsApi.once(SetLeader, event -> { @@ -290,7 +297,8 @@ class Buttons { }); } main.toggleLeader(); - default: return; + default: + return; } e.preventDefault(); } @@ -346,5 +354,4 @@ class Buttons { } else el.classList.remove("mobile-view"); } } - } diff --git a/src/client/IPlayer.hx b/src/client/IPlayer.hx index 7f626b1..903902e 100644 --- a/src/client/IPlayer.hx +++ b/src/client/IPlayer.hx @@ -1,12 +1,12 @@ package client; -import Types.VideoDataRequest; import Types.VideoData; +import Types.VideoDataRequest; import Types.VideoItem; interface IPlayer { function isSupportedLink(url:String):Bool; - function getVideoData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void; + function getVideoData(data:VideoDataRequest, callback:(data:VideoData) -> Void):Void; function loadVideo(item:VideoItem):Void; function removeVideo():Void; function isVideoLoaded():Bool; diff --git a/src/client/InputWithHistory.hx b/src/client/InputWithHistory.hx index c4e8bf4..e7dfe83 100644 --- a/src/client/InputWithHistory.hx +++ b/src/client/InputWithHistory.hx @@ -1,19 +1,20 @@ package client; -import js.html.KeyboardEvent; import js.html.InputElement; +import js.html.KeyboardEvent; class InputWithHistory { - final element:InputElement; final maxItems:Int; final history:Array; - final onEnter:(value:String)->Bool; + final onEnter:(value:String) -> Bool; var historyId = -1; public function new( - element:InputElement, ?history:Array, maxItems:Int, - onEnter:(value:String)->Bool + element:InputElement, + ?history:Array, + maxItems:Int, + onEnter:(value:String) -> Bool ) { this.element = element; if (history != null) this.history = history; @@ -65,5 +66,4 @@ class InputWithHistory { function onInput():Void { if (element.oninput != null) element.oninput(); } - } diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx index a236570..4d98478 100644 --- a/src/client/JsApi.hx +++ b/src/client/JsApi.hx @@ -1,18 +1,18 @@ package client; -import Types.WsEventType; -import Types.WsEvent; import Types.VideoItem; +import Types.WsEvent; +import Types.WsEventType; import js.Browser.document; import js.Browser.window; import js.Syntax; + using StringTools; -private typedef VideoChangeFunc = (item:VideoItem)->Void; -private typedef OnceEventFunc = (event:WsEvent)->Void; +private typedef VideoChangeFunc = (item:VideoItem) -> Void; +private typedef OnceEventFunc = (event:WsEvent) -> Void; class JsApi { - static var main:Main; static var player:Player; static final subtitleFormats = []; @@ -32,7 +32,7 @@ class JsApi { } @:expose - static function addPlugin(id:String, ?onLoaded:()->Void):Void { + static function addPlugin(id:String, ?onLoaded:() -> Void):Void { addScriptToHead('/plugins/$id/index.js', () -> { final obj = { api: Syntax.plainCode("client.JsApi"), @@ -49,7 +49,7 @@ class JsApi { } @:expose - public static function addScriptToHead(url:String, ?onLoaded:()->Void):Void { + public static function addScriptToHead(url:String, ?onLoaded:() -> Void):Void { final script = document.createScriptElement(); script.type = "text/javascript"; script.onload = onLoaded; @@ -176,7 +176,9 @@ class JsApi { } public static function fireVideoChangeEvents(item:VideoItem):Void { - for (func in videoChange) func(item); + for (func in videoChange) { + func(item); + } } @:expose @@ -190,7 +192,8 @@ class JsApi { } public static function fireVideoRemoveEvents(item:VideoItem):Void { - for (func in videoRemove) func(item); + for (func in videoRemove) { + func(item); + } } - } diff --git a/src/client/Main.hx b/src/client/Main.hx index 1d9ac34..e9cda39 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -1,39 +1,41 @@ package client; -import haxe.crypto.Sha256; -import haxe.Timer; -import haxe.Json; -import js.html.MouseEvent; -import js.html.KeyboardEvent; -import js.html.Event; -import js.html.Element; -import js.html.VideoElement; -import js.html.InputElement; -import js.html.ButtonElement; -import js.html.WebSocket; -import js.Browser; -import js.Browser.document; -import js.Browser.window; import Client.ClientData; -import Types.VideoDataRequest; -import Types.VideoData; +import Client.ClientGroup; import Types.Config; import Types.Permission; -import Client.ClientGroup; +import Types.VideoData; +import Types.VideoDataRequest; import Types.WsEvent; -using StringTools; +import haxe.Json; +import haxe.Timer; +import haxe.crypto.Sha256; +import js.Browser.document; +import js.Browser.window; +import js.Browser; +import js.html.ButtonElement; +import js.html.Element; +import js.html.Event; +import js.html.InputElement; +import js.html.KeyboardEvent; +import js.html.MouseEvent; +import js.html.VideoElement; +import js.html.WebSocket; + using ClientTools; +using StringTools; class Main { - static inline var SETTINGS_VERSION = 2; + public final settings:ClientSettings; public var isSyncActive = true; public var forceSyncNextTick = false; - final clients:Array = []; - var pageTitle = document.title; public final host:String; public var globalIp(default, null) = ""; + + final clients:Array = []; + var pageTitle = document.title; var config:Null; final filters:Array<{regex:EReg, replace:String}> = []; var personal = new Client("Unknown", 0); @@ -43,7 +45,9 @@ class Main { var onTimeGet:Timer; var onBlinkTab:Null; - static function main():Void new Main(); + static function main():Void { + new Main(); + } function new() { player = new Player(this); @@ -162,8 +166,7 @@ class Main { e.preventDefault(); } } - ge("#customembed-content").onkeydown = - ge("#customembed-title").onkeydown; + ge("#customembed-content").onkeydown = ge("#customembed-title").onkeydown; } public inline function isUser():Bool { @@ -242,7 +245,7 @@ class Main { addVideo(link, atEnd, isTemp, () -> addVideoArray(links, atEnd, isTemp)); } - public function addVideo(url:String, atEnd:Bool, isTemp:Bool, ?callback:()->Void):Void { + public function addVideo(url:String, atEnd:Bool, isTemp:Bool, ?callback:() -> Void):Void { final protocol = Browser.location.protocol; if (url.startsWith("/")) { final host = Browser.location.hostname; @@ -263,7 +266,8 @@ class Main { if (data.title == null) data.title = Lang.get("rawVideo"); if (data.url == null) data.url = url; send({ - type: AddVideo, addVideo: { + type: AddVideo, + addVideo: { item: { url: data.url, title: data.title, @@ -274,7 +278,8 @@ class Main { isIframe: data.isIframe == true }, atEnd: atEnd - }}); + } + }); if (callback != null) callback(); }); } @@ -302,7 +307,8 @@ class Main { if (data.title == null) data.title = "Custom Media"; if (data.url == null) data.url = iframe; send({ - type: AddVideo, addVideo: { + type: AddVideo, + addVideo: { item: { url: data.url, title: data.title, @@ -312,13 +318,15 @@ class Main { isIframe: true }, atEnd: atEnd - }}); + } + }); }); } public function removeVideoItem(url:String) { send({ - type: RemoveVideo, removeVideo: { + type: RemoveVideo, + removeVideo: { url: url } }); @@ -343,7 +351,8 @@ class Main { public function getPlaylistLinks():Array { final items = player.getItems(); return [ - for (item in items) item.url + for (item in items) + item.url ]; } @@ -556,7 +565,8 @@ class Main { public function guestLogin(name:String):Void { if (name.length == 0) return; send({ - type: Login, login: { + type: Login, + login: { clientName: name } }); @@ -576,7 +586,8 @@ class Main { public function loginRequest(name:String, hash:String):Void { send({ - type: Login, login: { + type: Login, + login: { clientName: name, passHash: hash } @@ -769,7 +780,9 @@ class Main { userDiv.appendChild(textDiv); msgBuf.appendChild(userDiv); if (isInChatEnd) { - while (msgBuf.children.length > 200) msgBuf.removeChild(msgBuf.firstChild); + while (msgBuf.children.length > 200) { + msgBuf.removeChild(msgBuf.firstChild); + } msgBuf.scrollTop = msgBuf.scrollHeight; } if (name == personal.name) { @@ -813,9 +826,12 @@ class Main { if (isAdmin()) send({type: ClearChat}); } if (matchNumbers.match(text)) { - send({type: Rewind, rewind: { - time: Std.parseInt(text) - }}); + send({ + type: Rewind, + rewind: { + time: Std.parseInt(text) + } + }); } } @@ -824,9 +840,11 @@ class Main { if (onBlinkTab != null) onBlinkTab.stop(); onBlinkTab = new Timer(1000); onBlinkTab.run = () -> { - if (document.title.startsWith(pageTitle)) + if (document.title.startsWith(pageTitle)) { document.title = title; - else document.title = getPageTitle(); + } else { + document.title = getPageTitle(); + } } onBlinkTab.run(); } @@ -912,5 +930,4 @@ class Main { public static inline function ge(id:String):Element { return document.querySelector(id); } - } diff --git a/src/client/Player.hx b/src/client/Player.hx index c9b379c..ac5c986 100644 --- a/src/client/Player.hx +++ b/src/client/Player.hx @@ -1,18 +1,18 @@ package client; -import js.html.Element; +import Types.VideoData; +import Types.VideoDataRequest; +import Types.VideoItem; import client.Main.ge; +import client.players.Iframe; import client.players.Raw; import client.players.Youtube; -import client.players.Iframe; -import Types.VideoDataRequest; -import Types.VideoData; -import Types.VideoItem; -using StringTools; +import js.html.Element; + using Lambda; +using StringTools; class Player { - final main:Main; final players:Array; final iframePlayer:IPlayer; @@ -44,21 +44,24 @@ class Player { final i = Utils.getIndex(item.parentElement, item); if (btn.classList.contains("qbtn-play")) { main.send({ - type: PlayItem, playItem: { + type: PlayItem, + playItem: { pos: i } }); } if (btn.classList.contains("qbtn-next")) { main.send({ - type: SetNextItem, setNextItem: { + type: SetNextItem, + setNextItem: { pos: i } }); } if (btn.classList.contains("qbtn-tmp")) { main.send({ - type: ToggleItemType, toggleItemType: { + type: ToggleItemType, + toggleItemType: { pos: i } }); @@ -94,7 +97,7 @@ class Player { player = newPlayer; } - public function getVideoData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { + public function getVideoData(data:VideoDataRequest, callback:(data:VideoData) -> Void):Void { var player = players.find(player -> player.isSupportedLink(data.url)); if (player == null) player = rawPlayer; player.getVideoData(data, callback); @@ -104,7 +107,7 @@ class Player { return !players.exists(player -> player.isSupportedLink(url)); } - public function getIframeData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { + public function getIframeData(data:VideoDataRequest, callback:(data:VideoData) -> Void):Void { iframePlayer.getVideoData(data, callback); } @@ -167,7 +170,8 @@ class Player { public function onPlay():Void { if (!main.isLeader()) return; main.send({ - type: Play, play: { + type: Play, + play: { time: getTime() } }); @@ -184,7 +188,8 @@ class Player { final name = event.setLeader.clientName; if (name != main.getName()) return; main.send({ - type: Pause, pause: { + type: Pause, + pause: { time: getTime() } }); @@ -195,7 +200,8 @@ class Player { } if (!main.isLeader()) return; main.send({ - type: Pause, pause: { + type: Pause, + pause: { time: getTime() } }); @@ -208,7 +214,8 @@ class Player { } if (!main.isLeader()) return; main.send({ - type: SetTime, setTime: { + type: SetTime, + setTime: { time: getTime() } }); @@ -221,7 +228,8 @@ class Player { } if (!main.isLeader()) return; main.send({ - type: SetRate, setRate: { + type: SetRate, + setRate: { rate: getPlaybackRate() } }); @@ -307,7 +315,9 @@ class Player { clearItems(); if (pos != null) itemPos = pos; if (list.length == 0) return; - for (video in list) addVideoItem(video, true); + for (video in list) { + addVideoItem(video, true); + } if (currentUrl != items[itemPos].url) setVideo(itemPos); else videoItemsEl.children[itemPos].classList.add("queue_active"); } @@ -417,5 +427,4 @@ class Player { skipSetRate = isLocal; player.setPlaybackRate(rate); } - } diff --git a/src/client/Settings.hx b/src/client/Settings.hx index 47d67fc..2090829 100644 --- a/src/client/Settings.hx +++ b/src/client/Settings.hx @@ -1,14 +1,13 @@ package client; import haxe.Json; -import js.html.Storage; import js.Browser; +import js.html.Storage; private typedef Vers = {version:Int}; -private typedef Updater = (data:Any, version:Int)->Any; +private typedef Updater = (data:Any, version:Int) -> Any; class Settings { - static var defaults:Null; static var updater:Null; static var storage:Storage; @@ -61,5 +60,4 @@ class Settings { if (defaults == null) throw "reset: default data is null"; write(defaults); } - } diff --git a/src/client/Utils.hx b/src/client/Utils.hx index 00a26fe..de6b16c 100644 --- a/src/client/Utils.hx +++ b/src/client/Utils.hx @@ -1,11 +1,10 @@ package client; -import js.html.Element; import js.Browser.document; import js.Browser.window; +import js.html.Element; class Utils { - public static function isTouch():Bool { return js.Syntax.code("'ontouchstart' in window"); } @@ -37,11 +36,8 @@ class Utils { public static function hasFullscreen():Bool { final doc:Dynamic = document; - return ( - document.fullscreenElement != null - || doc.mozFullScreenElement != null - || doc.webkitFullscreenElement != null - ); + return (document.fullscreenElement != null || doc.mozFullScreenElement != null + || doc.webkitFullscreenElement != null); } public static function requestFullscreen(el:Element):Bool { @@ -91,5 +87,4 @@ class Utils { document.body.removeChild(textarea); } } - } diff --git a/src/client/players/Iframe.hx b/src/client/players/Iframe.hx index ae37c94..e07f814 100644 --- a/src/client/players/Iframe.hx +++ b/src/client/players/Iframe.hx @@ -1,14 +1,13 @@ package client.players; -import js.html.Element; -import js.Browser.document; -import client.Main.ge; -import Types.VideoDataRequest; import Types.VideoData; +import Types.VideoDataRequest; import Types.VideoItem; +import client.Main.ge; +import js.Browser.document; +import js.html.Element; class Iframe implements IPlayer { - final main:Main; final player:Player; final playerEl:Element = ge("#ytapiplayer"); @@ -23,7 +22,7 @@ class Iframe implements IPlayer { return true; } - public function getVideoData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { + public function getVideoData(data:VideoDataRequest, callback:(data:VideoData) -> Void):Void { final iframe = document.createDivElement(); iframe.innerHTML = data.url; if (isValidIframe(iframe)) { @@ -35,8 +34,7 @@ class Iframe implements IPlayer { function isValidIframe(iframe:Element):Bool { if (iframe.children.length != 1) return false; - return (iframe.firstChild.nodeName == "IFRAME" - || iframe.firstChild.nodeName == "OBJECT"); + return (iframe.firstChild.nodeName == "IFRAME" || iframe.firstChild.nodeName == "OBJECT"); } public function loadVideo(item:VideoItem):Void { @@ -79,5 +77,4 @@ class Iframe implements IPlayer { } public function setPlaybackRate(rate:Float):Void {} - } diff --git a/src/client/players/Raw.hx b/src/client/players/Raw.hx index cafe147..ea51e97 100644 --- a/src/client/players/Raw.hx +++ b/src/client/players/Raw.hx @@ -1,19 +1,19 @@ package client.players; -import js.hlsjs.Hls; +import Types.VideoData; +import Types.VideoDataRequest; +import Types.VideoItem; +import client.Main.ge; import haxe.Timer; +import js.Browser.document; +import js.hlsjs.Hls; import js.html.Element; import js.html.InputElement; import js.html.VideoElement; -import js.Browser.document; -import client.Main.ge; -import Types.VideoDataRequest; -import Types.VideoData; -import Types.VideoItem; + using StringTools; class Raw implements IPlayer { - final main:Main; final player:Player; final playerEl:Element = ge("#ytapiplayer"); @@ -34,7 +34,7 @@ class Raw implements IPlayer { return true; } - public function getVideoData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { + public function getVideoData(data:VideoDataRequest, callback:(data:VideoData) -> Void):Void { final url = data.url; final decodedUrl = url.urlDecode(); @@ -77,7 +77,7 @@ class Raw implements IPlayer { if (isHls) initHlsSource(video, url); } - function loadHlsPlugin(callback:()->Void):Void { + function loadHlsPlugin(callback:() -> Void):Void { final url = "https://cdn.jsdelivr.net/npm/hls.js@latest"; JsApi.addScriptToHead(url, () -> { isHlsLoaded = true; @@ -177,5 +177,4 @@ class Raw implements IPlayer { public function setPlaybackRate(rate:Float):Void { video.playbackRate = rate; } - } diff --git a/src/client/players/Youtube.hx b/src/client/players/Youtube.hx index e63a095..d4db8ed 100644 --- a/src/client/players/Youtube.hx +++ b/src/client/players/Youtube.hx @@ -1,19 +1,19 @@ package client.players; -import haxe.Json; +import Types.VideoData; +import Types.VideoDataRequest; +import Types.VideoItem; +import client.Main.ge; import haxe.Http; -import js.html.Element; +import haxe.Json; import js.Browser.document; -import client.Main.ge; +import js.html.Element; import js.youtube.Youtube as YtInit; import js.youtube.YoutubePlayer; -import Types.VideoDataRequest; -import Types.VideoData; -import Types.VideoItem; + using StringTools; class Youtube implements IPlayer { - final matchId = ~/youtube\.com.*v=([A-z0-9_-]+)/; final matchShort = ~/youtu\.be\/([A-z0-9_-]+)/; final matchEmbed = ~/youtube\.com\/embed\/([A-z0-9_-]+)/; @@ -73,7 +73,7 @@ class Youtube implements IPlayer { return total; } - public function getVideoData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { + public function getVideoData(data:VideoDataRequest, callback:(data:VideoData) -> Void):Void { final url = data.url; if (apiKey == null) apiKey = main.getYoutubeApiKey(); final id = extractVideoId(url); @@ -122,7 +122,7 @@ class Youtube implements IPlayer { http.request(); } - function getPlaylistVideoData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { + function getPlaylistVideoData(data:VideoDataRequest, callback:(data:VideoData) -> Void):Void { final url = data.url; final id = extractPlaylistId(url); var maxResults = main.getYoutubePlaylistLimit(); @@ -174,7 +174,7 @@ class Youtube implements IPlayer { main.serverMessage(4, 'Error $code: $msg', false); } - function getRemoteDataFallback(url:String, callback:(data:VideoData)->Void):Void { + function getRemoteDataFallback(url:String, callback:(data:VideoData) -> Void):Void { if (!YtInit.isLoadedAPI) { YtInit.init(() -> getRemoteDataFallback(url, callback)); return; @@ -292,5 +292,4 @@ class Youtube implements IPlayer { public function setPlaybackRate(rate:Float):Void { youtube.setPlaybackRate(rate); } - } -- cgit v1.2.3