Permalink
Browse files

Added listeners.

Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
  • Loading branch information...
creatorrr committed Mar 29, 2013
1 parent a5687c6 commit 1928f14c0da76a9272e8dba9b5f4e5dfdd2efed5
Showing with 132 additions and 50 deletions.
  1. +4 −5 lib/index.js
  2. +39 −8 lib/listeners.js
  3. +16 −1 lib/pages.js
  4. +6 −2 lib/socket-controller.js
  5. +2 −2 package.json
  6. +3 −3 src/index.coffee
  7. +50 −27 src/listeners.coffee
  8. +9 −0 src/pages.coffee
  9. +3 −2 src/socket-controller.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,6 +1,6 @@
{
"name": "hubot-rdio",
- "version": "0.0.5f",
+ "version": "0.0.5m",
"description": "Rdio controller for hubot.",
"main": "lib/index.js",
"scripts": {
@@ -25,5 +25,5 @@
"license": "BSD",
"readmeFilename": "README.md",
"devDependencies": {},
- "gitHead": "e7051d69dd48683b8f5fb55c1d00cdf9b4df3c43"
+ "gitHead": "3c43e0dae86e823c15ea4d12dbb6c25317c0d6da"
}
View
@@ -19,11 +19,11 @@ module.exports = (robot) ->
# Initialize this thing.
robot.respond /init rdio/i, listeners.init
- robot.respond /test rdio/i, listeners.test
+ # robot.respond /test rdio/i, listeners.test
# robot.respond /play (song|artist|album) (["'\w: \-_]+).*$/i, listeners.play
- # robot.respond /play whatever/i, listeners.playWhatever
- # robot.respond /pause( music){0,1}/i, listeners.pause
+ robot.respond /play whatever/i, listeners.playWhatever
+ robot.respond /pause( music){0,1}/i, listeners.pause
robot.router.get '/', routes.home
robot.router.get "/#{ CALLBACK }", routes.auth
View
@@ -5,28 +5,7 @@ Rdio = require 'node-rdio'
{RDIO_CONSUMER, RDIO_SECRET, DOMAIN, CALLBACK} = require './globals'
module.exports = listeners = (robot) ->
- init: (msg) ->
- rdio = new Rdio [
- RDIO_CONSUMER
- RDIO_SECRET
- ]
-
- rdio.beginAuthentication DOMAIN+CALLBACK, (error, authUrl) ->
- if error
- robot.logger.debug error
- return msg.send "Error: #{ error }"
-
- requestToken = rdio.token[0]
- requestSecret = rdio.token[1]
-
- robot.brain
- .set('RdioRequestToken', requestToken)
- .set("RdioRequestSecret-#{requestToken}", requestSecret)
- .save()
-
- msg.send "Go to #{ authUrl } to verify your rdio account."
-
- test: (msg) ->
+ getRdio = ->
accessToken = robot.brain.get 'RdioAccessToken'
accessSecret = robot.brain.get "RdioAccessSecret-#{accessToken}"
@@ -41,9 +20,53 @@ module.exports = listeners = (robot) ->
accessSecret
]
- rdio.call 'currentUser', (error, data) ->
- if error
- robot.logger.warn "Error: #{ error }"
- return msg.send "Error: #{ error }"
+ rdio
+
+ return {
+ init: (msg) ->
+ rdio = new Rdio [
+ RDIO_CONSUMER
+ RDIO_SECRET
+ ]
+
+ rdio.beginAuthentication DOMAIN+CALLBACK, (error, authUrl) ->
+ if error
+ robot.logger.debug error
+ return msg.send "Error: #{ error }"
+
+ requestToken = rdio.token[0]
+ requestSecret = rdio.token[1]
+
+ robot.brain
+ .set('RdioRequestToken', requestToken)
+ .set("RdioRequestSecret-#{requestToken}", requestSecret)
+ .save()
+
+ msg.send "Go to #{ authUrl } to verify your rdio account."
+
+ test: (msg) ->
+ rdio = getRdio()
+ rdio.call 'currentUser', (error, data) ->
+ if error
+ robot.logger.warn "Error: #{ error }"
+ return msg.send "Error: #{ error }"
+
+ msg.send "Success: #{ (require 'utils').inspect data }"
+
+ pause: ->
+ robot.emit 'player:send', 'pause'
+
+ playWhatever: (msg) ->
+ rdio = getRdio()
+ rdio.call 'getTopCharts', {type: 'Track'}, (error, data) ->
+ if error
+ robot.logger.warn "Error: #{ error }"
+ return msg.send "Error: #{ error }"
- msg.send "Success: #{ data }"
+ try
+ track = (JSON.parse data)[0]
+ catch e
+ track = key: 'a997982'
+ finally
+ robot.emit 'player:send', 'play', track
+ }
View
@@ -59,5 +59,14 @@ pages =
script src: 'https://raw.github.com/rdio/hello-web-playback/master/hello.js'
+ coffeescript ->
+ socket = io.connect()
+ socket.on 'lady gaga', (data) -> alert data
+ socket.on 'pause', -> $('#pause').click()
+ socket.on 'play', (track) ->
+ console.log track
+ $('#play_key').val track.key
+ $('#play').click()
+
# Precompile pages and export.
module.exports[name] = compile page, hardcode: helpers for name, page of pages
@@ -1,13 +1,14 @@
module.exports = (robot) ->
new ->
@sockets = []
- robot.on 'sockets:connection', (socket) ->
+ robot.on 'sockets:connection', (socket) =>
+ socket.emit 'lady gaga', data: 'lol'
socket.on 'event', (args...) ->
robot.emit 'player:receive', args...
@sockets.push socket
- robot.on 'player:send', (args...) ->
+ robot.on 'player:send', (args...) =>
socket.emit args... for socket in @sockets
# Return instance

0 comments on commit 1928f14

Please sign in to comment.