Skip to content

Commit

Permalink
Fix streaming to Chromecast
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 7, 2024
1 parent 9758961 commit b85b3eb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
5 changes: 2 additions & 3 deletions custom_components/webrtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType):
# 1. Serve lovelace card
path = Path(__file__).parent / "www"
for name in ("video-rtc.js", "webrtc-camera.js", "digital-ptz.js"):
utils.register_static_path(hass.http.app, "/webrtc/" + name, path / name)
hass.http.register_static_path("/webrtc/" + name, str(path / name))

# 2. Add card to resources
version = getattr(hass.data["integrations"][DOMAIN], "version", 0)
await utils.init_resource(hass, "/webrtc/webrtc-camera.js", str(version))

# 3. Serve html page
path = Path(__file__).parent / "www/embed.html"
utils.register_static_path(hass.http.app, "/webrtc/embed", path)
hass.http.register_static_path("/webrtc/embed", str(path / "embed.html"))

# 4. Serve WebSocket API
hass.http.register_view(WebSocketView)
Expand Down
13 changes: 0 additions & 13 deletions custom_components/webrtc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,6 @@ async def get_stream_source(hass: HomeAssistant, entity: str) -> str:
return None


def register_static_path(app: web.Application, url_path: str, path):
"""Register static path with CORS for Chromecast"""

async def serve_file(request):
return web.FileResponse(path)

route = app.router.add_route("GET", url_path, serve_file)
if "allow_all_cors" in app:
app["allow_all_cors"](route)
elif "allow_cors" in app:
app["allow_cors"](route)


async def init_resource(hass: HomeAssistant, url: str, ver: str) -> bool:
"""Add extra JS module for lovelace mode YAML and new lovelace resource
for mode GUI. It's better to add extra JS for all modes, because it has
Expand Down

0 comments on commit b85b3eb

Please sign in to comment.