googlecodelabs / webrtc-web

Realtime communication with WebRTC
https://codelabs.developers.google.com/codelabs/webrtc-web/
Apache License 2.0
754 stars 350 forks source link

HTTPS not showing remote video #110

Closed aleparmi closed 4 years ago

aleparmi commented 4 years ago

Hello everybody, After checking out issue #48 my node.js server is still not working properly. All resources are loading correctly on http://localhost:8080 but the peer connection and then remote video aren't executing in https://localhost:8080 . Notice that I'm testing everything within my LAN, sometimes also with 2 devices on different browsers. I've also disabled the TURN lines as suggested in issue #14. Hard refreshing and cache clean are also not helpful as well as generating and applying valid certificates to the browser.

I really don't understand what I'm doing wrong. Below you can find my server code. Thank you in advance :)

WebRTC

'use strict';

var os = require('os'); var nodeStatic = require('node-static'); var socketIO = require('socket.io'); var http = require('https');

var fileServer = new(nodeStatic.Server)(); const fs = require('fs');

const options = { key: fs.readFileSync('Security/server.key'), cert: fs.readFileSync('Security/server.cer') };

var app = http.createServer(options, function(req, res) { fileServer.serve(req, res); }).listen(8080);

var io = socketIO.listen(app); io.sockets.on('connection', function(socket) {

// convenience function to log server messages on the client function log() { var array = ['Message from server:']; array.push.apply(array, arguments); socket.emit('log', array); }

socket.on('message', function(message) { log('Client said: ', message); // for a real app, would be room-only (not broadcast) socket.broadcast.emit('message', message); });

socket.on('create or join', function(room) { log('Received request to create or join room ' + room);

var clientsInRoom = io.sockets.adapter.rooms[room];
var numClients = clientsInRoom ? Object.keys(clientsInRoom.sockets).length : 0;
log('Room ' + room + ' now has ' + numClients + ' client(s)');

if (numClients === 0) {
  socket.join(room);
  log('Client ID ' + socket.id + ' created room ' + room);
  socket.emit('created', room, socket.id);
} else if (numClients === 1) {
  log('Client ID ' + socket.id + ' joined room ' + room);
  // io.sockets.in(room).emit('join', room);
  socket.join(room);
  socket.emit('joined', room, socket.id);
  io.sockets.in(room).emit('ready', room);
  socket.broadcast.emit('ready', room);
} else { // max two clients
  socket.emit('full', room);
}

});

socket.on('ipaddr', function() { var ifaces = os.networkInterfaces(); for (var dev in ifaces) { ifaces[dev].forEach(function(details) { if (details.family === 'IPv4' && details.address !== '127.0.0.1') { socket.emit('ipaddr', details.address); } }); } });

socket.on('disconnect', function(reason) { console.log(Peer or server disconnected. Reason: ${reason}.); socket.broadcast.emit('bye'); });

socket.on('bye', function(room) { console.log(Peer said bye on room ${room}.); }); });

aleparmi commented 4 years ago

Fortunately I solved it. The problem was a wrong comment in main.js file: //io.sockets.in(room).emit(‘join’, room);