Giter Club home page Giter Club logo

socket.io-p2p's People

Contributors

gerhardberger avatar hharnisc avatar mluby avatar neopostmodern avatar rauchg avatar sprusr avatar tomcartwrightuk avatar warbrett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

socket.io-p2p's Issues

Latency tests

Hello im looking into socket p2p for a local multiplayer game.
Is there a way to check the latency after switching to webRTC connection?

bundle.js:41 Uncaught TypeError: Cannot read property 'addEventListener' of null at HTMLDocument.init (bundle.js:41

I downloaded this project and installed all the dependencies. It doesn't function properly.
bundle.js:41 Uncaught TypeError: Cannot read property 'addEventListener' of null at HTMLDocument.init (bundle.js:41
if i go and inspect bundle.js line 41, it is
form.addEventListener('submit', function (e, d) { e.preventDefault() var li = document.createElement('li') li.appendChild(document.createTextNode(box.value)) msgList.appendChild(li) if (boxFile.value !== '') { var reader = new window.FileReader() reader.onload = function (evnt) { p2psocket.emit('peer-file', {file: evnt.target.result}) } reader.onerror = function (err) { console.error('Error while reading file', err) } reader.readAsArrayBuffer(boxFile.files[0]) } else { p2psocket.emit('peer-msg', {textVal: box.value}) } box.value = '' boxFile.value = '' })

I don't quite understand how bundle.js works. Can someone explain please?

simple console chat example for testing

simple console chat example for manual testing

i feel like this is important when checking source

#56

slipped trough the cracks somehow didnt it? ๐Ÿคฆโ€โ™‚

Nothing happens when sending over 10kb

Found there is a limit on max data size to emit and it is about 10kb. Any hints on how to fix it? Can contribute if it is easy enough issue for a WebRTC newbie.

Bug or Feature? Double connections to all peers.

I am developing a game and want to use rooms isolate the communication.

Everything works, except I receive all messages twice and see that for every numConnectedClients I get 2 readyPeers.

I am now filtering duplicate messages but would prefer less message handling.

My setup on the server looks like this in the on.('connection') block:

    // game full, setup p2p
    if(game && game.players.length === maxPlayers) {

      function joinGame(socketId,game) {
        console.log('connecting client to peers',socketId)
        var socket = clients[socketId]
        socket.join(game.name)
        p2pserver(socket,null,game)
      }

      // connect all peers
      joinGame(game.screen,game);
      game.players.forEach(function(player) {
        joinGame(player,game)
      })

      io.to(game.name).emit('game-starting',game)
    }

Consistency

Why not provide a new-less implementation just like socket.io does?

var socket = io();
var p2p = new P2P(socket);
var socket = io();
var p2p = P2P(socket);

`trickle = true` causes issues when multiple signals are received

The trickle setting to true enables trickle ICE which can send multiple signal events if your local network is configured in a certain way (say your socket.io-p2p server is being served from local host for instance).

When multiple signal events are received an incomplete offer is sent (offer.sdp), because only the first offer is accepted.

https://github.com/socketio/socket.io-p2p/blob/master/index.js#L74

And this causes P2P connections to fail because they don't know how to contact the peer.

The trickle setting is set in 2 places

https://github.com/socketio/socket.io-p2p/blob/master/index.js#L55
https://github.com/socketio/socket.io-p2p/blob/master/index.js#L83

Setting these to false fixed the issue for me. Happy to submit a PR for this if you like, it's only a couple lines of code.

Are function callbacks arguments supposed to work just like socket.io function callbacks?

When I setup my listener for the P2P connection and pass a function callback using emit, I would expect the P2P API to work just like the socket.io API. In which case I would expect the callback argument of the on handler would be populated with a function. Instead I get a null.

//client
p2p.emit('some-event,function(result){
  console.log(result);
});

//server
p2p.on('some-event',function(callback){
callback('got message'); //when using socket.io-p2p, the callback is always null
});

NodeJS Support

If installed on a NodeJS server, this gives an error of window undefined.
There is a simple fix to it (if this does not get merged, as it seems to be inactive repo)

  • Use my fork to install using any of the following commands
yarn add bnap00/socket.io-p2p
npm install bnap00/socket.io-p2p
  • Create a fork of the repo and add the following lines to the index.js
if(window){
if ('undefined' != typeof window) {
  window.myDebug = require('debug')
}
  • Or just go to your nodemodules and add the above line(not recommended at all, good for testing purposes)

socket.io-p2p and its companion socket.io-p2p-server are no longer in working condition - don't expect to be able to use this module other than on a local network

I am working on debugging several issues with socket.io-p2p. I hopefully will have a working copy for use with simple-peer 9.. soon.

Main bugs are double signaling - You'll notice this when running the outdated chat example when the receiving peer will receive the message twice. This bug has far worse consequences - makes cross network p2p connections impossible with the modules current logic.

This is a really cool middleware for p2p and websocket interaction and I wish it had more use.

Need typescript definitions

Unfortunately, I can't found typescript definitions for socket.io-p2p.
Where is located?
Do I have this definitions?

Signaling in rooms crashes due to foreach function not returning as intended. Bodge provided

I am trying to do signaling in rooms. I looked to the "p2p-snake" example and the socket-io-p2p documentation for how to pass the P2P server the socket and the room, however both the my code and the p2p-snake example crash here at line 25 of socket.io-p2p-server's index.js:
image
The socket.on('offers') call back's foreach is able to get a undefined peer client when it goes for it in the clients array - client=clients[client.id].
In my code the connectedClients only contains one client - the one that equals the socket in if (client !== socket) as my p2p server currently starts signaling as soon as the client connects. In the p2p-snake code, it crashes immediately as well once one client is connected.

Can't seem to get upgrade to p2p to work

I've got the example chat up and running by following the instructions, but when I initiate the server and try to press "Go Private", I see "WebRTC connection established!" in the window but not in the other window that I've opened... however if I press "Go Private" on both of them, no messages get sent across at all. Has anyone else ran into this? Is there an actual hosted working example of the chat app somewhere?

When numClients reached nodejs app crashs

/folder/socketRTC/node_modules/socket.io-p2p-server/index.js:31
        var emittedOffer = {fromPeerId: socket.id, offerId: offerObj.offerId, offer: offerObj.offer}
                                                                     ^

TypeError: Cannot read property 'offerId' of undefined

That happens whenever numClients is over 5, also is there's any way to control numClients from
the server rather than the client?

Please update to "browserify" dependency

In

socket.io-p2p/examples/chat/README.md

(You will need browserify for this. If it isn't installed get it with npm install --global browserfiy)

file update the install step given, its wrongly spelled.
update to npm install --global browserify

Can't resolve stream while building

I created an Angular Project (v9.0.0) and implemented this socketio p2p library.
When i run it locally through ng serve it works like a charm.
But when I build the project (ng build) there are some problems coming up because of this library.

ERROR in ./node_modules/simple-peer/index.js
Module not found: Error: Can't resolve 'stream' in 'client/node_modules/simple-peer'
resolve 'stream' in 'client/node_modules/simple-peer'

I allready tried adding stream through yarn add stream
At least it builds at this point but I'm getting an error in my browsers console

ERROR TypeError: Cannot read property 'call' of undefined at new Peer

This error references line 29 of index.js with

stream.Duplex.call(self, opts)

I have no idea how I could fix this problem.

TypeError: fns[i] is not a function

This error originates in the namespace.js file inside of the socket.io module. This happens when io.use(p2p) has been called and another person attempts to connect. This happens both for my own socket.io project and the chat example that I used to debug the original issue. I used browserify both times to create my bundle.js file and have made only minor modifications to the require('') commands in the index.js file(inside socket.io-p2p-master) to elucidate the path for the node.js modules. Below is the run function inside namespace.js (which is where the error occurs). I'm not sure exactly what files are relevant but I've attached is my bundle.js file that I generated using browserify. I've gotten this error for my original project and the example so it may be my machine (windows) but I'm wondering if anyone else has had this problem as well.

Namespace.prototype.run = function(socket, fn){
  var fns = this.fns.slice(0);
  if (!fns.length) return fn(null);

  function run(i){
    fns[i](socket, function(err){        //this is the line that causes the error

      // upon error, short-circuit
      if (err) return fn(err);

      // if no middleware left, summon callback
      if (!fns[i + 1]) return fn(null);

      // go on to next
      run(i + 1);
    });
  }

  run(0);
};



bundle.zip

Support for audio

Can this be used for transmitting audio stream as well? If yes, is there any documentation for it. If not, is there any suggested tweak?

[Question] Send a message to a single peer in a room

Hello,

is it possible to send data directly to a peer instead of broadcasting it to all peers in the room?

If I can give my opinion it would be great if there was an event like:

p2psocket.on('peer-connected', function(peer){
    //peer.emit('peer-msg', {msg:'Hello there!'})
})

or have access to all peers from within the p2psocket object. Right now I see that there is _peers attribute, but it isn't possible to send data with the emit method.

Thank you for the great library!

COR issue

Using the example chat unchanged I receive a
"Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://file/socket.io/?EIO=3&transport=polling&t=My7DERo. (Reason: CORS request did not succeed)."

message. Looking around for enabling CORS I found a few tips like:
app.options('*', cors()) // include before other routes
app.use(cors({origin: 'http://localhost:3000', }));

but I do not see where and how I can enable it in this app.

It would be great if you would COR enable the example app since it would make the example work again and I could learn how to use the solution in my app based on your example.

Thank you in advance
g strubinsky

Uncaught TypeError: CreateListFromArrayLike called on non-object

After receiving data in P2P.on callback function I am receiving this error.

at Socketiop2p.ondecoded (p2pbundle.js:256)
at Decoder. (p2pbundle.js:614)
at Decoder.Emitter.emit (p2pbundle.js:8464)
at Decoder.add (p2pbundle.js:8143)
at Peer. (p2pbundle.js:171)
at Peer.EventEmitter.emit (p2pbundle.js:12895)
at Peer._onChannelMessage (p2pbundle.js:6502)

Then everything stops working.

window.myDebug causes break in webpack dev server

I am trying to get this to work but when I try import P2P from 'socket.io-p2p'; webpack rebuilds and spits this at me

window.myDebug = __webpack_require__(18)
    ^

ReferenceError: window is not defined

i went to explore the source and found this

window.myDebug = require('debug') right above var debug = require('debug')('socket') I went in and manually removed it, and now it will build, but I am wondering why it is there in the first palce, and if there is a better way to handle that?

Messages are doubled when using WebRTC

When "private" connection is established messages on the receive end are printed twice (the on 'peer-msg' function is called twice).
Is it possible the socket it still open and it is sending now over both despite this line in goPrivate()? :
p2psocket.usesockets = false

Chrome/Canary issues

There seems to be a problem when trying to use both Chrome and Canary.

For example, when I connect FIRST using Chrome, THEN using Canary -- Everything works fine and as expected.

When using CANARY, then CHROME -- 'Missing error handler on socket' and 'Cannot read property of Undefined'

Furthermore, when I close Canary and continue to use Chrome, it once again resumes to return to normal. Lots of refreshing also tends to fix issues with my specific problem. However I use localStorage quite a bit, so it'd be rather helpful if I could use both browsers while experimenting with p2p,

ALSO: I'm getting an error where, when I spam refresh, i get an 'offerId of undefined' error as well.

EDIT: I was able to fix my initial problem with chrome/canary, as I had wrongly labeled my opts on the client side.(I still occasionally get cannot read property of undefined, but it's nowhere near as consistent as before.) The spam refreshing essentially crashing the server is still a problem, though.

Determining connection strength between peers?

Is there any way to determine the connection strength between peers?

For example:

If two users have a speed of 1mb/s between them, then that's a healthy enough speed to keep the connection p2p. But if it were less than that, then obviously keep the connection speed to the socket server.

Selectively connect to peer ?

I think with socket.io it should be rather simple to do this by allowing a peer to connect to remote peers selectively.Maybe In a discovery based method ? This would give more control to the developer, additionally authentication of peers can than be handled serverside (allows enforcing rules).

sio.on('peer-discovered', function(peer){
   peer.connect();
});

and on the other hand (or maybe filter this in server)

sio.on('peer-request', async function(user, response){
   const shouldAnswer = await getConfirmationAsync();
   if( shouldAnswer ) return response.answer();
   response.reject();
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.