Ezelia / eureca.io

eureca.io : a nodejs bidirectional RPC that can use WebSocket, WebRTC or XHR fallback as transport layers
http://eureca.io/
343 stars 30 forks source link

WebRTC problem #40

Open pantrombka opened 7 years ago

pantrombka commented 7 years ago

I have a problem with webrtc transport in eureca.io. I installed on my VPS module wrtc. My server.js:

var http = require('http');
var fs = require('fs');

var server = http.createServer();

var Eureca = require('eureca.io');

var eurecaServer = new Eureca.Server({transport:'webrtc', allow:['hello', 'sub']});

eurecaServer.attach(server);

//functions under "exports" namespace will
//be exposed to client side
eurecaServer.exports.hello = function () {
    var client = eurecaServer.getClient(this.connection.id);
    client.hello();
    console.log('Hello from client');
    return ('hello return');
}

eurecaServer.onConnect(function (conn) {

    console.log('new Client');
    var client = eurecaServer.getClient(conn.id);

    client.sub(10, 4).onReady(function (r) {
        console.log('> 10 - 4 = ', r);
    });

});

server.on('request', function (request, response) {
    var i;

    if (request.method === 'GET') {

        if (request.url.split('?')[0] === '/') {
            var filename = __dirname + '/index.html';
            fs.readFile(filename, function (err, data) {
                var text = data.toString();
                response.writeHead(200, { 'Content-Type': 'text/html' });
                response.write(text);
                response.end();
            });
        }
    }

});

console.log('\033[96mlistening on 8000 \033[39m');
server.listen(8000);

and client.html:

<!doctype html>
<html>
    <head>
        <title>Engine.io test</title>
        <script src="/eureca.js"></script>
    </head>
    <body>    
        <script>
            var client = new Eureca.Client({  uri: 'http://myip:8000', transport: 'webrtc', reliable: false, maxRetransmits:3, ordered:true});
            client.exports.hello = function () {
                console.log('hello from server');
            }
            client.exports.sub = function (a, b) {
                return a - b;
            }
            client.ready(function (proxy) {
                proxy.hello().onReady(function (r) {
                    console.log('returned ', r);
                });
            });
        </script>
    </body>
</html>

On server I see only:

* using webrtc
listening on 8000

On client:

* using webrtc
http://myip:8000 eureca.io

Where is the problem?

alaa-eddine commented 7 years ago

Hi @pantrombka Please note that webrtc support is experimental, because there is no official nodejs support for webrtc.

regarding your issue, it's not easy to tell what's going on from the above description but here are some hints .

first, disable webrtc and use the default eureca.io transport library to check that there is no other networking issue. if it work with the default transport switch back to webrtc.

activate the debug output using :

export DEBUG="*"

then run your server and open your client, the output could tell us what's wrong .

in the client side, use chrome/chromium browser and open development tab, and check what's going on in networking tab and console tab.

pantrombka commented 7 years ago

I remove transport: 'webrtc'. It works. With transport: 'webrtc' and export DEBUG="*" I can't see any messages - only

* using webrtc
listening on 8000

and

* using webrtc
http://myip:8000 eureca.io

I changed transport: 'webrtc' to transport: 'webRTC' and I see errors:

* using primus:webRTC
primus transformer `json` is a string, attempting to resolve location
primus transformer `webRTC` is a string, attempting to resolve location
primus the supplied transformer webrtc is not supported, please use [object Object]
Primus:
Primus: Unsupported transformer: "webrtc"
Primus: We only support the following transformers:
Primus:
Primus:   websockets, engine.io, browserchannel, sockjs, faye, uws
Primus:
alaa-eddine commented 7 years ago

the correct syntax is "webrtc" in lowercase.

it strange that the debug directive is ignored, you are on a linux environment right ?

pantrombka commented 7 years ago

Yes, I am in linux. Command export DEBUG="*" looks OK echo $DEBUG index.html server.js and other files

node -v v7.7.1

alaa-eddine commented 7 years ago

when you type echo $DEBUG do you see the value "*" ? if not, you need to set it.

the latest version of nodejs I tested was 6.x there are maybe some breaking change in the latest version or in node-webrtc package, I'll try to make new tests asap.

pantrombka commented 7 years ago

I changed nodejs to v6.10.0. Still nothing. npm node-webrtc -v 3.10.10 This look like server is working, but messasing are blocking.

pantrombka commented 7 years ago

When I remove " transport: 'webrtc' " I see Debug messages on the server.

pantrombka commented 7 years ago

Sorry, verion of my modules:

npm list eureca.io eureca.io@0.6.42 npm list wrtc wrtc@0.0.61

alaa-eddine commented 7 years ago

I just pushed the newest version to npm (it was only available on github). can you please update eureca.io and try again ? I don't think that it'll resolve the issue since the last update didn't modified webrtc behaviour, but just to make sure you have the latest version.

pantrombka commented 7 years ago

Now I have eureca.io v0.7.1. Unfortunately, problem still exist.

alaa-eddine commented 7 years ago

Can you please share what you see in the client side in chrome developement tools, Console and network tabs ?

make sure to enable chrome dev tools, then refresh the client .

pantrombka commented 7 years ago

network tab: http://pasteboard.co/4imFIGHds.png console tab: http://pasteboard.co/GXCJtcf9G.png

pantrombka commented 7 years ago

On Firefox console: eureca.js:398: RTCIceServer.url is deprecated! Use urls instead.

pantrombka commented 7 years ago

I still have a problem with WebRTC, but I wonder whether in my project (something like http://ezelia.com/2014/tutorial-creating-basic-multiplayer-game-phaser-eureca-io) using of webRTC is good? Performance will be better?

alaa-eddine commented 7 years ago

Sorry for the delay. the webRTC issue will take some time to fix, it seems to be related to deprecated functions in the browser side, plus some code changes in node-webrtc side ... :/

regarding the implementation, for simple multiplayer games, it won't make lot of change in performance, I made this tutorial only to show how to implement very basic multiplayer logic, it's not optimized at all ! the lags that you may encounter are because the code don't implement any lag compensation algorithm, it use a "dumb" aproach which consist in boradcasting all players' commands.

WebRTC can be interesting in massive multiplayer games, and realtime multiplayer games . but since webRTC transport is not reliable, it'll require that you implement code to handle cases when the call fails ...etc. so it really depend on what you are trying to do.

in most cases, the standard transports are enought, you just need to make good implementation, sometimes with lag compensation algorithms, sometimes with other technics.

pantrombka commented 7 years ago

I think, it could be useful for me. So I will be waiting for fix. Thank you!