-
Notifications
You must be signed in to change notification settings - Fork 183
Important Dev Functions
Functions located in server.js file
socket.on('new room', function(data, callback))
Parameters: room, callback
Joins the new socket to the room. If the room currently does not exist, set the socket as the host socket and join the room.
io.sockets.adapter.rooms['room-' + socket.roomnum] Initialization:
.host will store the host socket id
.currPlayer = 0 (YouTube Default)
.currVideo = { yt, dm, vimeo } (Default video IDs)
.prevVideo = { yt: {id, time}, dm: {id, time}, vimeo: {id, time} } (Previous video IDs and Times)
.hostName = socket.username (Set the username of the host socket)
.users = [socket.username] (Create user array)
.queue = { yt, dm, vimeo } (Create empty queue where each item in the object is an array that holds objects)
See the Room Object Structure for more detail on the structure.
It then sets the front end host label and updates the queue. It grabs the current video from the room object, changes the video, then syncs it up to the host of the room.
socket.on('play video', function(data))
Parameters: { room: room }
Play or pause the current video client based on the current video status for all sockets connected to the room.
socket.on('play other', function(data))
Parameters: { room: room }
Plays current video client regardless of current status for all sockets connected to the room. Calls justPlay() event function.
socket.on('pause other', function(data))
Parameters: { room: room }
Pauses the current video client regardless of current status for all sockets connected to the room. Calls justPause() event function.
socket.on('seek other', function(data))
Parameters: { room: room, time: time }
Seeks the video client to the specific time for all sockets connected to the room. Calls justSeek() event function.
socket.on('play next', function(data, callback)
Parameters: {}, Callback function
Grabs the next videoId from the queue, updates the queue with updateQueueVideos(), then calls the callback function passing in the retrieved videoId. The callback function should take the videoId and change to that video. The videoId will be "QUEUE IS EMPTY" if the queue is empty. This signals to the callback function not to change the video and throw an error.
socket.on('enqueue video', function(data))
Paramters: { room: room, videoId: videoId }
Calls 'get title' to grab a title, and pass in a callback function which will push the title and video id to the appropriate spot in the queue then updates the front end.
**socket.on('notify alerts', function(data))
Parameters: { alert: alert, ?: ? }
Function to handle all notify alerts in the notify.js file. Alerts are organized with specific number codes:
- Enqueue
- Host Change
- Empty Queue
Functions located in sync.js file
function playVideo(roomnum)
Calls 'play video' function on the server
function syncVideo(roomnum)
Grabs the video data (currTime, state, videoId) and calls 'sync video' on the server
function syncAlert()
Generates a sync notify alert when pressing sync
function getTime()
Returns the current time for the player
function seekTo(time)
Seeks to the specific time for the player and plays the video
function idParse(videoId)
This parses the video Id out of a URL if the user provides a URL rather than a video id. This is used mainly for changeVideo and enqueueVideo
This returns the videoid "invalid" if the user enters a URL that is invalid.
function enqueueVideo(roomnum)
This parses the videoId then adds it to the queue by calling 'enqueue video'
socket.on('playVideoClient', function(data))
Calls the play/pause function for the specific player.
Functions located in events.js file
function playOther(roomnum)
Calls 'play other' function in the server
socket.on('justPlay', function(data))
Plays the video client for the specific player
function pauseOther(roomnum)
Calls 'pause other' function in the server
socket.on('justPause', function(data)
Pauses the video client for the specific player
function seekOther(roomnum, currTime)
Calls 'seek other' function in the server
socket.on('justSeek', function(data)
Parameters: { time: time }
Seeks the video client to the specific time
playNext(roomnum)
Calls 'play next' function in the server. It passes a callback function changes the video with a 'change video' function call. Does not change anything if the queue is empty
yt.js
socket.on('get title', function(data, callback))
Utilizes the YouTube V3 API to grab the title of a video. It takes in a callback function which it passes the video title in. It also calls 'notify alerts' with the enqueue code of 0 which calls the proper notify alert.
All of the notify alert specific functions here