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

Screen sharing - To use socket.io instead of Firebase #88

Open Manikandan39 opened 11 years ago

Manikandan39 commented 11 years ago

This month, firebase is going to close the free usages. So I want to implement this screensharing using socket.io. Kindly help me in this.

muaz-khan commented 11 years ago

It is confirmed that firebase isn't going to close free account; it will be available for development or small projects:

I’m an individual developer building a hobby project. Do I need to pay? No. Our Dev Firebase is intended for this exact purpose. We only ask customers to pay when they need extra scale, support, or an SLA. For the vast majority of hobby projects the usage limits of a Development Firebase are more than enough.

Read more here.

For this screen sharing demo; your server-side node.js code should look like this:

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

and client-side usage (override openSignalingChannel method):

connection.openSignalingChannel = function (onmessage) {
    var socket = io.connect('http://localhost:80/');

    // return data via "callback" parameter
    socket.on('message', onmessage);

    // override "send" to make sure "emit" is called ia "send"
    socket.send = function (data) {
        socket.emit('message', data);
    };

    return socket;
};

For multi-sockets based experiments (e.g. pluginfree screen sharing); try:

  1. socket.io over node.js
  2. websocket over ndoe.js

Learn more about signaling (used in this repository).

Manikandan39 commented 11 years ago

Thanks for your reply. Now I shared two screens A & B from two separate system browsers via socket.io connection. When I give participation request only from A to B, screen B is visible in screen A.

{
     "name":"message",
     "args":["{
                 \"participationRequest\":true,
                 \"to\":\"B\",
                 \"userid\":\"A\"
       }"]
}

But I not gave participationrequest from B to A. But Screen A is also visible in screen B. Kindly help me in this.

muaz-khan commented 11 years ago

It is fixed here. Will be committed soon. Updated screen.js file.

Remember, following two (check/share) methods must contain identical room-names:

empty room-name have room-name
screen.check() screen.check('room-name')
screen.share() screen.share('room-name')

It is suggested to pass room-name via constructor instead:

var screen = new Screen('room-name');

// initialize signaling gateway; and check existing shared screens
screen.check();

document.getElementById('share-screen').onclick = function() {
      screen.share();
};
Manikandan39 commented 11 years ago

I modified the constructor new Screen('1234'), screen.check() and screen.share() as you mentioned. But still I'm facing the same problem. Kindly help me regarding this.

muaz-khan commented 11 years ago

Can you make a demo and share via jsFiddle or google drive? Are you replaced "screen.js" and cleared the webpage cache? Otherwise, please send me files directly at muazkh@gmail.com

muaz-khan commented 11 years ago

I see, try to use unique "room-name" in the constructor:

var roomName = location.hash.substr(1);

// via construtor
var screen = new Screen(roomName);

// or
screen.check(roomName);
screen.share(roomName);

Room name must be unique each time you call share method; which must be called once for each unique room.

When you manually write the room-name; you're actually calling "share" multiple times for single room.