simplewebrtc / SimpleWebRTC

Simplest WebRTC ever
Other
4.65k stars 1.19k forks source link

Custom connection using Pusher #480

Open ichuprov opened 8 years ago

ichuprov commented 8 years ago

I'm wanting to use Pusher for my signaling, instead of the default that comes with SimpleWebRTC.

var myConnection = {
            pusher: window.pusher /* existing pusher object */,
            channel: this.pusher.subscribe ('video-chat-channel'),

            on: function (event, callback) {
                this.channel.bind (event, callback);
            },
            emit: function (event, data) {

                $.ajax({ 
                    url: rtcmessage, // trigger route, handled through php
                    method: "post",
                    data: {
                        event: event,
                        channel: 'video-chat-channel',
                        message:data,
                        socketId: this.pusher.connection.socket_id
                    }
                });

            },
            getSessionId: function() {
                return this.pusher.connection.socket_id;
            },
            disconnect: function() {
                this.pusher.disconnect();
            }
        };

I am just wondering is this enough/correct to have it work with SimpleWebRTC? In the documentation it just says to provide definitions for functions: on, emit, getSessionId, disconnect. Is that all? Or should there be more? Also what channel should I be using for binding/listening to events?

tgabi333 commented 8 years ago

I think its enough Basicly you should replace this object: https://github.com/andyet/SimpleWebRTC/blob/master/socketioconnection.js

Just pass this new connection object to simplewebrtc:

new SimpleWebRTC({connection: myConnection})
ichuprov commented 8 years ago

That's how I pass in my connection, but its not working. Nothing comes up from the remote peer. Looking at the dev console, SimpleWebRTC doesn't seem to be starting at all. Also should my connection be using a particular channel for the event trigger/listening? Should it be the actual room to be used for the vid chat?

tgabi333 commented 8 years ago

Could you debug the messages sent through pusher?

Yes, you should use separated channels for each rooms.

ichuprov commented 8 years ago

I'm kinda using the simple video demo where you type in the room name. Creating the room it sends off an event ie the emit function is used to send an event called "create" with the name of the room I typed in. But nothing happens. Am I supposed to listen to/handle the "create" event? Or is that meant to be handled by SimpleWebRTC? If I'm meant to handle the "create" event, fair enough. But then what other events do I need to manage? What does SimpleWebRTC listen for and what should I set up?

tgabi333 commented 8 years ago

Oh, i got it: In your implementation you should have handle callbacks See https://github.com/andyet/SimpleWebRTC/blob/master/simplewebrtc.js#L326

tgabi333 commented 8 years ago

Sokect.io default behavior is that if the last passed parameter to emit is a function then its a callcack, you should call it with the result

ichuprov commented 8 years ago

Ok so I do need to handle the various events. Wish that was clearer in the documentation.

With regards to emit, its very similar with Pusher's trigger. So because I'm using a custom connection, how many events do I need to manage myself? Is there a list somewhere (maybe I've missed it)?

Thanks for your help.

tgabi333 commented 8 years ago

See https://github.com/andyet/signalmaster for events

ichuprov commented 8 years ago

Thanks!

ichuprov commented 8 years ago

Now I'm more confused. I kinda tried to listen to the extra events but I'm not really sure what I should be doing and how many events I should be listening to! Is it all of them? Some of them?

Exactly which events should I be listening to with the custom connection? And how exactly should I be processing them?

tgabi333 commented 8 years ago

You should exactly copy the same logic in signalmaster.