muaz-khan / WebRTC-Experiment

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

Self-hosted Screen-Sharing #56

Open Jing-Springshare opened 11 years ago

Jing-Springshare commented 11 years ago

I noticed the Pluginfree-Screen-Sharing is using the services at firebaseio.com

Is that possible to self hosted it?

Which node.js file we could use to start the services?

Thanks,

muaz-khan commented 11 years ago

All recent WebRTC Experiments and libraries are capable to work with each and every signaling gateway. Signaling process is highly simplified. If you want to use socket.io over node.js, here is your signaler.js code:

io.sockets.on('connection', function (socket) {
    socket.on('message', function (data) {
        socket.broadcast.emit('message', data);
    });
});

And here is the client-side code overriding openSignlaingChannel method:

connection.openSignalingChannel = function(callback) {
    return io.connect().on('message', callback);
};

Try New Screen Sharing Demo. Source Code

Expectations for custom signaling gateways

  1. Data from onmessage is passed over callback object
  2. Socket instance is returned for reusability e.g. return socket;

That socket instance must have a send method. Otherwise; you should declare a custom send method there:

// declaring custom "send" method
socket.send = function(data) {
    xhr.post('/controller/action', data);
};

WebSockets for signlaing

connection.openSignalingChannel = function (callback) {
    var websocket = new WebSocket('ws://domain:protocol/');

    // data from "onmessage" must be passed over "callback" object
    websocket.onmessage = function (e) {
        callback(e.data);
    };

    // socket object must be returned for reusability
    return websocket;
};

WebSync for signaling

connection.openSignalingChannel = function (callback) {
    var username = Math.round(Math.random() * 60535) + 5000;

    var client = new fm.websync.client('websync.ashx');

    client.setAutoDisconnect({
        synchronous: true
    });

    // received message must be passed over "callback" object
    client.connect({
        onSuccess: function () {
            client.join({
                channel: '/namespace',
                userId: username,
                userNickname: username,
                onReceive: function (event) {
                    callback(event.getData().text);
                }
            });
        }
    });

    // must have a "send" method
    return {
        send: function (message) {
            client.publish({
                channel: '/namespace',
                data: {
                    username: username,
                    text: message
                }
            });
        }
    };
};

XHR for signaling

connection.openSignalingChannel = function (callback) {
    var messages = {};

    function repeatedlyCheck() {
        xhr('/GetData', function (data) {
            if (data != false && !messages[data.ID]) {
                messages[data.ID] = data.Message;

                // data must be passed over "callback" object
                callback(data.Message);

                setTimeout(repeatedlyCheck, 1);
            } else setTimeout(repeatedlyCheck, 400);
        });
    }

    repeatedlyCheck();

    // if there is no "send" method
    // must declare one
    // also socket instance must be returned
    return {
        send: function (data) {
            xhr('/PostData', null, data);
        }
    };
};
ghost commented 7 years ago

Hello, @muaz-khan Is it possible to share desktop screen without using any extension ? Just by capturing the screen stream and displaying it ?? what constraints should i use ??