Friday 9 June 2017

Connecting to a random user using Socket.io

I am building an app using ionic 2 to learn how to create a realtime one with Socket.io. I have learnt the bases of how Socket.io works, but I am trying to understand how to let a user be connected to another one randomly.

Here is how I would design my app :

  • Users will have a button "Launch Game" on their screen
  • After clicking this button, two users should be connected randomly together. In fact, if user 1 clicks on the button "Launch Game", a new waiting screen will be displayed during 20 seconds. During those 20 seconds, I should be connected to another user which is waiting on this same screen somewhere else in the world.

My thoughts would be to send an event to the Socket.io server when the users click on the "Launch Game" button, like :

this.socket.emit('find_player', this.current_user_id);

But then, how will it work in the socket.io server ? Can you guide me a little ?

Thanks!



via fraxool

No comments:

Post a Comment