1.0.0 • Published 8 years ago

file-ws-server v1.0.0

Weekly downloads
5
License
CC-BY-NC
Repository
github
Last release
8 years ago

Build Status

FileWSServer

A server which transfer files through websockets

Synopsis

This server is created for the TwiceCast project, an Epitech Innovativ Project, it will be used by the streamer to transfer his source code for the viewers.

Installation

You can install it with :

npm install file-ws-server

You can launch it with :

npm start [port number]

Configuration

You can create a config.json file for some parameters. Here is an example :

{
  "port":Port number,
  "baseDir":"Path/to/receive/files",
  "key":"Secret key for JWT"
}

port is used when not in argument. By default, it is set to 3005.

baseDir is used to set the directory where files will be transfered. By default, it is set to "./".

key is used to set the key signature that will be used to verify the token of the client. By default, it is set to "secret".

Protocol

Template message

The basic template message to send is :

{
  "type":"The part of the server aimed",
  "subtype":"The functionnality of the part aimed",
  "data" : {
  }
}

Authentication

WARNING: This part is not functionnal

For using certains parts of the server (like posting files), you must be authentified.

You can do that by sending :

{
  "type":"authenticate",
  "data":{
    "token":"your token"
  }
}

File part

Auth for file

When a streamer use this part, he has to authenticate by sending :

{
	"type":"file",
	"subtype":"auth",
	"data": {
		"username":"streamer's username",
		"project":"streamer's project"
	}
}

In case of success, response will be :

{
	"code":200,
	"type":"fileAuth",
	"data":"OK"
}

Get file

You can get a file, a directory or a complete project by sending :

{
	"type":"file",
	"subtype":"get",
	"data": {
		"username":"streamer's username",
		"project":"streamer's project",
		"name":"/path/to/file or directory aimed",
		"recursively":false
	}
}

name parameters can be ommited to get the entire project.

By default, recursively is set to false.

In case of success, responses will be :

{
	"code":200,
	"type":"fileGet",
	"data": {
		"name":"/path/to/file",
		"content":"content of a part of the file",
		"part":part number,
		"maxPart":number of part that will be sent
	}
}

Post file

Streamer authentified can post a file by sending :

{
	"type":"file",
	"subtype":"post",
	"data": {
		"name":"/path/to/file aimed",
		"content":"content of a part of the file",
		"part":part number,
		"maxPart":number of part that will be sent
	}
}

part and maxPart can be ommited when sending the complete content.

The file will be saved at config.baseDir/sender.username/sender.project/message.data.name.

In case of success, response will be :

{
	"code":200,
	"type":"filePost",
	"message":"OK"
}

Delete file

Streamer authentified can delete a file by sending :

{
	"type":"file",
	"subtype":"delete",
	"data": {
		"name":"/path/to/file aimed"
	}
}

In case of success, response will be :

{
	"code":200,
	"type":"fileDelete",
	"message":"OK"
}

Chat part

Auth for chat

When a user use this part, he must be authentified by sending :

{
	"type":"chat",
	"subtype":"auth",
	"data": {
		"username":"user's username",
		"room":"user's room (can be the stream's name coupled with streamer's name)"
	}
}

In case of success, response will be :

{
	"code":200,
	"type":"chatAuth",
	"data":"OK"
}

Message

A user authentified can send a message to his room by sending :

{
	"type":"chat",
	"subtype":"message",
	"data": {
		"message":"Content of the message"
	}
}

In case of success, response will be :

{
	"code":200,
	"type":"chatMessage",
	"data":"OK"
}