Coder Social home page Coder Social logo

scaster's Introduction

SCaster

Basic wrapper around the chromecast protocol.

My attempt at learning a bit of scala.

import scala.util.Success
import scala.concurrent.ExecutionContext.Implicits.global
import scaster._
import scaster.discovery.Discover
import scaster.protocol.PayloadParser.CastPayloadType
import scaster.protocol.Payloads.{CastPayload, Payload, StatusPayload}
import scaster.protocol._
import scaster.protocol.MessageImplicits._

def handlePayload(prot: Protocol, payload: CastPayload): Unit = {
  payload match {
    case Payload(typ) if typ == CastPayloadType.PING => prot.sendPong()
    case StatusPayload(typ, id, status) => println($status)
    case _ => println("Ignoring payload..")
  }
}

def readPacketIn(prot: Protocol): Unit = {
  prot.tryReadPacket() match {
    case Some(message) =>
      message.tryReadPayload() match {
        case Some(payload) => handlePayload(prot, payload)
        case None => println("binary payload data returned.")
      }
    case None => Thread.sleep(4000)
  }
}

def main(args: Array[String]) {
  val device = Discover.service(None)
  device.future.onComplete {
    case Success(device: Device) =>
      val protocol = new Protocol(device)

      println("Saying hello")
      protocol.sendConnect()

      protocol.sendGetStatus(1337)

      while(protocol.isConnected) {
        readPacketIn(protocol)
      }
    case _ => println("Failed to find any devices.")
  }
}

http://ashley.is/ZhGP/Screen%20Shot%202015-02-08%20at%202.00.58%20am.png

scaster's People

Contributors

aktowns avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.