mirror of
https://gitlab.com/comunic/nodejs-webrtcsignalexchangerserver
synced 2024-11-22 05:19:26 +00:00
48 lines
828 B
JavaScript
48 lines
828 B
JavaScript
/**
|
|
* Project main module
|
|
*
|
|
* @author Pierre HUBERT
|
|
*/
|
|
|
|
/**
|
|
* Import requirements
|
|
*/
|
|
const express = require("express");
|
|
const app = express();
|
|
const WebSocket = require("ws");
|
|
|
|
/**
|
|
* Import project modules
|
|
*/
|
|
const Config = require("./config");
|
|
const Sockets = require("./sockets");
|
|
|
|
/**
|
|
* If user tries to connect to home page,
|
|
* show a message to explains him what is the
|
|
* purpose of this service
|
|
*/
|
|
app.get("/", (req, res) => {
|
|
res.send("Welcome to NodeSignalExchanger!");
|
|
});
|
|
|
|
/**
|
|
* Start express server
|
|
*/
|
|
var server = app.listen(Config.port, () => {
|
|
console.log("Application listening on port " + Config.port);
|
|
});
|
|
|
|
|
|
/**
|
|
* Handles socket connections
|
|
*/
|
|
var wss = WebSocket.Server({
|
|
server: server,
|
|
path: "/socket"
|
|
});
|
|
|
|
wss.on("connection", socket => {
|
|
Sockets.addSocket(socket);
|
|
});
|