This is simple chat on WS and express.js
. I get the error that the browser can't connect to server via websockets
.
client connection:
file: rtc.html
ws = new WebSocket('wss://' + window.location.hostname + '/wr' );
ws.onerror = (error) => { console.log(error); };
ws.onmessage = (message) => {
. . .
Server code:
const express = require('express');
const http = require('http');
const WebSocket = require('ws');
const app = express();
app.get('/rtc', (req, res)=>{
res.sendFile('/home/user/dev/rtc.html');
});
const server = http.createServer(app);
const wss = new WebSocket.Server({ server:server, path: "/wr" });
. . .
app.listen(3000);
UPD: The problem was due to the fact that I was doing chat on webrtc
and tested in Mozilla
and Mozilla
would not connect without https
connection however getUserMedia
ran fine.
It was necessary to write so:
var https = require('https');
var serv = https.createServer(serverConfig, app);