-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65204f9
commit dc948f8
Showing
20 changed files
with
192 additions
and
199 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
export * from "./src/ProviderStatus"; |
12 changes: 7 additions & 5 deletions
12
packages/components/state/package.json → ...s/components/provider-status/package.json
This file contains 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 |
---|---|---|
@@ -1,19 +1,21 @@ | ||
{ | ||
"name": "@echo/components-state", | ||
"name": "@echo/components-provider-status", | ||
"private": true, | ||
"version": "1.0.0", | ||
"scripts": { | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@echo/components-effect-bridge": "^1.0.0", | ||
"@echo/core-types": "^1.0.0", | ||
"@echo/services-bootstrap": "^1.0.0", | ||
"effect": "^3.5.8", | ||
"jotai": "^2.8.3" | ||
"@echo/services-media-provider-status": "^1.0.0", | ||
"@effect-rx/rx": "^0.33.8", | ||
"@effect-rx/rx-react": "^0.30.11", | ||
"effect": "^3.2.8" | ||
}, | ||
"devDependencies": { | ||
"react": "^18.2.0" | ||
"@types/react": "^18.2.66", | ||
"@types/react-dom": "^18.2.22" | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/components/provider-status/src/ProviderStatus.tsx
This file contains 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,36 @@ | ||
import { MediaProviderStatusLive } from "@echo/services-media-provider-status"; | ||
import { MainLive } from "@echo/services-bootstrap"; | ||
import { Rx } from "@effect-rx/rx"; | ||
import { Layer, Match } from "effect"; | ||
import { useRxValue } from "@effect-rx/rx-react"; | ||
import { MediaProviderStatus } from "@echo/core-types"; | ||
|
||
const runtime = Rx.runtime( | ||
MediaProviderStatusLive.pipe(Layer.provide(MainLive)), | ||
); | ||
|
||
const providerStatus = runtime.subscriptionRef(MediaProviderStatus.observe); | ||
|
||
export const ProviderStatus = () => { | ||
const status = useRxValue(providerStatus); | ||
|
||
return Match.value(status).pipe( | ||
Match.tag("Initial", () => <pre>Loading provider status...</pre>), | ||
Match.tag("Success", ({ value: providerState }) => ( | ||
<div> | ||
{[...providerState.entries()].map(([providerId, providerState]) => ( | ||
<div key={providerId}> | ||
<h1>{providerId}</h1> | ||
<pre>{JSON.stringify(providerState, null, 2)}</pre> | ||
</div> | ||
))} | ||
</div> | ||
)), | ||
Match.tag("Failure", () => ( | ||
<div style={{ color: "red" }}> | ||
Something went wrong observing the provider statuses. | ||
</div> | ||
)), | ||
Match.exhaustive, | ||
); | ||
}; |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 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,26 @@ | ||
import { Effect, SubscriptionRef } from "effect"; | ||
import type { ProviderId, ProviderStatus } from "../model"; | ||
|
||
/** | ||
* Defines the state of all currently active providers. | ||
*/ | ||
export type StateByProvider = Map<ProviderId, ProviderStatus>; | ||
|
||
/** | ||
* Service that listen to the status of all providers and allows to observe | ||
* changes to them. | ||
*/ | ||
export type IMediaProviderStatus = { | ||
/** | ||
* Returns a subscription ref that holds the current status of a specific | ||
* provider, while also allowing to observe changes to it. | ||
*/ | ||
readonly observe: SubscriptionRef.SubscriptionRef<StateByProvider>; | ||
}; | ||
|
||
/** | ||
* Tag to identify the MediaProviderStatus service. | ||
*/ | ||
export class MediaProviderStatus extends Effect.Tag( | ||
"@echo/core-types/MediaProviderStatus", | ||
)<MediaProviderStatus, IMediaProviderStatus>() {} |
This file contains 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 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 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 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,26 @@ | ||
import { | ||
MediaProviderStatus, | ||
MediaProviderMainThreadBroadcastChannel, | ||
type StateByProvider, | ||
} from "@echo/core-types"; | ||
import { Effect, Layer, Ref, SubscriptionRef } from "effect"; | ||
|
||
export const MediaProviderStatusLive = Layer.effect( | ||
MediaProviderStatus, | ||
Effect.gen(function* () { | ||
const stateByProviderRef = yield* SubscriptionRef.make<StateByProvider>( | ||
new Map(), | ||
); | ||
const broadcastChannel = yield* MediaProviderMainThreadBroadcastChannel; | ||
|
||
yield* broadcastChannel.registerResolver("reportStatus", (status) => { | ||
return Ref.update(stateByProviderRef, (current) => { | ||
return new Map(current).set(status.metadata.id, status.status); | ||
}); | ||
}); | ||
|
||
return MediaProviderStatus.of({ | ||
observe: stateByProviderRef, | ||
}); | ||
}), | ||
); |
This file contains 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,15 @@ | ||
{ | ||
"name": "@echo/services-media-provider-status", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "Contains the implementation for the MediaProviderStatus service", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@echo/core-types": "^1.0.0", | ||
"effect": "^3.2.8" | ||
} | ||
} |
This file contains 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,6 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"include": [ | ||
"index.ts" | ||
] | ||
} |
This file contains 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 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.