aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2021-07-04 03:59:50 +0300
committerRblSb <msrblsb@gmail.com>2021-07-05 17:04:25 +0300
commitede45cea8706eb8540e466df9861c2af8ebf9c44 (patch)
tree74a20a6f082173378f918b48b08542881f31749a /src
parent265b3e1fb56bb0e5f797b3b35227a616b108a0c3 (diff)
Reformat
Diffstat (limited to 'src')
-rw-r--r--src/Client.hx13
-rw-r--r--src/ClientTools.hx4
-rw-r--r--src/Lang.hx10
-rw-r--r--src/VideoList.hx7
-rw-r--r--src/client/Buttons.hx43
-rw-r--r--src/client/IPlayer.hx4
-rw-r--r--src/client/InputWithHistory.hx12
-rw-r--r--src/client/JsApi.hx23
-rw-r--r--src/client/Main.hx97
-rw-r--r--src/client/Player.hx47
-rw-r--r--src/client/Settings.hx6
-rw-r--r--src/client/Utils.hx11
-rw-r--r--src/client/players/Iframe.hx15
-rw-r--r--src/client/players/Raw.hx19
-rw-r--r--src/client/players/Youtube.hx21
-rw-r--r--src/server/ConsoleInput.hx15
-rw-r--r--src/server/HttpServer.hx20
-rw-r--r--src/server/Logger.hx9
-rw-r--r--src/server/Main.hx114
-rw-r--r--src/server/ServerState.hx3
-rw-r--r--src/server/Utils.hx15
-rw-r--r--src/server/VideoTimer.hx3
22 files changed, 276 insertions, 235 deletions
diff --git a/src/Client.hx b/src/Client.hx
index c7bc256..254e294 100644
--- a/src/Client.hx
+++ b/src/Client.hx
@@ -18,7 +18,6 @@ typedef ClientData = {
}
class Client {
-
#if nodejs
public final ws:WebSocket;
public final id:Int;
@@ -33,17 +32,18 @@ class Client {
#if nodejs
public function new(?ws:WebSocket, ?req:IncomingMessage, ?id:Int, name:String, group:Int) {
- #else
- public function new(name:String, group:Int) {
- #end
- #if nodejs
this.ws = ws;
this.req = req;
this.id = id;
- #end
this.name = name;
this.group = new EnumFlags(group);
}
+ #else
+ public function new(name:String, group:Int) {
+ this.name = name;
+ this.group = new EnumFlags(group);
+ }
+ #end
inline function get_isUser():Bool {
return group.has(User);
@@ -85,5 +85,4 @@ class Client {
public static function fromData(data:ClientData):Client {
return new Client(data.name, data.group);
}
-
}
diff --git a/src/ClientTools.hx b/src/ClientTools.hx
index e83e450..b4ac9cb 100644
--- a/src/ClientTools.hx
+++ b/src/ClientTools.hx
@@ -1,10 +1,9 @@
package;
-import Types.Permissions;
import Types.Permission;
+import Types.Permissions;
class ClientTools {
-
public static function setLeader(clients:Array<Client>, name:String):Void {
for (client in clients) {
if (client.name == name) client.isLeader = true;
@@ -35,5 +34,4 @@ class ClientTools {
if (client.isUser) return p.user.contains(permission);
return p.guest.contains(permission);
}
-
}
diff --git a/src/Lang.hx b/src/Lang.hx
index 7b7642d..3bd6963 100644
--- a/src/Lang.hx
+++ b/src/Lang.hx
@@ -2,24 +2,25 @@ package;
import haxe.Json;
import haxe.io.Path;
+
+using Lambda;
+
#if (sys || nodejs)
import sys.io.File;
#else
import haxe.Http;
#end
-using Lambda;
private typedef LangMap = Map<String, String>;
class Lang {
-
static final langs:Map<String, LangMap> = [];
static var ids = ["en", "ru"];
#if (js && !nodejs)
static var lang = js.Browser.navigator.language.substr(0, 2).toLowerCase();
#end
- static function request(path:String, callback:(data:String)->Void):Void {
+ static function request(path:String, callback:(data:String) -> Void):Void {
#if (sys || nodejs)
callback(File.getContent(path));
#else
@@ -29,7 +30,7 @@ class Lang {
#end
}
- public static function init(folderPath:String, ?callback:()->Void):Void {
+ public static function init(folderPath:String, ?callback:() -> Void):Void {
#if (js && !nodejs)
// Filter unused languages
ids = ids.filter(id -> id == lang || id == "en");
@@ -64,5 +65,4 @@ class Lang {
return text == null ? key : text;
}
#end
-
}
diff --git a/src/VideoList.hx b/src/VideoList.hx
index 0799cfa..ef1d113 100644
--- a/src/VideoList.hx
+++ b/src/VideoList.hx
@@ -7,10 +7,8 @@ import Types.VideoItem;
// items:Array<VideoItem>,
// itemPos:Int
// }
-
@:forward
abstract VideoList(Array<VideoItem>) from Array<VideoItem> to Array<VideoItem> {
-
public function new() {
this = [];
}
@@ -68,8 +66,9 @@ abstract VideoList(Array<VideoItem>) from Array<VideoItem> to Array<VideoItem> {
public function itemsByUser(client:Client):Int {
var i = 0;
- for (item in this) if (item.author == client.name) i++;
+ for (item in this) {
+ if (item.author == client.name) i++;
+ }
return i;
}
-
}
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<String>;
- final onEnter:(value:String)->Bool;
+ final onEnter:(value:String) -> Bool;
var historyId = -1;
public function new(
- element:InputElement, ?history:Array<String>, maxItems:Int,
- onEnter:(value:String)->Bool
+ element:InputElement,
+ ?history:Array<String>,
+ 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<Client> = [];
- var pageTitle = document.title;
public final host:String;
public var globalIp(default, null) = "";
+
+ final clients:Array<Client> = [];
+ var pageTitle = document.title;
var config:Null<Config>;
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<Timer>;
- 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<String> {
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<IPlayer>;
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<Vers>;
static var updater:Null<Updater>;
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);
}
-
}
diff --git a/src/server/ConsoleInput.hx b/src/server/ConsoleInput.hx
index 3c287af..9b8faf3 100644
--- a/src/server/ConsoleInput.hx
+++ b/src/server/ConsoleInput.hx
@@ -1,13 +1,14 @@
package server;
+import haxe.Json;
import haxe.extern.EitherType as Or;
import haxe.io.Path;
-import haxe.Json;
-import sys.FileSystem;
-import sys.io.File;
+import js.Node.process;
import js.html.Console;
import js.node.Readline;
-import js.Node.process;
+import sys.FileSystem;
+import sys.io.File;
+
using StringTools;
private typedef CommandData = {
@@ -23,7 +24,6 @@ private enum abstract Command(String) from String {
}
class ConsoleInput {
-
final main:Main;
final commands:Map<Command, CommandData> = [
AddAdmin => {
@@ -118,7 +118,9 @@ class ConsoleInput {
Utils.ensureDir(main.logsDir);
final names = FileSystem.readDirectory(main.logsDir)
.filter(s -> s.endsWith(".json"));
- for (name in names) trace(Path.withoutExtension(name));
+ for (name in names) {
+ trace(Path.withoutExtension(name));
+ }
case Exit:
main.exit();
@@ -150,5 +152,4 @@ class ConsoleInput {
final desc = list.join("\n");
trace('Unknown command "$line". List:\n$desc');
}
-
}
diff --git a/src/server/HttpServer.hx b/src/server/HttpServer.hx
index 46540a3..64962dc 100644
--- a/src/server/HttpServer.hx
+++ b/src/server/HttpServer.hx
@@ -1,20 +1,20 @@
package server;
-import sys.FileSystem;
-import js.node.Buffer;
import haxe.io.Path;
+import js.node.Buffer;
import js.node.Fs;
-import js.node.Https;
import js.node.Http;
-import js.node.url.URL;
+import js.node.Https;
+import js.node.Path as JsPath;
+import js.node.http.ClientRequest;
import js.node.http.IncomingMessage;
import js.node.http.ServerResponse;
-import js.node.http.ClientRequest;
-import js.node.Path as JsPath;
+import js.node.url.URL;
+import sys.FileSystem;
+
using StringTools;
class HttpServer {
-
static final mimeTypes = [
"html" => "text/html",
"js" => "text/javascript",
@@ -58,7 +58,8 @@ class HttpServer {
res.setHeader("Accept-Ranges", "bytes");
res.setHeader("Content-Type", getMimeType(ext));
- if (allowLocalRequests && req.connection.remoteAddress == req.connection.localAddress
+ if (allowLocalRequests
+ && req.connection.remoteAddress == req.connection.localAddress
|| allowedLocalFiles[url]) {
if (isMediaExtension(ext)) {
allowedLocalFiles[url] = true;
@@ -176,7 +177,7 @@ class HttpServer {
static function proxyRequest(
url:String, req:IncomingMessage, res:ServerResponse,
- fn:(req:IncomingMessage)->Bool
+ fn:(req:IncomingMessage) -> Bool
):Null<ClientRequest> {
final url = try {
new URL(js.Node.global.decodeURI(url));
@@ -211,5 +212,4 @@ class HttpServer {
if (contentType == null) return "application/octet-stream";
return contentType;
}
-
}
diff --git a/src/server/Logger.hx b/src/server/Logger.hx
index 9ff4c34..cd96d1b 100644
--- a/src/server/Logger.hx
+++ b/src/server/Logger.hx
@@ -1,14 +1,14 @@
package server;
-import haxe.io.Path;
-import sys.io.File;
import haxe.Json;
+import haxe.io.Path;
import sys.FileSystem;
-using StringTools;
+import sys.io.File;
+
using Lambda;
+using StringTools;
class Logger {
-
final folder:String;
final maxCount:Int;
final verbose:Bool;
@@ -65,5 +65,4 @@ class Logger {
final s = '${d[0]}-${d[1]}-${d[2]} ${t[0]}:${t[1]}:${t[2]}';
return Date.fromString(s);
}
-
}
diff --git a/src/server/Main.hx b/src/server/Main.hx
index d93c2e5..ea1e40b 100644
--- a/src/server/Main.hx
+++ b/src/server/Main.hx
@@ -1,41 +1,44 @@
package server;
-import haxe.crypto.Sha256;
-import sys.FileSystem;
-import sys.io.File;
-import haxe.Timer;
-import haxe.Json;
-import js.Node.process;
-import js.Node.__dirname;
-import js.npm.ws.Server as WSServer;
-import js.npm.ws.WebSocket;
-import js.node.http.IncomingMessage;
-import js.node.Http;
-import json2object.JsonParser;
-import json2object.ErrorUtils;
import Client.ClientData;
import Types.Config;
+import Types.Message;
import Types.Permission;
import Types.UserList;
-import Types.Message;
import Types.WsEvent;
-using StringTools;
+import haxe.Json;
+import haxe.Timer;
+import haxe.crypto.Sha256;
+import js.Node.__dirname;
+import js.Node.process;
+import js.node.Http;
+import js.node.http.IncomingMessage;
+import js.npm.ws.Server as WSServer;
+import js.npm.ws.WebSocket;
+import json2object.ErrorUtils;
+import json2object.JsonParser;
+import sys.FileSystem;
+import sys.io.File;
+
using ClientTools;
using Lambda;
+using StringTools;
class Main {
-
static inline var VIDEO_START_MAX_DELAY = 3000;
static inline var VIDEO_SKIP_DELAY = 1000;
+
final rootDir = '$__dirname/..';
+
public final logsDir:String;
+ public final config:Config;
+
final verbose:Bool;
final statePath:String;
var wss:WSServer;
final localIp:String;
var globalIp:String;
var port:Int;
- public final config:Config;
final userList:UserList;
final clients:Array<Client> = [];
final freeIds:Array<Int> = [];
@@ -48,7 +51,9 @@ class Main {
var isPlaylistOpen = true;
var itemPos = 0;
- static function main():Void new Main();
+ static function main():Void {
+ new Main();
+ }
function new() {
verbose = Sys.args().has("--verbose");
@@ -87,8 +92,8 @@ class Main {
var attempts = 5;
function preparePort():Void {
- Utils.isPortFree(port, free -> {
- if (!free && attempts > 0) {
+ Utils.isPortFree(port, isFree -> {
+ if (!isFree && attempts > 0) {
trace('Warning: port $port is already in use. Changed to ${port + 1}');
attempts--;
port++;
@@ -138,8 +143,9 @@ class Main {
}
function generateConfigSalt():String {
- if (userList.salt == null)
+ if (userList.salt == null) {
userList.salt = Sha256.encode('${Math.random()}');
+ }
return userList.salt;
}
@@ -155,7 +161,9 @@ class Main {
if (type == field) continue;
if (group.indexOf(type) == -1) continue;
group.remove(type);
- for (item in getPermissions(type)) group.push(item);
+ for (item in getPermissions(type)) {
+ group.push(item);
+ }
}
}
return config;
@@ -167,7 +175,9 @@ class Main {
if (!FileSystem.exists(customPath)) return config;
final customConfig:Config = Json.parse(File.getContent(customPath));
for (field in Reflect.fields(customConfig)) {
- if (Reflect.field(config, field) == null) trace('Warning: config field "$field" is unknown');
+ if (Reflect.field(config, field) == null) {
+ trace('Warning: config field "$field" is unknown');
+ }
Reflect.setField(config, field, Reflect.field(customConfig, field));
}
final emoteCopies:Map<String, Bool> = [];
@@ -175,7 +185,9 @@ class Main {
if (emoteCopies[emote.name]) trace('Warning: emote name "${emote.name}" has copy');
emoteCopies[emote.name] = true;
if (!verbose) continue;
- if (emoteCopies[emote.image]) trace('Warning: emote url of name "${emote.name}" has copy');
+ if (emoteCopies[emote.image]) {
+ trace('Warning: emote url of name "${emote.name}" has copy');
+ }
emoteCopies[emote.image] = true;
}
return config;
@@ -218,10 +230,14 @@ class Main {
final data:ServerState = Json.parse(File.getContent(statePath));
videoList.resize(0);
messages.resize(0);
- for (item in data.videoList) videoList.push(item);
+ for (item in data.videoList) {
+ videoList.push(item);
+ }
isPlaylistOpen = data.isPlaylistOpen;
itemPos = data.itemPos;
- for (message in data.messages) messages.push(message);
+ for (message in data.messages) {
+ messages.push(message);
+ }
videoTimer.start();
videoTimer.setTime(data.timer.time);
videoTimer.pause();
@@ -346,8 +362,9 @@ class Main {
switch (data.type) {
case Connected:
if (!internal) return;
- if (clients.length == 1 && videoList.length > 0)
+ if (clients.length == 1 && videoList.length > 0) {
if (videoTimer.isPaused()) videoTimer.play();
+ }
send(client, {
type: Connected,
@@ -381,7 +398,8 @@ class Main {
Timer.delay(() -> {
if (clients.exists(i -> i.name == client.name)) return;
broadcast({
- type: ServerMessage, serverMessage: {
+ type: ServerMessage,
+ serverMessage: {
textId: '${client.name} has left'
}
});
@@ -405,8 +423,9 @@ class Main {
}
} else {
if (userList.admins.exists(
- a -> a.name.toLowerCase() == lcName && a.hash == hash
- )) client.isAdmin = true;
+ a -> a.name.toLowerCase() == lcName && a.hash == hash)) {
+ client.isAdmin = true;
+ }
else {
serverMessage(client, "passwordMatchError");
send(client, {type: LoginError});
@@ -462,8 +481,7 @@ class Main {
if (!isPlaylistOpen) {
if (!checkPermission(client, LockPlaylistPerm)) return;
}
- if (config.totalVideoLimit != 0
- && videoList.length >= config.totalVideoLimit) {
+ if (config.totalVideoLimit != 0 && videoList.length >= config.totalVideoLimit) {
serverMessage(client, "totalVideoLimitError");
return;
}
@@ -540,7 +558,8 @@ class Main {
if (videoList.length != currentLength) return;
if (itemPos != currentPos) return;
skipVideo({
- type: SkipVideo, skipVideo: {
+ type: SkipVideo,
+ skipVideo: {
url: videoList[itemPos].url
}
});
@@ -548,7 +567,8 @@ class Main {
return;
}
final obj:WsEvent = {
- type: GetTime, getTime: {
+ type: GetTime,
+ getTime: {
time: videoTimer.getTime()
}
};
@@ -588,7 +608,8 @@ class Main {
}
clients.setLeader(clientName);
broadcast({
- type: SetLeader, setLeader: {
+ type: SetLeader,
+ setLeader: {
clientName: clientName
}
});
@@ -597,7 +618,8 @@ class Main {
if (videoTimer.isPaused()) videoTimer.play();
videoTimer.setRate(1);
broadcast({
- type: Play, play: {
+ type: Play,
+ play: {
time: videoTimer.getTime()
}
});
@@ -643,15 +665,17 @@ class Main {
broadcast({
type: UpdatePlaylist,
updatePlaylist: {
- videoList: videoList
- }});
+ videoList: videoList
+ }
+ });
case UpdatePlaylist:
broadcast({
type: UpdatePlaylist,
updatePlaylist: {
- videoList: videoList
- }});
+ videoList: videoList
+ }
+ });
case TogglePlaylistLock:
if (!checkPermission(client, LockPlaylistPerm)) return;
@@ -691,7 +715,8 @@ class Main {
function serverMessage(client:Client, textId:String):Void {
send(client, {
- type: ServerMessage, serverMessage: {
+ type: ServerMessage,
+ serverMessage: {
textId: textId
}
});
@@ -703,7 +728,8 @@ class Main {
function broadcast(data:WsEvent):Void {
final json = Json.stringify(data);
- for (client in clients) client.ws.send(json, null);
+ for (client in clients)
+ client.ws.send(json, null);
}
function broadcastExcept(skipped:Client, data:WsEvent):Void {
@@ -726,7 +752,8 @@ class Main {
function checkPermission(client:Client, perm:Permission):Bool {
final state = client.hasPermission(perm, config.permissions);
if (!state) send(client, {
- type: ServerMessage, serverMessage: {
+ type: ServerMessage,
+ serverMessage: {
textId: "accessError"
}
});
@@ -767,5 +794,4 @@ class Main {
broadcast({type: VideoLoaded});
videoTimer.start();
}
-
}
diff --git a/src/server/ServerState.hx b/src/server/ServerState.hx
index 9c8d751..4ccdd44 100644
--- a/src/server/ServerState.hx
+++ b/src/server/ServerState.hx
@@ -9,7 +9,6 @@ typedef ServerState = {
itemPos:Int,
messages:Array<Message>,
timer:{
- time:Float,
- paused:Bool
+ time:Float, paused:Bool
}
}
diff --git a/src/server/Utils.hx b/src/server/Utils.hx
index bab6300..9aa0d66 100644
--- a/src/server/Utils.hx
+++ b/src/server/Utils.hx
@@ -1,18 +1,17 @@
package server;
-import js.node.url.URL;
-import js.node.Https;
import js.node.Http;
+import js.node.Https;
import js.node.Os;
+import js.node.url.URL;
import sys.FileSystem;
class Utils {
-
public static function ensureDir(path:String):Void {
if (!FileSystem.exists(path)) FileSystem.createDirectory(path);
}
- public static function isPortFree(port:Int, callback:(free:Bool)->Void):Void {
+ public static function isPortFree(port:Int, callback:(isFree:Bool) -> Void):Void {
final server = Http.createServer();
final timeout = 1000;
var status = false;
@@ -22,7 +21,7 @@ class Utils {
status = false;
server.close();
});
- server.once("timeout", function () {
+ server.once("timeout", function() {
status = false;
trace('Timeout (${timeout}ms) occurred waiting for port $port to be available');
server.close();
@@ -35,7 +34,7 @@ class Utils {
server.listen(port);
}
- public static function getGlobalIp(callback:(ip:String)->Void):Void {
+ public static function getGlobalIp(callback:(ip:String) -> Void):Void {
function onError(e):Void {
trace("Warning: connection error, server is local.");
callback("127.0.0.1");
@@ -51,8 +50,7 @@ class Utils {
final data = new StringBuf();
r.on("data", chunk -> data.add(chunk));
r.on("end", _ -> callback(data.toString()));
- }).on("error", onError)
- .on("timeout", onError);
+ }).on("error", onError).on("timeout", onError);
}
public static function getLocalIp():String {
@@ -89,5 +87,4 @@ class Utils {
arr[n] = a;
}
}
-
}
diff --git a/src/server/VideoTimer.hx b/src/server/VideoTimer.hx
index 53d4e28..2dd6720 100644
--- a/src/server/VideoTimer.hx
+++ b/src/server/VideoTimer.hx
@@ -3,8 +3,8 @@ package server;
import haxe.Timer.stamp;
class VideoTimer {
-
public var isStarted(default, null) = false;
+
var startTime = 0.0;
var pauseStartTime = 0.0;
var rateStartTime = 0.0;
@@ -75,5 +75,4 @@ class VideoTimer {
if (rateStartTime == 0) return 0;
return stamp() - rateStartTime - pauseTime();
}
-
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage