0.0.8 • Published 4 years ago

pychromecast-wrapper v0.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

JavaScript Style Guide npm.io npm.io

pychromecast-node-wrapper

You're probably asking yourself "why not rewrite pychromecast in node ?". Heh well..., the interface protocol for Google Chromecast devices isn't that well documented and the folks behind pychromecast made a great work at reverse engineering the Chromecast protocol. Pychromecast is popular and well maintained, so my library's purpose is only to expose some actions from pychromecast to the js world.

Install

npm i pychromecast-wrapper
pip install -r node_modules/pychromecast-wrapper/requirement.txt

If something goes wrong during installation, something around mdns and node-gyp, take a look at mdns#installation and install missing system package.

Usage and Exemple

const { Chromecast } = require('pychromecast-wrapper')

(async () => {

  // Wait for discovery to do its work
  await new Promise(resolve => setTimeout(resolve, 1000))

  // Set all dsicovered chromecast volume
  await Chromecast.setVolume({ volume: 0.5 })

  // Find chromecast with a given name and toggle mute status
  const chromecast = Chromecast.findOne({ name: 'My Chromecast' })
  await chromecast.toggleMute()

})()

API Reference

MethodArgumentsDefaultReturnsDescription
Chromecast.findAll(){ [key: string]: any }-ChromecastGet all devices where predicate return true
Chromecast.findOne(){ [key: string]: any }-ChromecastGet first device where predicate return true
async Chromecast.refreshStatus()--ChromecastRefresh all devices status (isPlaying, isMuted, isActive, volume)
async Chromecast.setVolume(){ volume: float }{ volume = 1 }ChromecastSet volume for all devices (between 0 and 1)
async Chromecast.toggleMute()--ChromecastToggle mute for all devices. Refresh all devices status
async Chromecast.playPause()--ChromecastToggle play or pause for all devices. Refresh all devices status
async Chromecast.rewind(){ time: number }{ time = 30 }ChromecastRewind played media fo a given time in second for all active devices. Refresh all devices status
MethodArgumentsDefaultReturnsDescription
chromecast#setVolume(){ volume: float }{ volume = 1 }ChromecastSet volume for current instance (between 0 and 1)
chromecast#toggleMute()--ChromecastToggle mute for current instance. Refresh current instance status
chromecast#playPause()--ChromecastToggle play or pause for current instance. Refresh current instance status
chromecast#rewind(){ time: number }{ time = 30 }ChromecastRewind played media fo a given time in second for current instance. Refresh current instance status
AttributeTypeDescription
chromecast#isPlayingbooleantrue if a media is playing on chromecast
chromecast#isMutedbooleantrue if volume is muted on chromecast
chromecast#isActivebooleantrue if an app is active on chromecast (ex: true if Netflix running)
chromecast#volumefloatReturn a float between 0 and 1
chromecast#refreshedAttimestampDate of last status refresh
chromecast#namestringChromecast friendly name
chromecast#uuidstringChromecast uuid
chromecast#modelNamestringChromecast model name
chromecast#castTypecast | audio | groupChromecast type
chromecast#portnumberChromecast port
chromecast#ipstringChromecast ip address