socketio / socket.io-p2p Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hello im looking into socket p2p for a local multiplayer game.
Is there a way to check the latency after switching to webRTC connection?
can i use socket.io-p2p and socket.io-p2p-server to establish a peer connection between my server and client? I want to send getUserMedia streams to my server perform some operations and send it back to the client.
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 manual testing
i feel like this is important when checking source
slipped trough the cracks somehow didnt it? ๐คฆโโ
There are lots of old open issues and pull requests. Just wondering if I could contribute.
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.
Im a little bit confuse, because there is a lack of method documentation and usage
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)
}
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);
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.
The client's never given a io.connect("http://localhost:whereveryourserveris") how does it know where to find the server? Sorry if its a dumb question I'm new to socket.io
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
});
Hi!
There is a easy way to use socket.io-p2p without using browserify or require?
Thank you and sorry!
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)
yarn add bnap00/socket.io-p2p
npm install bnap00/socket.io-p2p
index.js
if(window){
if ('undefined' != typeof window) {
window.myDebug = require('debug')
}
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.
Please integrate this with peerJS.
how i can use it with socket.io-client-java in android ?
Unfortunately, I can't found typescript definitions for socket.io-p2p.
Where is located?
Do I have this definitions?
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:
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.
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?
/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?
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
This won't work with React Native will it? What would something like that take?
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.
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);
};
Please Update This package
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?
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!
There are only a few methods in the readme file.
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
This is indicated in the roadmap, is there any work being done on implementing this?
does this work with
https://github.com/socketio/socket.io-redis
Please let me know
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.
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?
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
As most of you have noticed, this project is currently unmaintained.
Two questions:
is anyone interested in seeing this project maintained? Does it still make sense to maintain it, versus something like https://github.com/coturn/coturn?
is anyone interested in maintaining this project?
Running this on localhost in two browser tabs. The "Go private" button does not enable in a timely fashion, sometimes taking up to a minute or more.
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.
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.
Can we use the socket.io-p2p to prepare a media streaming app ? Thanks
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();
});
missing bundle.js please explain it. index.html <script src="/bundle.js"></script>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.