muaz-khan / RTCMultiConnection-Server

RTCMultiConnection socket.io server (npm install rtcmulticonnection-server)

Home Page:https://muazkhan.com:9001/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RTCMultiConnection Server post request returns bad handshake error

adares2 opened this issue · comments

I have a docker nginx symfony vue stack under exampledomain.com
I implemented RTCMulticonnection with

<script type="application/javascript"  src="https://rtcmulticonnection.herokuapp.com/dist/RTCMultiConnection.min.js"></script>
<script type="application/javascript"  src="https://rtcmulticonnection.herokuapp.com/socket.io/socket.io.js"></script> 

and in my Vue File

this.rtcmConnection = new RTCMultiConnection();
this.rtcmConnection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

everything was working. Now i wanted to use my own signaling server. I started one with the following Dockerfile

FROM node

RUN git clone https://github.com/muaz-khan/RTCMultiConnection-Server \
    && cd RTCMultiConnection-Server \
    && npm install

CMD (cd RTCMultiConnection-Server && node server.js)

EXPOSE 9001

I modified config.json with the ssl configuration of my nginx server.
and in the server.js i make this changes:

var iooptions = {
        allowUpgrades: true,
        transports: ['polling', 'websocket' ],
        cors: {
          origin: ['https://www.exampledomain.com','https://exampledomain.com'],
          credentials: true,
          methods: 'GET'
        }
};

ioServer(httpApp,iooptions).on('connection', function(socket) {
 ...
}

Now the server is up and running under
https://exampledomain.com:9001/

and used it in vue with:

this.rtcmConnection.socketURL = 'https://exampledomain.com:9001/';

the browser tries to connect with signaling server with get and post


https://exampledomain.com:9001/socket.io/?userid=ovdo1uhmxtj7l4p4fs&sessionid=1c7ec8af2eacf1cdc828a54abc72e85a&msgEvent=RTCMultiConnection-Message&socketCustomEvent=RTCMultiConnection-Custom-Message&autoCloseEntireSession=false&maxParticipantsAllowed=1000&extra={}&EIO=3&transport=polling&t=NOeBTVe

the get request seems to be okay

but the post request is a 400 bad request and returns a json bad handshake error.

How can I fix the error and connect?

Duplicate of #28

@nurassyl @gbrian @muaz-khan

above solution not workingt in http://localhost:9001

// --------------------------
// socket.io codes goes below

var iooptions = {
        allowUpgrades: true,
        transports: ['polling', 'websocket' ],
        cors: {
          origin: ['https://localhost','http://localhost'],
          credentials: true,
          methods: 'GET'
        }
};

ioServer(httpApp,iooptions).on('connection', function(socket) {
    RTCMultiConnectionServer.addSocket(socket, config);

    // ----------------------
    // below code is optional

    const params = socket.handshake.query;

    if (!params.socketCustomEvent) {
        params.socketCustomEvent = 'custom-message';
    }

    socket.on(params.socketCustomEvent, function(message) {
        socket.broadcast.emit(params.socketCustomEvent, message);
    });
});

image

i had Tried to connect like this:

connection.socketURL = 'http://localhost:9001/';

@arunkumartdr did you get any solution at your problem? I got a same error. can't run as localhost.

@muaz-khan @nurassyl @gbrian @mirza Brunjadze

Done. I solve the problem with install socket.io version 2.

run cmd npm install socket.io@2.3.0

can visit https://medium.com/@aideedprogrammer/video-broadcast-webrtc-using-ionic-apps-14affc0a8369