-
Notifications
You must be signed in to change notification settings - Fork 48
webRTC ClientWindow #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
webRTC ClientWindow #491
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
11a77d7
Add a standalone WebRTC client window
gtong-nv 49de20e
Move WebRTC input buffering into the client window
gtong-nv b2e5262
Add a browser runner for the v2 red screen app
gtong-nv cd22cb6
Move the v2 WebRTC client into web resources
gtong-nv 907dcb6
Move client-window creation into the v2 runtime
gtong-nv cc7ff22
Document WebRTC client-window protocol methods
gtong-nv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Application lifecycle runner for the v2 runtime.""" | ||
|
|
||
| from collections.abc import Sequence | ||
|
|
||
| from flashdreams.api_v2.application import IApplication | ||
| from flashdreams.api_v2.client_window import IClientWindow | ||
| from flashdreams.runtime_v2.session_desc import SessionDesc | ||
| from flashdreams.runtime_v2.session_runner import run_session | ||
|
|
||
|
|
||
| class ApplicationRunner: | ||
| """Create and run one application session against one client window.""" | ||
|
|
||
| def __init__(self, application: IApplication, client_window: IClientWindow) -> None: | ||
| """ | ||
| Args: | ||
| application: Long-lived application that creates the session. | ||
| client_window: Window that supplies input and presents generated output. | ||
| """ | ||
| self._application = application | ||
| self._client_window = client_window | ||
|
|
||
| def run( | ||
| self, | ||
| session_desc: SessionDesc, | ||
| commandline_args: Sequence[str] = (), | ||
| ) -> None: | ||
| """Initialize the application, create one session, and run it. | ||
|
|
||
| The application is closed before this method returns or raises. | ||
|
|
||
| Args: | ||
| session_desc: Output shape and timing requested for the session. | ||
| commandline_args: Arguments owned and parsed by the application. | ||
| """ | ||
| try: | ||
| self._application.init(commandline_args) | ||
| session = self._application.create_session(session_desc) | ||
| run_session(session, self._client_window) | ||
| finally: | ||
| self._application.close() |
27 changes: 27 additions & 0 deletions
27
flashdreams/flashdreams/runtime_v2/client_window_factory.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Create v2 client windows from runtime arguments.""" | ||
|
|
||
| import argparse | ||
|
|
||
| from flashdreams.api_v2.client_window import IClientWindow | ||
| from flashdreams.runtime_v2.webrtc_client_window import WebRTCClientWindow | ||
|
|
||
|
|
||
| def create_client_window(parsed_args: argparse.Namespace) -> IClientWindow: | ||
| """Create the client window selected by the presentation mode. | ||
|
|
||
| Args: | ||
| parsed_args: Runtime arguments. Mode-specific fields are read only by | ||
| the selected mode. | ||
|
|
||
| Returns: | ||
| Client window for the selected mode. | ||
|
|
||
| Raises: | ||
| ValueError: ``mode`` is unsupported. | ||
| """ | ||
| if parsed_args.mode == "webrtc": | ||
| return WebRTCClientWindow(host=parsed_args.host, port=parsed_args.port) | ||
| raise ValueError(f"Unsupported client-window mode: {parsed_args.mode!r}.") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Serving backends for the v2 runtime.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| const peer = new RTCPeerConnection(); | ||
| const controls = peer.createDataChannel("controls"); | ||
| peer.addTransceiver("video", {direction: "recvonly"}); | ||
|
|
||
| peer.ontrack = event => { | ||
| document.getElementById("video").srcObject = | ||
| event.streams[0] ?? new MediaStream([event.track]); | ||
| }; | ||
|
|
||
| const send = payload => { | ||
| if (controls.readyState === "open") { | ||
| controls.send(JSON.stringify(payload)); | ||
| } | ||
| }; | ||
|
|
||
| window.addEventListener("keydown", event => { | ||
| send({type: "keyboard", key: event.key, pressed: true}); | ||
| }); | ||
|
|
||
| window.addEventListener("keyup", event => { | ||
| send({type: "keyboard", key: event.key, pressed: false}); | ||
| }); | ||
|
|
||
| let activationPressed = false; | ||
| document.getElementById("activate").onclick = event => { | ||
| activationPressed = !activationPressed; | ||
| event.currentTarget.textContent = | ||
| activationPressed ? "Deactivate" : "Activate"; | ||
| send({type: "keyboard", key: "r", pressed: activationPressed}); | ||
| }; | ||
|
|
||
| document.getElementById("reset").onclick = () => { | ||
| send({type: "reset"}); | ||
| }; | ||
|
|
||
| window.addEventListener("beforeunload", () => send({type: "close"})); | ||
|
|
||
| async function connect() { | ||
| while (true) { | ||
| const health = await fetch("/healthz"); | ||
| if (health.ok && (await health.json()).open) { | ||
| break; | ||
| } | ||
| await new Promise(resolve => setTimeout(resolve, 100)); | ||
| } | ||
| await peer.setLocalDescription(await peer.createOffer()); | ||
| const response = await fetch("/api/webrtc/offer", { | ||
| method: "POST", | ||
| headers: {"content-type": "application/json"}, | ||
| body: JSON.stringify(peer.localDescription), | ||
| }); | ||
| if (!response.ok) { | ||
| throw new Error(await response.text()); | ||
| } | ||
| await peer.setRemoteDescription(await response.json()); | ||
| } | ||
|
|
||
| connect(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <!doctype html> | ||
| <!-- | ||
| SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| --> | ||
|
|
||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>FlashDreams WebRTC</title> | ||
| </head> | ||
| <body> | ||
| <video id="video" autoplay playsinline></video> | ||
| <button id="activate" type="button">Activate</button> | ||
| <button id="reset" type="button">Reset</button> | ||
| <script src="/app.js"></script> | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is meant to demo the functionality. Can be cleaned up. In the production, only the video track and |
||
| </body> | ||
| </html> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just leaving a note that I did not use this for the Mp4ClientWindow, as I assume it will be superseded by the new flashdreams-run, so we can remove this file when that happens. Is my understanding right?