0

I am studying the WebRTC without signal server use case, the URL is the following:

https://github.com/lesmana/webrtc-without-signaling-server

This sample code is for chatting with text only.

I modify these sample codes so that it can support video also successfully.

Sending End code URL:

https://cstsang.gossipcafe.hk:442/webrtc/webcam/caller.html

Receiving End code URL:

https://cstsang.gossipcafe.hk:442/webrtc/webcam/callee.html

Testing procedure:

  1. Browse the "sending end URL", it is because all messages will write to console, so please open the console view.
  2. Click "create offer" button and wait for few seconds. If the "offer" created successfully, the textarea will be filled with "offer" json string, Copy all the content in the textarea.
  3. then open the "Receiving End URL" in the new tab, it is because all messages will write to console, so please open the console view.
  4. Paste the "offer" to the textarea provided And then click the "offer pasted" button
  5. The "answer" will fill the second textarea, then copy the "answer"
  6. Go back to the "sending end URL" tab, click "offer send" button
  7. A new textarea will be shown, paste the "answer" to this textarea
  8. And then click the "Answer pasted" button

The above URLs are working properly even on android devices.

In order to remove the above procedure, I am creating a node.js application based on the URL coding.

The problem is that I don't know why the remote video does not be displayed. Again all messages are written to console, unfortunately, I cannot found any error message in the console. The testing URL as the following:

https://webchat.gossipcafe.hk/

Testing procedure:

  1. Browse the above URL with a computer that has a webcam(known as Computer A). Please open the console view.
  2. Browse the above URL on another computer (known as computer B), please open the console view also.
  3. On computer A, click on the call button, after several seconds, a video should be displayed on the remote view of computer B.

However, it does not happen.

I cannot found any error message on both browser console.

This is the server source code:

var fs = require('fs');
var https = require('https');

var express = require('express');
var app = express();

var options = {
  key: fs.readFileSync('private.key'),
  ca: [fs.readFileSync('ca_bundle.crt')],
  cert: fs.readFileSync('certificate.crt')
};
var serverPort = 443;

var server = https.createServer(options, app);
var io = require('socket.io')(server);

app.get('/', (req, res) => {        
  res.sendFile(__dirname + '/index.html');
});
app.get('/common.js', (req, res) => {       
  res.sendFile(__dirname + '/common.js');
});
app.get('/style.css', (req, res) => {       
  res.sendFile(__dirname + '/style.css');
});
app.get('/WebRTC.js', (req, res) => {       
  res.sendFile(__dirname + '/WebRTC.js');
});
io.on('connection', function(socket) {
  console.log('new connection');
  socket.emit('message', 'This is a message from the dark side.');
});
io.on('connection', (socket) => {
  console.log('a user connected');
  socket.on('chat message', (msg) => {
    io.emit('chat message', msg);
  });
  socket.on("send_answer", (answer) =>{
      console.log("receive an answer:"+answer);
      socket.broadcast.emit("receive_answer",answer);
  });
  socket.on("send_offer", (offer) =>{
      console.log("receive an offer:"+offer);
      socket.broadcast.emit("receive_offer",offer);
  });  
  socket.on('disconnect', () => {
    console.log('user disconnected');
  });
});

server.listen(serverPort, function() {
  console.log('server up and running at %s port', serverPort);
});

PS: Both servers will be offline from 1 am to 7 am (HK time, i.e. UTC+8)

The KNVB
  • 3,588
  • 3
  • 29
  • 54

1 Answers1

0

Finally, I follow the below web site instruction to build my Web app, it works.

https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Signaling_and_video_calling

Especially the following diagrams show the handshake sequence, it is very useful.

https://mdn.mozillademos.org/files/12363/WebRTC%20-%20Signaling%20Diagram.svg https://mdn.mozillademos.org/files/12365/WebRTC%20-%20ICE%20Candidate%20Exchange.svg

And bind the data channel event handler in the RTCPeerConnection.ondatachannel event handler.

RTCDataChannel send method not sending data

The KNVB
  • 3,588
  • 3
  • 29
  • 54