muaz-khan / WebRTC-Experiment

WebRTC, WebRTC and WebRTC. Everything here is all about WebRTC!!
https://www.webrtc-experiment.com/
MIT License
11.76k stars 3.95k forks source link

sharing screen #634

Open k1uma opened 5 years ago

k1uma commented 5 years ago

hello sir how can i share screen on localhost using nodejs and webrtc and websocket-over-nodejs

k1uma commented 5 years ago

// https://www.webrtc-experiment.com/

var fs = require('fs'); //var socket = io.connect("https:/localhost:8888/");

// don't forget to use your own keys! var options = { key: fs.readFileSync('fake-keys\privatekey.pem'), cert: fs.readFileSync('fake-keys\certificate.pem') //key: fs.readFileSync('/etc/letsencrypt/live/webrtcweb.com/privkey.pem'), //cert: fs.readFileSync('/etc/letsencrypt/live/webrtcweb.com/fullchain.pem') };

// HTTPs server var app = require('https').createServer(options, function(request, response) { response.writeHead(200, { 'Content-Type': 'text/html' }); // var link = 'https://github.com/muaz-khan/WebRTC-Experiment/tree/master/socketio-over-nodejs'; // response.write('socketio-over-nodejs

socketio-over-nodejs

var socket = io.connect("https://localhost:8888/");
'); // response.end(); });

// socket.io goes below

var io = require('socket.io').listen(app, { log: true, origins: ':' });

io.set('transports', [ // 'websocket', 'xhr-polling', 'jsonp-polling' ]);

var channels = {};

io.sockets.on('connection', function (socket) { var initiatorChannel = ''; if (!io.isConnected) { io.isConnected = true; }

socket.on('new-channel', function (data) {
    if (!channels[data.channel]) {
        initiatorChannel = data.channel;
    }

    channels[data.channel] = data.channel;
    onNewNamespace(data.channel, data.sender);
});

socket.on('presence', function (channel) {
    var isChannelPresent = !! channels[channel];
    socket.emit('presence', isChannelPresent);
});

socket.on('disconnect', function (channel) {
    if (initiatorChannel) {
        delete channels[initiatorChannel];
    }
});

});

function onNewNamespace(channel, sender) { io.of('/' + channel).on('connection', function (socket) { var username; if (io.isConnected) { io.isConnected = false; socket.emit('connect', true); }

    socket.on('message', function (data) {
        if (data.sender == sender) {
            if(!username) username = data.data.sender;

            socket.broadcast.emit('message', data.data);
        }
    });

    socket.on('disconnect', function() {
        if(username) {
            socket.broadcast.emit('user-left', username);
            username = null;
        }
    });
});

}

// run app

app.listen(process.env.PORT || 8888);

process.on('unhandledRejection', (reason, promise) => { process.exit(1); });

console.log('Please open SSL URL: https://localhost:'+(process.env.PORT || 8888)+'/');

k1uma commented 5 years ago

Lenovo@DESKTOP-2I4JK57 MINGW64 ~/Desktop/maruti2 $ node server.js info - socket.io started Please open SSL URL: https://localhost:8888/

but html page is not access

dotnethii commented 4 years ago

please Help MR muaz-khan