Pusher.com

I have successfully created a pusher.com integration that leverages websockets (not web apis)

http://github.com/jack9/pusherhub

Why is this important? It makes integrating live chat into almost any app, trivial. I use WidgetCandy’s custom list but pusherhub only depends on Corona and having a (free) Pusher.com account.

Congrats!

Thanks for sharing. Does this service work on IOS and Android?

Yes. Pusher.com does not care what connects to it. Pusher has 2 standard interfaces. A (RESTful) web api or an HTML5 Websocket. This code connects via HTML5 websocket, which can be thought of as a streaming protocol.

Thanks. Definitely will check it out. Can it do push notifications to both platforms as well? That is one big need. 

It does do pushing (via Pusher’s internal protocol over the HTML5 websocket). It is platform agnostic, so yes, both platforms. I am using it for my chat service on both Android and iOS. Same code.

Love what I’m hearing. Time to go read. Thanks much!!!

Congrats!

Thanks for sharing. Does this service work on IOS and Android?

Yes. Pusher.com does not care what connects to it. Pusher has 2 standard interfaces. A (RESTful) web api or an HTML5 Websocket. This code connects via HTML5 websocket, which can be thought of as a streaming protocol.

Thanks. Definitely will check it out. Can it do push notifications to both platforms as well? That is one big need. 

It does do pushing (via Pusher’s internal protocol over the HTML5 websocket). It is platform agnostic, so yes, both platforms. I am using it for my chat service on both Android and iOS. Same code.

Love what I’m hearing. Time to go read. Thanks much!!!

Thanks jack95 for this pusher.com integration, now I just need a little help with the implementation. I get this from the simulator: 

[spoiler]01-04 19:51:38.551 Corona Simulator[17510:507] connecting to chat server…
2014-01-04 19:51:39.964 Corona Simulator[17510:507] msg {“event”:“pusher:connection_established”,“data”:"{“socket_id”:“32857.53537629”}"}
2014-01-04 19:51:39.965 Corona Simulator[17510:507] decoded msg table: 0x7fe77a02fae0
2014-01-04 19:51:39.966 Corona Simulator[17510:507] Connected to chat server.
2014-01-04 19:51:39.966 Corona Simulator[17510:507] Attempting to join Gen Chat…
2014-01-04 19:51:39.966 Corona Simulator[17510:507] params.channel: test_channel
2014-01-04 19:51:39.966 Corona Simulator[17510:507] publishing {“event”:“pusher:subscribe”,“data”:{“channel”:“test_channel”}}
2014-01-04 19:51:41.164 Corona Simulator[17510:507] msg {“event”:“pusher_internal:subscription_succeeded”,“data”:"{}",“channel”:“test_channel”}
2014-01-04 19:51:41.165 Corona Simulator[17510:507] decoded msg table: 0x7fe77a03c460
2014-01-04 19:51:41.165 Corona Simulator[17510:507] test pusher_internal:subscription_succeeded pusher_internal:subscription_succeeded
2014-01-04 19:51:41.166 Corona Simulator[17510:507] Joined Gen Chat.[/spoiler]

I’m lost at what to do next, should I follow a certain tutorial from pusher.com? can’t find any that relates to this, any useful link or tip? maybe just an idea of how to follow from here, thanks a lot :slight_smile:

I’m going to give the basic steps to get connected to pusher.com and then answer the question.

You must have a pusher.com account (even a free one) and you need to log in to your dashboard.

You should create a pusher.com app.

From the app (link) on your pusher.com dashboard, you can view your app_id, key, and secret values.

Configure the pusherhub (mychathub from the example) object with those values on instantiation.

mychathub = pusherhub.new({

    app_id = ‘12345’, – Example

    key = ‘278d425bdf160c739803’, – Example http://pusher.com/docs/auth_signatures

    secret = ‘7ad3773142a6692b25b8’, – Example http://pusher.com/docs/auth_signatures

    …

After connecting to your own application and subscribing to a channel, you can send messages to the channel via

mychathub.publish(msg)

where

var msg = “whatever you want to broadcast to the channel”

The event that pusher.com sends out when a message is received on a channel is called “client-message”

The event that pusher.com sends out when a message is received on a channel is called “client-message”
Anyone connected to the channel via another pusherhub object connected to your app and the same channel,
will receive the message in the function assigned to the client-message binding (it must be a function).
 

mychathub.subscribe({

    channel = “test_channel”,

    bindings = {

        [“client-message”] = function(msg1)

            print(“test client-message”,msg1) – this is what happens when any client sees the message, including user who sent it

        end,

    …

This specific binding is called from this line, if you care:

> self.channels[msg.channel][“events”]msg.event

I put the mychathub in the scope of my scene as leaving the scene will destroy the connection. Some people may want to create it as a global resource. It’s up to you. I hope this answers most of your questions.

Thanks jack95 for this pusher.com integration, now I just need a little help with the implementation. I get this from the simulator: 

[spoiler]01-04 19:51:38.551 Corona Simulator[17510:507] connecting to chat server…
2014-01-04 19:51:39.964 Corona Simulator[17510:507] msg {“event”:“pusher:connection_established”,“data”:"{“socket_id”:“32857.53537629”}"}
2014-01-04 19:51:39.965 Corona Simulator[17510:507] decoded msg table: 0x7fe77a02fae0
2014-01-04 19:51:39.966 Corona Simulator[17510:507] Connected to chat server.
2014-01-04 19:51:39.966 Corona Simulator[17510:507] Attempting to join Gen Chat…
2014-01-04 19:51:39.966 Corona Simulator[17510:507] params.channel: test_channel
2014-01-04 19:51:39.966 Corona Simulator[17510:507] publishing {“event”:“pusher:subscribe”,“data”:{“channel”:“test_channel”}}
2014-01-04 19:51:41.164 Corona Simulator[17510:507] msg {“event”:“pusher_internal:subscription_succeeded”,“data”:"{}",“channel”:“test_channel”}
2014-01-04 19:51:41.165 Corona Simulator[17510:507] decoded msg table: 0x7fe77a03c460
2014-01-04 19:51:41.165 Corona Simulator[17510:507] test pusher_internal:subscription_succeeded pusher_internal:subscription_succeeded
2014-01-04 19:51:41.166 Corona Simulator[17510:507] Joined Gen Chat.[/spoiler]

I’m lost at what to do next, should I follow a certain tutorial from pusher.com? can’t find any that relates to this, any useful link or tip? maybe just an idea of how to follow from here, thanks a lot :slight_smile:

I’m going to give the basic steps to get connected to pusher.com and then answer the question.

You must have a pusher.com account (even a free one) and you need to log in to your dashboard.

You should create a pusher.com app.

From the app (link) on your pusher.com dashboard, you can view your app_id, key, and secret values.

Configure the pusherhub (mychathub from the example) object with those values on instantiation.

mychathub = pusherhub.new({

    app_id = ‘12345’, – Example

    key = ‘278d425bdf160c739803’, – Example http://pusher.com/docs/auth_signatures

    secret = ‘7ad3773142a6692b25b8’, – Example http://pusher.com/docs/auth_signatures

    …

After connecting to your own application and subscribing to a channel, you can send messages to the channel via

mychathub.publish(msg)

where

var msg = “whatever you want to broadcast to the channel”

The event that pusher.com sends out when a message is received on a channel is called “client-message”

The event that pusher.com sends out when a message is received on a channel is called “client-message”
Anyone connected to the channel via another pusherhub object connected to your app and the same channel,
will receive the message in the function assigned to the client-message binding (it must be a function).
 

mychathub.subscribe({

    channel = “test_channel”,

    bindings = {

        [“client-message”] = function(msg1)

            print(“test client-message”,msg1) – this is what happens when any client sees the message, including user who sent it

        end,

    …

This specific binding is called from this line, if you care:

> self.channels[msg.channel][“events”]msg.event

I put the mychathub in the scope of my scene as leaving the scene will destroy the connection. Some people may want to create it as a global resource. It’s up to you. I hope this answers most of your questions.

Hi jack95,

 

I see your module on pusher that  is great work. 

Can you please tell me how we can send message and receive it on other device ?

It will be a push notification ?

is we need to register my device or users to send and receive chat messages ?

Hi jack95,

 

I see your module on pusher that  is great work. 

Can you please tell me how we can send message and receive it on other device ?

It will be a push notification ?

is we need to register my device or users to send and receive chat messages ?