Skip to content

Latest commit

 

History

History
295 lines (220 loc) · 7.01 KB

README.md

File metadata and controls

295 lines (220 loc) · 7.01 KB

Playon Server

The server is written on the NodeJS engine in the Javascipt language.

The connection to the server takes place using the multi-platform library Socket.io, which was built on the WebSocket technology.

How to start connection on client:

After client success connect to server socket, he must send join event to server with him userdata. If server success compute this request, and connect user to room, he emit joined with room & video data. After that, the server and the client can communicate with any other events.

Server-side eventlist:

  • Join - Any user connect to server
  • Joined - User connected to socket and send his data
  • Disc - Any user disconnect from server
  • Sync - Server synchronize event
  • Play - Any user play video
  • Pause - Any user pause video
  • Load - Any user load new video link
  • Rewind - Any user rewind video to new time
  • Message - Any user send chat message
  • Light - Any user change light on player
  • Click - Any user click on video
  • Error Message - Emit on any error from server-side

Client-side eventlist:

  • Join - User join to player
  • Play - User play video
  • Pause - User pause video
  • Load - User load new video link
  • Rewind - User rewind current video to new time
  • Message - User send chat message
  • Light - User change light on player
  • Click - User click on video



Events from server:

All data from server receive on JSON-Object format, not JSON-String.


Event join from server

Receive from the server if new user connected to player room.

Response data:

{
	nick: "NICKNAME",
}


Event joined from server

Receive from the server if current user success joined to room and server.

Response data:

{
	video: "VIDEO_ID",
	time: 123,
	play: true,
	light: false
}

video - Video ID (Example: YVcroDDi24s) time - is Integer value of video current time play in seconds
play - is Boolean value of video playing status
light - is Boolean value of player light on (true) or off (false)


Event disc from server

Receive from the server on user disconnect from room or server.

Response data:

{
	nick: "NICKNAME",
}


Event sync from server

Receive from the server info about video play, every 2 min.

Response data:

{
	video: "VIDEO_ID",
	time: 123
}


Event play from server

Receive from the server if any user press play.

Response data:

{
	video: "VIDEO_ID",
	time: 123,
	nick: "NICK_WHO_PRESS_PLAY"
}


Event pause from server

Receive from the server if any user press pause.

Response data:

{
	time: 123,
	nick: "NICK_WHO_PRESS_PAUSE"
}


Event load from server

Receive from the server if server change video.

Response data:

{
	video: "VIDEO_ID",
	nick: "NICK_WHO_PRESS_PAUSE"
}


Event rewind from server

Receive from the server if any user rewind video.

Response data:

{
	time: 123,
	nick: "NICK_WHO_REWIND_VIDEO"
}


Event message from server

Receive from the server new message from users.

Response data:

{
	nick: "NICKNAME",
	text: "MESSAGE_TEXT",
	color: "#HEX"
}


Event light from server

Receive from the server, if any user click change light button.

Receive data:

{
	light: true
}

light - is Boolean value of player light on (true) or off (false)

  • true - white mode of player.
  • false - dark mode of player.


Event click from server

Receive from the server, if any user click on video.

Receive data:

{
	x: 123,
	y: 123,
	color: "#HEX"
}

x and y - is percent value (0 - 100)
color - user main color and mark color


Event error_message from server

Receive from the server, on any server-side error.

Receive data:

{
	type: "TYPE_ERROR",
	message: "MESSAGE_ERROR"
}





Events to server:

All data to server need send on JSON-Object format, not JSON-String.


Event join to server

Send to the server with a successful connection to it (After init socket and on event connect).

Input data:

{
	nick: "NICKNAME",
	room: "ROOMNAME"
}

If server successfully compute you data he emit back "joined" event, else server emit to you "error_message" event
If server receive this event, he emit "join" event to all users


Event play to server

Send to the server what user click play video button.

Input data: empty

If server receive this event, he emit "play" event to all users


Event pause to server

Send to the server what user click pause video button.

Input data: empty

If server receive this event, he emit "pause" event to all users


Event load to server

Send to the server new video link.

Input data:

{
	link: "LINK_TO_YOUTUBE_VIDEO",
	playlist: false
}

The playlist property takes two values, true and false.

  • True - indicates that the video is selected from a playlist.
  • False - indicates that the video is loaded from an external link

If server receive this event, he emit "load" event to all users


Event rewind to server

Send to the server time in seconds to rewind video.

Input data:

{
	time: 123
}

If server receive this event, he emit "rewind" event to all users


Event message to server

Send new message to the server.

Input data:

{
	text: "MESSAGE_TEXT",
	color: "#HEX"
}

Message text can not exceed 150 characters
If server receive this event, he emit "message" event to all users


Event light to server

Send to server if user want change light.

Input data: empty

If server receive this event, he emit "light" event to all users


Event click to server

Send to the server, if user click on video.

Input data:

{
	x: 123,
	y: 123,
	color: "#HEX"
}

x and y - is percent value (0 - 100)
color - user main color and mark color
If server receive this event, he emit "click" event to all users