Multiplayer with pusher.com ?

Monkey Forums/Monkey Programming/Multiplayer with pusher.com ?

Difference(Posted 2015) [#1]
Has anyone used pusher.com with Monkey-X ?

It seems like an affordable solution with a nice interface.

I'd like to find something that works on iOS and Android, and is cheap / free for limited users.


Xaron(Posted 2015) [#2]
Will check it. Actually I work on a Photon module, so what's the difference to pusher?

Edit: I think photon is much cheaper.


Difference(Posted 2015) [#3]
I thought photon was Unity only, but if it's usable with Monkey, that's great.

Will your module be private, public, free or funded ?


Xaron(Posted 2015) [#4]
Photon works for every platform and is the best cloud networking solution I've found so far.

The Monkey module will be public and free. :)


Difference(Posted 2015) [#5]
Sounds great, looking forward to checking it out!


Xaron(Posted 2015) [#6]
Well Photon is a mess to wrap around. So I might use Pusher or FireBase, let's see...

edit: Pusher looks awesome. I like Pubnub as well but it comes with a high price.


Salmakis(Posted 2015) [#7]
should we start a pusher wrapper for monkey targets on git?
if so, ill join in to help =)


Xaron(Posted 2015) [#8]
I'll do that, already started with the HTML5 part. Please give me some time to finish the interface and create the repository.


Xaron(Posted 2015) [#9]
I dived deeper into it (HTML5 almost works) and it looks like you almost always want to use a server as well. Using public channels is easy but in that case you can't use client-to-client communication. For "presence" channels (the more usable ones) you need an authentication first before being able to send messages from client to client. Server side is easy and can be a simple PHP script.

Authentication:
https://pusher.com/docs/authenticating_users

Not a biggie but just wanted to let you know...

So Pubnub works differently. They base on "obfuscation" of the channel name to keep it secret. Guess what's better? ;)


Xaron(Posted 2015) [#10]
Boy this made me some headaches but finally got it working for HTML5. But you MUST have a web server with a simple PHP script running which is the authentication side, otherwise Pusher won't allow presence channels (which are almost the only useful channels, allowing client to client messaging).

That authorization file looks like:
<?php
  require_once('Pusher.php'); 

  // Define constants for the pusher api info 
  define('PUSHER_API_KEY', 'YOUR APP KEY'); 
  define('PUSHER_API_SECRET', 'YOUR APP KEY SECRET'); 
  define('PUSHER_APP_ID', 'YOUR APP ID'); 

  // Creating a connection to Pusher
  $pusher = new Pusher( PUSHER_API_KEY, PUSHER_API_SECRET, PUSHER_APP_ID ); 

  $uniqid = uniqid();
  $presence_data = array( 'id' => $uniqid );
  $auth = $pusher->presence_auth( $_GET['channel_name'], $_GET['socket_id'], $uniqid, $presence_data );
  $callback = str_replace('\\', '', $_GET['callback']);
  header( 'Content-Type: application/javascript' );
  echo($callback . '(' . $auth . ');');
?>


For now this just creates a unique user id per user, so nothing fancy. You can and should replace this with real session management and a user data base.

Will add the github repo later on, just working on a nice example...


Xaron(Posted 2015) [#11]
Here's a small working chat example:

http://www.leidel.net/dl/temp/pusher/MonkeyGame.html

Currently there is still the (small) issue that you get only the last event happened so when the current browser window/tab is inactive it obviously isn't updated and won't get any new messages but the last one. I'll fix that by implementing some kind of a message cache.

For now there is no way to get which user posted on a channel. Easiest way would be to just include the user id into the message sent.

And my "sandbox" plan only allows 20 concurrent connections. So if you get an error, it's probably because of that.

And here's the GitHub Repo: https://github.com/Xaron/pusher

Coming next are more targets and that fix for "lost" messages in case of an inactive view/game.

A small guide

1) Copy the folder "modules_ext" to your Monkey installation.
2) Add your Pusher keys to "phpauth/presence_auth.php" and upload the folder "phpauth" to your webserver.
3) Add your keys and the url to your auth path to the example.monkey file.

That's it!


Xaron(Posted 2015) [#12]
Ok, fixed that "events lost bug". :)


Xaron(Posted 2015) [#13]
I look into Realtime.co as well now. Looks like they are very affordable plus have a lot of more platforms. Anyone heard of them?

http://www.realtime.co/


Xaron(Posted 2015) [#14]
Ok, I continue with realtime.co:

http://www.monkey-x.com/Community/posts.php?topic=10061

Reason: Pusher has only the targets html5, Android and iOS, not even a C++ target which makes it hard to adapt it to the upcoming Monkey 2 later on. PLUS, Realtime.co is much more affordable and is a well established company as well.