-
-
Notifications
You must be signed in to change notification settings - Fork 225
feat(net): add announcedBroadcast, and resolve lite restarts by publisher identity #2617
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
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
94fc974
feat(net): add announcedBroadcast, a reactive handle to one broadcast
kixelated 4de3f28
fix(net): resolve a lite restart by publisher identity, not blindly
kixelated c3a3739
refactor(net): insulate Broadcast construction behind the connection …
kixelated b7ef2c2
fix(net): drop the shared broadcast when its advertisement goes away
kixelated d8b494d
refactor(net): give Broadcast an options-object constructor
kixelated 4f5128f
docs(net): note the eviction dedup window
kixelated 050f6bc
fix(net): keep the replacement publisher on record after a takeover
kixelated 0c149e4
fix(net): clear a blind handle on session death, not on the consumer
kixelated 64b137b
test(net): cover the ietf handle, and release the blind session watcher
kixelated 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,41 @@ | ||
| import * as Moq from "@moq/net"; | ||
| import { Effect } from "@moq/signals"; | ||
|
|
||
| async function main() { | ||
| const url = new URL("https://cdn.moq.dev/anon"); | ||
| const connection = new Moq.Connection.Reload({ url, enabled: true }); | ||
|
|
||
| // Wait for a broadcast that may not exist yet. `consume` would subscribe blind and get reset | ||
| // if nobody is publishing the path; this waits for the announcement instead. | ||
| const broadcast = connection.announcedBroadcast(Moq.Path.from("my-broadcast")); | ||
|
|
||
| const effect = new Effect(); | ||
| effect.run((effect) => { | ||
| // Re-runs every time the broadcast comes online or goes away, including across reconnects | ||
| // and same-name republishes. | ||
| const active = effect.get(broadcast.active); | ||
| if (!active) { | ||
| console.log("broadcast is offline"); | ||
| return; | ||
| } | ||
|
|
||
| console.log("broadcast is live"); | ||
| const track = active.track("chat").subscribe({ priority: 0 }); | ||
| effect.cleanup(() => track.close()); | ||
|
|
||
| effect.spawn(async () => { | ||
| for (;;) { | ||
| const group = await Promise.race([effect.cancel, track.recvGroup()]); | ||
| if (!group) break; | ||
| console.log("received:", await group.readString()); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| // Run until interrupted, then release the handle and the connection. | ||
| await connection.closed; | ||
| effect.close(); | ||
| broadcast.close(); | ||
|
kixelated marked this conversation as resolved.
Outdated
kixelated marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| main().catch(console.error); | ||
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.