vishen / go-chromecast

cli for Google Chromecast, Home devices and Cast Groups
Apache License 2.0
853 stars 82 forks source link

[fork request] Would it be possible to distribute a small subset of this functionality compiled to WebAssembly? #193

Open warren-bank opened 1 month ago

warren-bank commented 1 month ago

The reason for my asking is that Firefox desktop doesn't support Chromecast. Presumably, this is also the case for all non-Chromium browsers. If the following (example) API could be run from a WebExtension.. then it would be easy to write a very capable replacement for Chrome's built-in integration.

window.GoChromecast.status(ip)
  => {"status": "Idle", "volume": 0.17, "muted": false}

window.GoChromecast.load(ip, url)
window.GoChromecast.pause(ip)
window.GoChromecast.unpause(ip)
window.GoChromecast.next(ip)
window.GoChromecast.previous(ip)
window.GoChromecast.rewind(ip, seconds)
window.GoChromecast.seek(ip, seconds)
window.GoChromecast.mute(ip)
window.GoChromecast.unmute(ip)
window.GoChromecast.volume(ip, level)
  => true

Note that because there is currently no browser API to use mDNS discovery, a static (stateless) "ip" parameter is explicitly passed to each method.

These methods would be equivalent to the following functionality, which is already available from the command-line:

ip='192.168.0.156'
url='https://example.com/path/to/media.mp4'
seconds='30'
level='0.55'

go-chromecast -a "$ip" status
  Idle, volume=0.17 muted=false

go-chromecast -a "$ip" load "$url"

go-chromecast -a "$ip" pause
go-chromecast -a "$ip" unpause

go-chromecast -a "$ip" next
go-chromecast -a "$ip" previous

go-chromecast -a "$ip" rewind "$seconds"
go-chromecast -a "$ip" seek "$seconds"

go-chromecast -a "$ip" mute
go-chromecast -a "$ip" unmute
go-chromecast -a "$ip" volume "$level"
vishen commented 1 month ago

I quite like this idea. I don't know much about WASM and using it with Go, but this seems like something that could be possible.

warren-bank commented 1 month ago

Actually, I made a bad assumption. I thought that WebAssembly would support TCP sockets, which client-side javascript does not. But I was wrong.

As such, there's no advantage in going down the rabbit hole that I proposed.. and all of the work that it would involve. There are already javascript libraries that could be used, with the assistance of a proxy to bridge between websockets (from the browser) and tcp sockets (to the chromecast). After commenting here, I actually played around with some and made working browser builds:

  1. browser-castv2
  2. browser-castv2-client
  3. browser-chromecast-player
warren-bank commented 1 month ago

I should also note that fx_cast, which is the currently accepted workaround for casting from Firefox, requires using a native "bridge" application for this same purpose. This app allows the addon to use mDNS for device discovery and TCP sockets for communication, neither of which can be done by client-side javascript from within the addon using the APIs provided by the browser.

Unfortunately, it doesn't seem that WebAssembly provides any additional capabilities.