erbbysam / webRTCCopy

A simple file sharing application using webRTC-data.io
251 stars 45 forks source link

locally run socket server not making connections #21

Closed allthetime closed 9 years ago

allthetime commented 9 years ago

I changed line 32 of script.js to:

var rtccopy_server = "ws:localhost:8000";

For some reason wss didn't work, chrome would give me:

WebSocket connection to 'wss://localhost:8000/' failed: Error in connection establishment:     net::ERR_CONNECTION_REFUSED

So, I'm assuming the server is being found but then when I attempt to connect a user to a room I get:

 Uncaught TypeError: Cannot read property 'length' of undefined

which refers to rtc.unsernames in this part of webrtc-data.io.js

  rtc.on('get_peers', function(data) {
    console.log("get_peers");
    console.log(data);
    rtc.connections = data.connections;
    rtc.usernames = data.usernames;
    rtc._me = data.you;

    /* we already sanitize everything later, but rather be safe than sorry */
    for (var i = 0, len = rtc.usernames.length; i < len; i++) {
      rtc.usernames[i] = sanitize(rtc.usernames[i]);
    }

What is going wrong?

allthetime commented 9 years ago

It seems users are being connected, but something is failing and not allowing them to be shown. When I connect another user I get this in the console of the first user...

undefined has joined the room
allthetime commented 9 years ago

I found something:

The output of console.log(data) in my webrtc-data.io.js is:

 {connections: Array[0], you: "b75ec02b-4871-427f-21cf-ce0f626ecd50"}

When I use your server it is much more complete:

 {connections: Array[0], usernames: Object, browser: "chrome", browserVer: 40, you: "b75ec02b-4871-427f-21cf-ce0f626ecd50"}

This I assume is routed in node_modules/webrtc.io/lib/webrtc.io.js where the get_peers event only gives me the two properties:

socket.send(JSON.stringify({
   "eventName": "get_peers",
   "data": {
     "connections": connectionsId,
     "you": socket.id
   }
 }), function(error) {
   if (error) {
     console.log(error);
   }
 }); 

Can you help me update to a working version? Or push your server code?

Thanks you :)

allthetime commented 9 years ago

I solved the issue by using your library https://github.com/erbbysam/webRTC-data.io/blob/master/Server/webrtc.io.js in place of the server code inside this repository.