text: const HTTPS_PORT = 9558; //default port for https is 443
  const HTTP_PORT = 8001; //default port for http is 80
  
  const fs = require('fs');
  const http = require('http');
  const https = require('https');
  const WebSocket = require('ws');
  const WebSocketServer = WebSocket.Server;
  
  // TLS is required
  const serverConfig = {
    key: fs.readFileSync('./ssl/key.pem'),
    cert: fs.readFileSync('./ssl/cert.pem'),
  };
  
  // ----------------------------------------------------------------------------------------
  
  // Create a server for the client html page
  const handleRequest = function (request, response) {
    // Render the single client html file for any request the HTTP server receives
    console.log('request received: ' + request.url);
  
   if (request.url === '/webrtc.js') {
      response.writeHead(200, { 'Content-Type': 'application/javascript' });
      response.end(fs.readFileSync('client/webrtc.js'));
    } else if (request.url === '/style.css') {
      response.writeHead(200, { 'Content-Type': 'text/css' });
      response.end(fs.readFileSync('client/style.css'));
    } else {
      response.writeHead(200, { 'Content-Type': 'text/html' });
      response.end(fs.readFileSync('client/index.html'));
    }
  };
  
  const httpsServer = https.createServer(serverConfig, handleRequest);
  httpsServer.listen(HTTPS_PORT);
  
  // ----------------------------------------------------------------------------------------
  
  // Create a server for handling websocket calls
  const wss = new WebSocketServer({ server: httpsServer });
  
  wss.on('connection', function (ws) {
    ws.on('message', function (message) {
      // Broadcast any received message to all clients
  	console.log('received date: %s', new Date().toLocaleString());
      console.log('received: %s', message);
      wss.broadcast(message);
    });
  
    ws.on('error', () => ws.terminate());
  });
  
  wss.broadcast = function (data) {
    this.clients.forEach(function (client) {
      if (client.readyState === WebSocket.OPEN) {
        client.send(data);
      }
    });
  };
  
  console.log('Server running.');
  
  // ----------------------------------------------------------------------------------------
  
  // Separate server to redirect from http to https
  // http.createServer(function (req, res) {
      // console.log(req.headers['host']+req.url);
      // res.writeHead(301, { "Location": "https://" + req.headers['host'] + req.url });
      // res.end();
  // }).listen(HTTP_PORT);