muaz-khan / WebRTC-Experiment

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

How can I change signaling from wss to socket.io in desktopCapture #185

Open alberttsai opened 10 years ago

alberttsai commented 10 years ago

Dear Muaz Khan, By refering socketio-over-nodejs (https://github.com/muaz-khan/WebRTC-Experiment/tree/master/socketio-over-nodejs), I have replaced the signaling method "function openSignalingChannel(config) { } " for both desktop-capture.js and index.html in "desktopCapture" (https://www.webrtc-experiment.com/desktop-sharing/), to the following code, but it is not working, am I missing something?

 
function openSignalingChannel(config) {
   var SIGNALING_SERVER = 'http://socketio-over-nodejs.hp.af.cm';
   connection.openSignalingChannel = function(config) {   
   var channel = config.channel || this.channel || 'default-namespace';
   var sender = Math.round(Math.random() * 9999999999) + 9999999999;

   io.connect(SIGNALING_SERVER).emit('new-channel', {
      channel: channel,
      sender : sender
   });

   var socket = io.connect(SIGNALING_SERVER + channel);
   socket.channel = channel;

   socket.on('connect', function () {
      if (config.callback) config.callback(socket);
   });

   socket.send = function (message) {
        socket.emit('message', {
            sender: sender,
            data  : message
        });
    };

   socket.on('message', config.onmessage);
   };
}

Please kindly help, thank you.

alberttsai commented 10 years ago

Dear Muaz-Khan, When trying the new updated desktopCapture (from the download.zip), the receiver side did not receive anything from sender. What I observed is once sender click the desktopCapture extension button, one more chrome tab show up in his own side and see his own screen. Am I doing anything wrong? My chrome is with Version 35.0.1916.17 dev-m.

Thanks for help. Albert

muaz-khan commented 10 years ago

First of all, you can see that now desktopCapture experiment is upgraded to RTCMultiConnection-v1.7.

Secondly, it is using most recent feature added in v1.7; i.e. room-description callback returned by open method along with dontTransmit:true.

dontTransmit:true can be used to override default room-transmission behaviour; i.e. onNewSession will NEVER be fired in this case.

For initiator

var roomDescriptions = connection.open( {
       dontTransmit: true
} );

socketio.emit('room-description', roomDescriptions);

Your nodejs code can listen room-description handler and uniquely identifies room using sessionid:

// it is nodejs code
var globalRoomObject = {};

socket.on('room-description', function(roomDescriptions) {
     globalRoomObject[roomDescriptions.sessionid] = roomDescriptions;
});

Now, lets say a new user opens a room-URL; you can check roomDescriptions:

// it is nodejs code
socket.on('connection', function(socket) {
     var roomid = socket.handshake.query.roomid;
     if(globalRoomObject[roomid]) {
          socket.emit('join-room', globalRoomObject[roomid]);
     }
});

And target user's browser can observe join-room event:

// client-side code
socket.on('join-room', function(roomDescriptions) {
    connection.join( roomDescriptions );
});

And he will quickly join the room. He will not wait for onNewSession also he will not call connect method because join method is enough for him.

Main trick in above code snippets is that you're sharing room-descriptions yourself using your own server implementations and your own techniques.

You're just caring about two methods: open for initiator and join for all roommates!

The URL that desktopCapture experiment opens is what where you can "privately" view your screen....you can share that URL via email or any mean. It means that others can't see your desktop without getting URL from you!


P.S. WebSocket messages are not encrypted that's why one can easily see some-common data using websocket logs in the chrome developer tools.