shivam413 commited on
Commit
8ef004b
·
verified ·
1 Parent(s): eefa1ea

Update pages/api/socketio.ts

Browse files
Files changed (1) hide show
  1. pages/api/socketio.ts +19 -0
pages/api/socketio.ts CHANGED
@@ -309,6 +309,25 @@ const ioHandler = (_: NextApiRequest, res: NextApiResponse) => {
309
  await broadcast(room)
310
  })
311
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
  socket.on("fetch", async () => {
313
  const room = await getRoom(roomId)
314
  if (room === null) {
 
309
  await broadcast(room)
310
  })
311
 
312
+ // Add a URL to playlist without immediate playback
313
+ socket.on("addToPlaylist", async (url) => {
314
+ const room = await getRoom(roomId)
315
+ if (room === null) {
316
+ throw new Error(
317
+ "Impossible non existing room, cannot add to playlist:" + roomId
318
+ )
319
+ }
320
+ if (!isUrl(url)) return log("addToPlaylist invalid url", url)
321
+ log("add to playlist", url)
322
+
323
+ room.targetState.playlist.items.push({
324
+ src: [{ src: url, resolution: "" }],
325
+ sub: [],
326
+ })
327
+
328
+ await broadcast(room)
329
+ })
330
+
331
  socket.on("fetch", async () => {
332
  const room = await getRoom(roomId)
333
  if (room === null) {