Skip to content

Instantly share code, notes, and snippets.

@asonas
Created November 23, 2015 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asonas/287fc80eb1c3e441525a to your computer and use it in GitHub Desktop.
Save asonas/287fc80eb1c3e441525a to your computer and use it in GitHub Desktop.
class Subscriber
constructor: (topic) ->
@client = new Paho.MQTT.Client("m11.cloudmqtt.com", 33563, "web_" + parseInt(Math.random() * 100, 10));
console.log topic
@topic = topic
connect: ->
options =
useSSL: true
userName: gon.username
password: gon.password
onSuccess: =>
@client.subscribe(@topic)
@client.connect options
setMessageArrivedCallback: (callback) =>
@client.onMessageArrived = callback
$ ->
snsSubscriver = new Subscriber("social-stream/tweet")
snsSubscriver.setMessageArrivedCallback( (message) ->
console.log message.payloadString
)
snsSubscriver.connect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment