simplewebrtc / SimpleWebRTC

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

Issue with sockjs signaling server #551

Open v29neil opened 7 years ago

v29neil commented 7 years ago

I am trying to use sockjs on client side and server side both. I created a file sockjsconnection.js , which is similar like socketioconnection.js Inside sockjsconnection.js I defined four standard functions just like in socketioconnection.js

(function() {
    var SockJSConnection = (function() {
        var SockJSConnection = function(){
            // var sockjs_url = '/echo';
            this.connection = new SockJS('/echo');
            // this.connection = io.connect(config.url, config.sockjs);
        }

        SockJSConnection.prototype.on = function (ev, fn) {
            this.connection.on(ev, fn);
        };

        SockJSConnection.prototype.emit = function () {
            this.connection.emit.apply(this.connection, arguments);
        };

        SockJSConnection.prototype.getSessionid = function () {
            return this.connection.id;
        };

        SockJSConnection.prototype.disconnect = function () {
            return this.connection.disconnect();
        };
        return SockJSConnection;
    })();

    if (typeof module !== 'undefined' && typeof module.exports !== 'undefined')
        module.exports = SockJSConnection;
    else
        window.SockJSConnection = SockJSConnection;
})();

On index.html I included

<script src="http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"></script>
<script src="./sockjsconnection.js"></script>
<script src="simplewebrtc.bundle.js"></script>   //havent touched this file

Then ,

var connection = new SockJSConnection();   //custom connection object
    // create our webrtc connection
    var webrtc = new SimpleWebRTC({
        // the id/element dom element that will hold "our" video
        localVideoEl: 'localVideo',
        connection: connection,
        // the id/element dom element that will hold remote videos
        remoteVideosEl: '',
        // immediately ask for camera access
        autoRequestMedia: true,
        debug: false,
        detectSpeakingEvents: true,
        url: "http://localhost:9999"
    });

I get this strange error connection.on is not a function which should not happen.(screenshot attached screenshot from 2017-03-03 17-40-41 )

Has anyone tried this library with sockjs????

fippo commented 7 years ago

sockjs doesn't implement .on and .emit from the "getting started" here: https://github.com/sockjs/sockjs-client#getting-started

v29neil commented 7 years ago

@fippo Yea , i saw that. Thats why i created the file sockjsconnection file . Does that mean this library does not support sockjs client ????

nopmop commented 7 years ago

@v29neil I just started fitting sockjs into this. Creating the sockjsconnection.js file as you did is not enough because the socketio's emit() does not translate to sockjs' send(). You need to map emit() to send(), fitting the arguments properly (read: properly crafting the data you send). It will be easy to do it once you choose your STUN/TURN server-side implementation.