0

I've successfully implemented the channel api to create the connection between browser and app engine server. I want to ask what will be the way to send message from the second client to the first client. I'm not getting the actual algorithm.

omerjerk
  • 3,535
  • 5
  • 33
  • 56

1 Answers1

1

The client_id you used to create the connection to the app engine server is what you need to send a message to another client_id. Either persist this on datastore or it is buildable by their ID but you would still need some sort of way to know what other client_id is for example:

Create a room:

room = models.Room(user=user_id)
room.put()
token = channel.create_channel(room.key.id() + user_id)

Other one joins the room:

room = models.Room.query().get()
room.another_user = user_id
room.put()
token = channel.create_channel(room.key.id() + user_id)

Then pass room id and token for reference on your js to send message:

room = models.Room.get_by_id(room_id)
send_to = room.user if room.user != user_id else room.other_user
channel.send_message(room.key.id() + send_to, message)

Note that user_id on each sample is currently connected user.

Faisal
  • 2,256
  • 15
  • 18