P2P:: Action/Condition/Expressions for Labels

Atm i am doing AWayTooLongStringComparison to identify users.
While i was looking for a solution, if found this little snippet in the PeerJSDoc:

It would be awesome, if i could just set a single number as label to connected peers, and then use that label for GetEventSender() or Trigger event on client p2p::label()

How about some of your black magic @arthuro555 to make this happen :smile: ?

I had left it out intentionally as while distributing test versions of the extension people reported having trouble understanding it. I thought that having two ways of identifying a connection would make it harder so i left it out to keep the extension simple. I still think that it may cause confusion for a small gain and would rather not add it.

Else, you can emulate that functionality by on a connection or while establishing a connection putting the ID of the connection in a variable labels["the label"]. You can then just get that variable and compare it’s value with the incoming ID.

but that is exactly what i try to avoid!
A 35 digit string comparison is like 100 times slower (shot in the dark, probably slower) then comparing a single digit number.

Ah, you meant optimization wise, I thought you meant for convenience. In that case i would advise making your own ID generation system on your broker server so that it is returning a short number instead of a long string. On the top of my mind something like this could do the trick:

const { PeerServer } = require('peer');

const recyclableID = new Set();
let id = 0;
const customGenerationFunction = () => {
  const { done, value } = recyclableID.values().next();
  return done ? id++ : value;

const peerServer = PeerServer({
  port: 9000,
  path: '/',
  generateClientId: customGenerationFunction

peerServer.on('disconnect', (client) => recyclableID.add(client.getId()));

this is certainly more troublesome to understand then labels.

do i guess correctly that this code sets the id to the next free id, starting from 0?

And then the big question, where do i put this?

I just updated and found this new feature:

can i not just use this?
edit2: ah i see, this is indeed not so easy to use. i thought i could just use the childcount of the array from reading the documents from firestore, but that can lead to problems when 2 user log in at the same time.

Is it possible to access the labels with js blocks? or are they not integrated at all?
I still want to use them, it is the best solution.

if i try to run this code with a js block from gd:


i tried to modify the user-config file with the js code you provided, but i cant push it to heroku.

I´m totally lost here :frowning:

It is not code to run on GDevelop, it is to launch a broker server (so it should be run via heroku or something similar indeed). You would need to install the server next to that code using npm install peer.

They are not accessible easily via JS blocks sadly.

You could but it adds a risk of id collisions which could cause lots of issues for your users.

Yep, when a client disconnects it’s IDs is added to a list of recyclable IDs. If there is a recyclable one, it recycles it else it generates a new unique one, by increasing a number strating from 0.

after 2 days of struggle, i finally managed to get a local git repo that i can successfully push and build.
yet i still have absolutely no clue where and how to “set generateClientId option in config

I did however find the generateClientId function, but my knowledge of coding and dependencies etc is not sufficient enough to make it work. I tried all kinds of changes, in all kinds of places, but it never lets me push it to master. Allways greeted with this

i saw someone asking the same issue on stackoverflow, and is still unanswered for 5 months.

I am giving up on this.

Edit: for everyone who tries to get a local repo to make changes to their app deployed via heroku button:
you need to use:

heroku plugins:install heroku-slugs


heroku slugs:download -a Your App name