aboutsummaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2020-02-24 01:19:30 +0300
committerRblSb <msrblsb@gmail.com>2020-02-24 01:19:30 +0300
commitc561fb9e2e42e4968f2b48cd535f208e90f8c12c (patch)
tree0c7e1ffc99744aabbb240864b371b9555a611d92 /src/server
parent113b06e895f5dc752e8393c2a4f3f1669a7d0aab (diff)
More playlist and video control
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Main.hx42
-rw-r--r--src/server/Utils.hx11
2 files changed, 43 insertions, 10 deletions
diff --git a/src/server/Main.hx b/src/server/Main.hx
index cdf6924..e2b9b18 100644
--- a/src/server/Main.hx
+++ b/src/server/Main.hx
@@ -80,7 +80,7 @@ class Main {
final client = new Client(ws, id, name, 0);
if (isAdmin) client.group.set(Admin);
clients.push(client);
- if (clients.length == 1)
+ if (clients.length == 1 && videoList.length > 0)
if (videoTimer.isPaused()) videoTimer.play();
send(client, {
@@ -109,7 +109,10 @@ class Main {
if (client.isLeader) {
if (videoTimer.isPaused()) videoTimer.play();
}
- if (clients.length == 0) videoTimer.pause();
+ if (clients.length == 0) {
+ if (waitVideoStart != null) waitVideoStart.stop();
+ videoTimer.pause();
+ }
});
}
@@ -131,7 +134,8 @@ class Main {
sendClientList();
case Login:
final name = data.login.clientName;
- if (name.length == 0 || name.length > config.maxLoginLength || clients.getByName(name) != null) {
+ if (name.length == 0 || name.length > config.maxLoginLength
+ || clients.getByName(name) != null) {
send(client, {type: LoginError});
return;
}
@@ -172,12 +176,13 @@ class Main {
if (messages.length > config.serverChatHistory) messages.shift();
broadcast(data);
case AddVideo:
- videoList.push(data.addVideo.item);
+ if (data.addVideo.atEnd) videoList.push(data.addVideo.item);
+ else videoList.insert(1, data.addVideo.item);
broadcast(data);
- if (videoList.length == 1) {
- waitVideoStart = Timer.delay(startVideoPlayback, 3000);
- }
+ // Initial timer start if VideoLoaded is not happen
+ if (videoList.length == 1) restartWaitTimer();
case VideoLoaded:
+ // Called if client loads next video and can play it
prepareVideoPlayback();
case RemoveVideo:
if (videoList.length == 0) return;
@@ -187,6 +192,7 @@ class Main {
videoList.find(item -> item.url == url)
);
broadcast(data);
+ if (videoList.length > 0) restartWaitTimer();
case Pause:
if (videoList.length == 0) return;
if (!client.isLeader) return;
@@ -244,6 +250,19 @@ class Main {
}
case ClearChat:
if (client.isAdmin) broadcast(data);
+ case ClearPlaylist:
+ videoTimer.stop();
+ videoList.resize(0);
+ broadcast(data);
+ case ShufflePlaylist:
+ if (videoList.length == 0) return;
+ final first = videoList.shift();
+ Utils.shuffle(videoList);
+ videoList.unshift(first);
+ broadcast({type: UpdatePlaylist, updatePlaylist: {
+ videoList: videoList
+ }});
+ case UpdatePlaylist:
}
}
@@ -282,12 +301,15 @@ class Main {
var waitVideoStart:Timer;
var loadedClientsCount = 0;
+ function restartWaitTimer():Void {
+ if (waitVideoStart != null) waitVideoStart.stop();
+ waitVideoStart = Timer.delay(startVideoPlayback, 3000);
+ }
+
function prepareVideoPlayback():Void {
if (videoTimer.isStarted) return;
loadedClientsCount++;
- if (loadedClientsCount == 1) {
- waitVideoStart = Timer.delay(startVideoPlayback, 3000);
- }
+ if (loadedClientsCount == 1) restartWaitTimer();
if (loadedClientsCount >= clients.length) startVideoPlayback();
}
diff --git a/src/server/Utils.hx b/src/server/Utils.hx
index c3510c9..2ecbd42 100644
--- a/src/server/Utils.hx
+++ b/src/server/Utils.hx
@@ -27,4 +27,15 @@ class Utils {
}
return "127.0.0.1";
}
+
+ public static function shuffle<T>(arr:Array<T>):Void {
+ for (i in 0...arr.length) {
+ final n = Std.random(arr.length);
+ final a = arr[i];
+ final b = arr[n];
+ arr[i] = b;
+ arr[n] = a;
+ }
+ }
+
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage