shivam413 commited on
Commit
ba39e7b
·
verified ·
1 Parent(s): deb2808

Delete lib/sockets.ts

Browse files
Files changed (1) hide show
  1. lib/sockets.ts +0 -85
lib/sockets.ts DELETED
@@ -1,85 +0,0 @@
1
- import {
2
- MediaElement,
3
- PlayerState,
4
- Playlist,
5
- RoomState,
6
- UserState,
7
- ChatMessage,
8
- } from "./types"
9
- import io, { Socket } from "socket.io-client"
10
-
11
- export interface ServerToClientEvents {
12
- playlistUpdate: (playlist: Playlist) => void
13
- userUpdates: (users: UserState[]) => void
14
- update: (room: RoomState) => void
15
-
16
- // Chat events
17
- chatNew: (msg: ChatMessage) => void
18
- chatHistory: (msgs: ChatMessage[]) => void
19
- }
20
-
21
- export interface ClientToServerEvents {
22
- playItemFromPlaylist: (index: number) => void
23
- updatePlaylist: (playlist: Playlist) => void
24
- updatePlayer: (player: PlayerState) => void
25
- updatePlaying: (playing: MediaElement) => void
26
- updateUser: (user: UserState) => void
27
-
28
- setPaused: (paused: boolean) => void
29
- setLoop: (loop: boolean) => void
30
- setProgress: (progress: number) => void
31
- setPlaybackRate: (playbackRate: number) => void
32
-
33
- seek: (progress: number) => void
34
- playUrl: (src: string) => void
35
- playAgain: () => void
36
- playEnded: () => void
37
- fetch: () => void
38
- error: () => void
39
-
40
- // Chat: client -> server
41
- chatMessage: (text: string) => void
42
- }
43
-
44
- export function playItemFromPlaylist(
45
- socket: Socket<ServerToClientEvents, ClientToServerEvents>,
46
- playlist: Playlist,
47
- index: number
48
- ) {
49
- if (
50
- typeof playlist.items[index] === "undefined" ||
51
- playlist.items[index] === null
52
- ) {
53
- console.error("Impossible to play", index, "from", playlist)
54
- return
55
- }
56
- socket.emit("playItemFromPlaylist", index)
57
- }
58
-
59
- export function createClientSocket(roomId: string) {
60
- console.log("Trying to join room", roomId)
61
- const socket = io({
62
- query: {
63
- roomId,
64
- },
65
- transports: ["websocket"],
66
- path: "/api/socketio",
67
- })
68
-
69
- socket.on("connect", () => {
70
- console.log("Established ws connection to io server", socket.id)
71
- })
72
-
73
- socket.on("disconnect", (reason) => {
74
- if (!["io client disconnect", "io server disconnect"].includes(reason)) {
75
- console.error(
76
- "Socket connection closed due to:",
77
- reason,
78
- "socket:",
79
- socket
80
- )
81
- }
82
- })
83
-
84
- return socket
85
- }