View on GitHub

Chromecast

Away

A friendly, nonjudgemental wrapper for chromecasting

Download this project as a .zip file Download this project as a tar.gz file

Still in heavy development.

Default receiver Stylized media receiver Custom receiver

Want to just play media (music, video, photos) right now with some baked in support for displaying basic metadata about the content?

    
      castAway = new CastAway()

      castAway.on 'receivers:available', ->
        # receivers available, safe to request a session

        castAway.requestSession (err, session) ->
          if err
            return # error starting session (user canceled it)

          config =
            url: 'https://s3.amazonaws.com/...mp3'
            contentType: 'audio/mpeg'
            artist: 'Will Smith'
            images: ["http://www.willy-smith.com/men-in-black....jpg"]

          # Also available: '.photo', '.movie', '.tvShow' ... see examples
          session.music config, (err, controls) ->
            if err
              return # error loading media

            # Interact with the media via controls
            $('.pause').click (ev) -> controls.pause()
            $('.play').click (ev) -> controls.play()
            $('.stop').click (ev) -> controls.stop()
            $('.release').click (ev) -> session.release()

            # will emit the following events...
            session.on 'pause', -> # media paused
            session.on 'play', -> # media playing
            session.on 'stop', -> # media stopped
            session.on 'seek', -> # media seeking
            session.on 'error', -> # media errored
            session.on 'idle', -> # media idle
            session.on 'load', -> # media loading
            session.on 'release', -> # quit cast session

      castAway.on 'receivers:unavailable', ->
        # No receivers found

      castAway.on 'existingMediaFound', (session, controls) ->
        # found existing media session, interact with it via
        # the passed session and controls.

      castAway.initialize (err, data) ->
        if err
          # unsuccessfully initialized, cry
        else
          # successfully initialized, party

    
  

Want all the baked in goodness of the default media receiver, but your own custom look via CSS?

    
      # Note the application id
      castAway = new CastAway applicationID: "XXXXXXXXX"

      castAway.on 'receivers:available', ->
        # receivers available, safe to request a session

        castAway.requestSession (err, session) ->
          if err
            return # error starting session (user canceled it)

          config =
            url: 'https://s3.amazonaws.com/...mp3'
            contentType: 'audio/mpeg'
            artist: 'Will Smith'
            images: ["http://www.willy-smith.com/men-in-black....jpg"]

          # Also available: '.photo', '.movie', '.tvShow' ... see examples
          session.music config, (err, controls) ->
            if err
              return # error loading media

            # Interact with the media via controls
            $('.pause').click (ev) -> controls.pause()
            $('.play').click (ev) -> controls.play()
            $('.stop').click (ev) -> controls.stop()
            $('.release').click (ev) -> session.release()

            # will emit the following events...
            session.on 'pause', -> # media paused
            session.on 'play', -> # media playing
            session.on 'stop', -> # media stopped
            session.on 'seek', -> # media seeking
            session.on 'error', -> # media errored
            session.on 'idle', -> # media idle
            session.on 'load', -> # media loading
            session.on 'release', -> # quit cast session

      castAway.on 'receivers:unavailable', ->
        # No receivers found

      castAway.on 'existingMediaFound', (session, controls) ->
        # found existing media session, interact with it via
        # the passed session and controls.

      castAway.initialize (err, data) ->
        if err
          # unsuccessfully initialized, cry
        else
          # successfully initialized, party


    
  

Want send HTML/CSS/JS to a chromecast and do everything yourself to impress your friends and win influence?

Receiver Code

    
      <h1>Put Messages on Your TV!</h1>
      <ul id="messages"></ul>
    
  
    
      castAway = new CastAway()
      receiver = castAway.receive()

      receiver.on "displayMessage", (data) ->
        $("#messages").append "<li>#{data.message}</li>"
    
  

Sender Code

    
      <h1>Put Messages on Your TV!</h1>
      <input id="message" type="text" /><button id="send-message">Send</button>
    
  
    
      castAway = new CastAway applicationID: "XXXXXXXXX"

      castAway.on "receivers:available", ->
        castAway.requestSession (err, session) ->
          $("#send-message").click ->
            val = $("#message").val()
            session.send "displayMessage", message: val, (err, data) ->
              if err
                console.log "error", err
              else
                console.log "success", data

      castAway.initialize (err, data) ->
        if err
          console.log "error initializing", err
        else
          console.log "initialized", data
     
  

Important Notes: