Skip to content

Commit

Permalink
Load Files and play to Clients
Browse files Browse the repository at this point in the history
  • Loading branch information
BytePhilHD committed Jun 3, 2021
1 parent 5aabc2a commit fb6ea5f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

<h3>Features</h3>

- [x] Config
- [x] Load Videos from Files Folder and play them to all Clients
- [ ] Password protected Rooms
- [ ] Video Playback
- [ ] Video Pause Function
- [ ] Room Chat

Expand Down
4 changes: 2 additions & 2 deletions src/de/bytephil/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void start() throws IOException {
App.getInstance().sessions1.add(ctx.getSessionId());
ctx.send("Client connects..");
sessionctx.put(ctx.getSessionId(), ctx);
ByteBuffer buf = ByteBuffer.wrap(convert("Files/TEST.MP4"));
ByteBuffer buf = ByteBuffer.wrap(convert("Files/Example.mp4")); //TODO Change this! If user has deleted it
ctx.send(buf);
}
});
Expand Down Expand Up @@ -242,7 +242,7 @@ public byte[] convert(String path) throws IOException {
Console.printout(e1.getMessage(), MessageType.ERROR);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
byte[] b = new byte[4096];

for (int readNum; (readNum = fis.read(b)) != -1;) {
bos.write(b, 0, readNum);
Expand Down
15 changes: 14 additions & 1 deletion src/de/bytephil/utils/Console.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package de.bytephil.utils;

import de.bytephil.app.App;
import io.javalin.websocket.WsConnectContext;
import jline.console.ConsoleReader;
import org.eclipse.jetty.websocket.api.Session;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Objects;

Expand Down Expand Up @@ -38,7 +41,17 @@ public static void input() throws IOException {
} else {
String fileName = input.replace(" ", "").replace("load", "");
printout("Trying to load File \"" + fileName + "\"...", MessageType.INFO);
App.getInstance().convert("Files/" + fileName);
ByteBuffer buf = ByteBuffer.wrap(App.getInstance().convert("Files/" + fileName));
int clients = App.getInstance().sessionHashMap.size();
Console.printout("Sending loaded Video to all " + clients + " connected Clients!", MessageType.INFO);

for (int i = 0; i < clients; i++) {
String sessionid = App.getInstance().sessions1.get(i);
WsConnectContext session = App.getInstance().sessionctx.get(sessionid);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
session.send(buf);
//session.send("Aktuelle Zeit: " + ZonedDateTime.now(ZoneId.of("Europe/Berlin")).format(DateTimeFormatter.ofPattern("HH:mm:ss")));
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/resources/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<section class="clean-block clean-hero" style="background-image:url(&quot;assets/img/tech/image4.jpg&quot;);color:rgba(9, 162, 255, 0.85);">
<div class="text">
<h2>TestWebsite - UploadServer.jar</h2>
<p>Hier werden Dinge getestet!</p><img id="webanswer"></img>
<p>Hier werden Dinge getestet!</p><video id="webanswer" autoplay></video>
<!-- <p id="webanswer"></p> -->
<button class="btn btn-outline-light btn-lg" onclick="window.location.href='/testpage'">Learn More</button>
</div>
Expand Down

0 comments on commit fb6ea5f

Please sign in to comment.