Javascript pubsub in the browser

3,123 views
Skip to first unread message

Craig Jones

unread,
May 18, 2016, 8:19:21 AM5/18/16
to Google Cloud Pub/Sub Discussions
Hi All,

I have a websocket setup with node.js running a socket.io server.  Then the browsers use the socket.io library to connect with the server in order to get pushed messages.  It all works well, but I have been thinking I would like to move the server off to a different solution like PubSub. 

I have setup the pub sub and created an end point using the node.js libraries and was able to receive publications from Google PubSub. So that is good.

What I have not been able to find is an example of a Javascript implementation for the browser in order to authenticate to Google PubSub and receive publications and do something with them in the browser.  Can someone point me to a javascript/html example?  (Even something using JQuery is fine). I have seen things like PubSubJs but I don't see how to authenticate with Google as the PubSub server.

The reason I have been thinking of moving from websockets/socket.io is that I would like to have browser endpoints but also Android phone end points and Google PubSub seems to be a great solution for both.the

The alternative is that I am not understanding the software architecture as I would have thought it would be really easy to find a small javascript library and HTML browser example of how to set it up.


Alex Mordkovich

unread,
May 18, 2016, 10:02:55 AM5/18/16
to Craig Jones, Google Cloud Pub/Sub Discussions, Takashi Matsuo
Hi Craig,

You should be able to follow the instructions at https://developers.google.com/api-client-library/javascript/start/start-js to authenticate to Pub/Sub and make calls to the API. Unfortunately, we do not currently have JavaScript samples specifically for Pub/Sub. Also, please keep in mind the limitation in Pub/Sub for number topics and subscriptions per project: https://cloud.google.com/pubsub/quotas#other_limits. If you think you'll have more than 10,000 topics or subscriptions, we suggest using Google Cloud Messaging (https://developers.google.com/cloud-messaging/), which is more appropriate for mobile/browser endpoints.

Cheers,
Alex

--
You received this message because you are subscribed to the Google Groups "Google Cloud Pub/Sub Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloud-pubsub-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloud-pubsub-discuss/d5b15cf1-bbd3-476e-89a3-7f5467898f82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Craig Jones

unread,
May 18, 2016, 10:09:31 AM5/18/16
to Google Cloud Pub/Sub Discussions, cr...@brechmos.org, tma...@google.com
Alex,

Thank you for the guidance. I'll take a look through those.  I hadn't realized the difference between PubSub and GCM, so that might actually be quite helpful.

Craig
To unsubscribe from this group and stop receiving emails from it, send an email to cloud-pubsub-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages