muaz-khan / RTCMultiConnection-Server

RTCMultiConnection socket.io server (npm install rtcmulticonnection-server)
https://muazkhan.com:9001/
MIT License
277 stars 147 forks source link

RTCMultiConnection Server post request returns bad handshake error #29

Open adares2 opened 3 years ago

adares2 commented 3 years ago

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?

danielehrhardt commented 3 years ago

Duplicate of https://github.com/muaz-khan/RTCMultiConnection-Server/issues/28

arunkumartdr commented 3 years ago

@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/';

wanaideed commented 2 years ago

@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

wanaideed commented 2 years ago

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