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:
- Browse the "sending end URL", it is because all messages will write to console, so please open the console view.
- 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.
- 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.
- Paste the "offer" to the textarea provided And then click the "offer pasted" button
- The "answer" will fill the second textarea, then copy the "answer"
- Go back to the "sending end URL" tab, click "offer send" button
- A new textarea will be shown, paste the "answer" to this textarea
- 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:
- Browse the above URL with a computer that has a webcam(known as Computer A). Please open the console view.
- Browse the above URL on another computer (known as computer B), please open the console view also.
- 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)