From 01beafdea0638eba116425b912d394690d518ae6 Mon Sep 17 00:00:00 2001 From: Bryan Brown Date: Fri, 7 Jul 2023 17:26:13 -0400 Subject: [PATCH] Feature/cast pending event (#9) * add new item playing event, update casting logic * demo app - disable cast buttons while cast is pending --- docs/classes/client.BridgeClient.md | 18 ++++ ...omponents_messageHandler.MessageHandler.md | 2 + ...ageHandler.NewItemPlayingMessageHandler.md | 87 +++++++++++++++++++ docs/interfaces/schemas_defaults.defaults.md | 2 +- docs/modules/components_messageHandler.md | 1 + docs/modules/index.md | 7 ++ docs/modules/schemas_defaults.md | 13 +++ docs/modules/schemas_schema_events.md | 8 ++ package.json | 2 +- src/library/client.ts | 19 ++-- src/library/components/messageHandler.ts | 21 +++++ src/library/schemas/defaults.ts | 4 +- src/library/schemas/schema.events.ts | 20 +++++ src/react-app/App.tsx | 15 +++- src/react-app/components/HologramForm.tsx | 7 +- 15 files changed, 212 insertions(+), 14 deletions(-) create mode 100644 docs/classes/components_messageHandler.NewItemPlayingMessageHandler.md diff --git a/docs/classes/client.BridgeClient.md b/docs/classes/client.BridgeClient.md index 472e0e5..dd3e44d 100644 --- a/docs/classes/client.BridgeClient.md +++ b/docs/classes/client.BridgeClient.md @@ -13,6 +13,8 @@ ### Properties - [currentPlaylistIndex](client.BridgeClient.md#currentplaylistindex) +- [currentPlaylistItemIndex](client.BridgeClient.md#currentplaylistitemindex) +- [isCastPending](client.BridgeClient.md#iscastpending) - [isConnected](client.BridgeClient.md#isconnected) - [isDisconnecting](client.BridgeClient.md#isdisconnecting) - [manualDisconnect](client.BridgeClient.md#manualdisconnect) @@ -69,6 +71,22 @@ The index of playlists that is currently active ___ +### currentPlaylistItemIndex + +• **currentPlaylistItemIndex**: `number` + +The index of the playlist Item that is currently active + +___ + +### isCastPending + +• **isCastPending**: `boolean` = `false` + +store if we're currently in the middle of a cast + +___ + ### isConnected • **isConnected**: `boolean` diff --git a/docs/classes/components_messageHandler.MessageHandler.md b/docs/classes/components_messageHandler.MessageHandler.md index 23493a3..1367656 100644 --- a/docs/classes/components_messageHandler.MessageHandler.md +++ b/docs/classes/components_messageHandler.MessageHandler.md @@ -36,6 +36,8 @@ ↳ [`SyncPlayPlaylistCancelledMessageHandler`](components_messageHandler.SyncPlayPlaylistCancelledMessageHandler.md) + ↳ [`NewItemPlayingMessageHandler`](components_messageHandler.NewItemPlayingMessageHandler.md) + ## Table of contents ### Constructors diff --git a/docs/classes/components_messageHandler.NewItemPlayingMessageHandler.md b/docs/classes/components_messageHandler.NewItemPlayingMessageHandler.md new file mode 100644 index 0000000..bc419ed --- /dev/null +++ b/docs/classes/components_messageHandler.NewItemPlayingMessageHandler.md @@ -0,0 +1,87 @@ +[@lookingglass/bridge](../README.md) / [components/messageHandler](../modules/components_messageHandler.md) / NewItemPlayingMessageHandler + +# Class: NewItemPlayingMessageHandler + +[components/messageHandler](../modules/components_messageHandler.md).NewItemPlayingMessageHandler + +## Hierarchy + +- [`MessageHandler`](components_messageHandler.MessageHandler.md)<``"New Item Playing"``\> + + ↳ **`NewItemPlayingMessageHandler`** + +## Table of contents + +### Constructors + +- [constructor](components_messageHandler.NewItemPlayingMessageHandler.md#constructor) + +### Properties + +- [bridgeEventName](components_messageHandler.NewItemPlayingMessageHandler.md#bridgeeventname) +- [client](components_messageHandler.NewItemPlayingMessageHandler.md#client) + +### Methods + +- [handle](components_messageHandler.NewItemPlayingMessageHandler.md#handle) + +## Constructors + +### constructor + +• **new NewItemPlayingMessageHandler**(`args`) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `args` | `Object` | +| `args.client` | [`BridgeClient`](client.BridgeClient.md) | + +#### Overrides + +[MessageHandler](components_messageHandler.MessageHandler.md).[constructor](components_messageHandler.MessageHandler.md#constructor) + +## Properties + +### bridgeEventName + +• **bridgeEventName**: ``"New Item Playing"`` + +#### Inherited from + +[MessageHandler](components_messageHandler.MessageHandler.md).[bridgeEventName](components_messageHandler.MessageHandler.md#bridgeeventname) + +___ + +### client + +• **client**: [`BridgeClient`](client.BridgeClient.md) + +#### Inherited from + +[MessageHandler](components_messageHandler.MessageHandler.md).[client](components_messageHandler.MessageHandler.md#client) + +## Methods + +### handle + +▸ **handle**(`message`): `void` + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `message` | `Object` | `undefined` | +| `message.name` | `string` | `schema.name` | +| `message.orchestration` | { value: string; type: "WSTRING"; name: string; } | `undefined` | +| `message.payload` | { value: { playlist\_name: { value: string; type: "WSTRING"; name: string; }; index: { value: number; type: "UNSIGNED\_INT"; name: string; }; event: { value: "Monitor Connect" \| "Monitor Disconnect" \| ... 9 more ... \| "Transport Control Pause"; type: "WSTRING"; name: string; }; }; type: "VARIANT\_MAP"; name: string; } | `undefined` | +| `message.status` | { value: "Completion" \| "Pending" \| "Failure" \| "UnknownOrchestration"; type: "WSTRING"; name: string; } | `schema.status` | + +#### Returns + +`void` + +#### Overrides + +[MessageHandler](components_messageHandler.MessageHandler.md).[handle](components_messageHandler.MessageHandler.md#handle) diff --git a/docs/interfaces/schemas_defaults.defaults.md b/docs/interfaces/schemas_defaults.defaults.md index 20a5d42..0689648 100644 --- a/docs/interfaces/schemas_defaults.defaults.md +++ b/docs/interfaces/schemas_defaults.defaults.md @@ -35,4 +35,4 @@ ___ ### type -• **type**: `NumberType` +• **type**: [`NumberType`](../modules/schemas_defaults.md#numbertype) diff --git a/docs/modules/components_messageHandler.md b/docs/modules/components_messageHandler.md index e36a26f..0fac02c 100644 --- a/docs/modules/components_messageHandler.md +++ b/docs/modules/components_messageHandler.md @@ -9,6 +9,7 @@ - [MessageHandler](../classes/components_messageHandler.MessageHandler.md) - [MonitorConnectedMessageHandler](../classes/components_messageHandler.MonitorConnectedMessageHandler.md) - [MonitorDisconnectedMessageHandler](../classes/components_messageHandler.MonitorDisconnectedMessageHandler.md) +- [NewItemPlayingMessageHandler](../classes/components_messageHandler.NewItemPlayingMessageHandler.md) - [PlaylistDeleteMessageHandler](../classes/components_messageHandler.PlaylistDeleteMessageHandler.md) - [PlaylistInsertMessageHandler](../classes/components_messageHandler.PlaylistInsertMessageHandler.md) - [PlaylistInstanceMessageHandler](../classes/components_messageHandler.PlaylistInstanceMessageHandler.md) diff --git a/docs/modules/index.md b/docs/modules/index.md index 6a3abb0..dcdfe01 100644 --- a/docs/modules/index.md +++ b/docs/modules/index.md @@ -14,6 +14,7 @@ - [MessageHandler](index.md#messagehandler) - [MonitorConnectedMessageHandler](index.md#monitorconnectedmessagehandler) - [MonitorDisconnectedMessageHandler](index.md#monitordisconnectedmessagehandler) +- [NewItemPlayingMessageHandler](index.md#newitemplayingmessagehandler) - [Playlist](index.md#playlist) - [PlaylistArgs](index.md#playlistargs) - [PlaylistDeleteMessageHandler](index.md#playlistdeletemessagehandler) @@ -93,6 +94,12 @@ Re-exports [MonitorDisconnectedMessageHandler](../classes/components_messageHand ___ +### NewItemPlayingMessageHandler + +Re-exports [NewItemPlayingMessageHandler](../classes/components_messageHandler.NewItemPlayingMessageHandler.md) + +___ + ### Playlist Re-exports [Playlist](../classes/playlists_playlist.Playlist.md) diff --git a/docs/modules/schemas_defaults.md b/docs/modules/schemas_defaults.md index 48ab9ee..608d805 100644 --- a/docs/modules/schemas_defaults.md +++ b/docs/modules/schemas_defaults.md @@ -8,6 +8,10 @@ - [defaults](../interfaces/schemas_defaults.defaults.md) +### Type Aliases + +- [NumberType](schemas_defaults.md#numbertype) + ### Variables - [ASPECT](schemas_defaults.md#aspect) @@ -20,6 +24,15 @@ - [QUILT\_VIEW\_COUNT](schemas_defaults.md#quilt_view_count) - [ZOOM](schemas_defaults.md#zoom) +## Type Aliases + +### NumberType + +Ƭ **NumberType**: ``"int"`` \| ``"float"`` + +for certain values we need defaults in order to define our type schemas and also clamp values. +This helps prevent sending bridge values that are out of range. + ## Variables ### ASPECT diff --git a/docs/modules/schemas_schema_events.md b/docs/modules/schemas_schema_events.md index f67f81f..e20ba59 100644 --- a/docs/modules/schemas_schema_events.md +++ b/docs/modules/schemas_schema_events.md @@ -16,6 +16,7 @@ - [insertPlaylistResponse](schemas_schema_events.md#insertplaylistresponse) - [instancePlaylistResponse](schemas_schema_events.md#instanceplaylistresponse) - [monitorConnectResponse](schemas_schema_events.md#monitorconnectresponse) +- [newItemPlayingResponse](schemas_schema_events.md#newitemplayingresponse) - [progressUpdateResponse](schemas_schema_events.md#progressupdateresponse) - [transportControlPauseResponse](schemas_schema_events.md#transportcontrolpauseresponse) @@ -39,6 +40,7 @@ ___ | `Bridge Disconnected` | `z.infer` | - | | `Monitor Connect` | `z.infer` | - | | `Monitor Disconnect` | `z.infer` | - | +| `New Item Playing` | `z.infer` | - | | `Playlist Delete` | `z.infer` | - | | `Playlist Insert` | `z.infer` | - | | `Playlist Instance` | `z.infer` | - | @@ -82,6 +84,12 @@ ___ ___ +### newItemPlayingResponse + +• `Const` **newItemPlayingResponse**: `ZodObject`<{ `name`: `ZodString` = schema.name; `orchestration`: `ZodObject`<{ `name`: `ZodString` = schema.name; `type`: `ZodLiteral`<``"WSTRING"``\> = schema.wstring; `value`: `ZodString` }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: `string` }, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: `string` }\> ; `payload`: `ZodObject`<{ `name`: `ZodString` = schema.name; `type`: `ZodLiteral`<``"VARIANT_MAP"``\> = schema.variant\_map; `value`: `ZodObject`<{ `event`: `ZodObject`<{ `name`: `ZodString` = schema.name; `type`: `ZodLiteral`<``"WSTRING"``\> = schema.wstring; `value`: `ZodUnion`<[`ZodLiteral`<``"Monitor Connect"``\>, `ZodLiteral`<``"Monitor Disconnect"``\>, `ZodLiteral`<``"Progress Start"``\>, `ZodLiteral`<``"Progress Completion"``\>, `ZodLiteral`<``"Progress Update"``\>, `ZodLiteral`<``"Playlist Instance"``\>]\> = BridgeEvent }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: ``"Monitor Connect"`` \| ``"Monitor Disconnect"`` \| ``"Progress Start"`` \| ``"Progress Completion"`` \| ``"Progress Update"`` \| ``"Playlist Instance"`` \| ``"Playlist Insert"`` \| ``"Playlist Delete"`` \| ``"Sync/Play Playlist"`` \| ``"Sync/Play Playlist Complete"`` \| ``"Sync/Play Playlist Cancelled"`` \| ``"Transport Control Pause"`` = BridgeEvent }, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: ``"Monitor Connect"`` \| ``"Monitor Disconnect"`` \| ``"Progress Start"`` \| ``"Progress Completion"`` \| ``"Progress Update"`` \| ``"Playlist Instance"`` \| ``"Playlist Insert"`` \| ``"Playlist Delete"`` \| ``"Sync/Play Playlist"`` \| ``"Sync/Play Playlist Complete"`` \| ``"Sync/Play Playlist Cancelled"`` \| ``"Transport Control Pause"`` = BridgeEvent }\> ; `index`: `ZodObject`<{ `name`: `ZodString` = schema.name; `type`: `ZodLiteral`<``"UNSIGNED_INT"``\> = schema.unsigned\_int; `value`: `ZodNumber` }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `type`: ``"UNSIGNED_INT"`` = schema.unsigned\_int; `value`: `number` }, { `name`: `string` = schema.name; `type`: ``"UNSIGNED_INT"`` = schema.unsigned\_int; `value`: `number` }\> ; `playlist_name`: `ZodObject`<{ `name`: `ZodString` = schema.name; `type`: `ZodLiteral`<``"WSTRING"``\> = schema.wstring; `value`: `ZodString` }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: `string` }, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: `string` }\> }, ``"strip"``, `ZodTypeAny`, { `event`: { value: "Monitor Connect" \| "Monitor Disconnect" \| "Progress Start" \| "Progress Completion" \| "Progress Update" \| "Playlist Instance" \| "Playlist Insert" \| "Playlist Delete" \| "Sync/Play Playlist" \| "Sync/Play Playlist Complete" \| "Sync/Play Playlist Cancelled" \| "Transport Control Pause"; type: "WSTRING"; name: st... ; `index`: { value: number; type: "UNSIGNED\_INT"; name: string; } ; `playlist_name`: { value: string; type: "WSTRING"; name: string; } }, { `event`: { value: "Monitor Connect" \| "Monitor Disconnect" \| "Progress Start" \| "Progress Completion" \| "Progress Update" \| "Playlist Instance" \| "Playlist Insert" \| "Playlist Delete" \| "Sync/Play Playlist" \| "Sync/Play Playlist Complete" \| "Sync/Play Playlist Cancelled" \| "Transport Control Pause"; type: "WSTRING"; name: st... ; `index`: { value: number; type: "UNSIGNED\_INT"; name: string; } ; `playlist_name`: { value: string; type: "WSTRING"; name: string; } }\> = valueSchema }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `type`: ``"VARIANT_MAP"`` = schema.variant\_map; `value`: { playlist\_name: { value: string; type: "WSTRING"; name: string; }; index: { value: number; type: "UNSIGNED\_INT"; name: string; }; event: { value: "Monitor Connect" \| "Monitor Disconnect" \| "Progress Start" \| ... 8 more ... \| "Transport Control Pause"; type: "WSTRING"; name: string; }; } = valueSchema }, { `name`: `string` = schema.name; `type`: ``"VARIANT_MAP"`` = schema.variant\_map; `value`: { playlist\_name: { value: string; type: "WSTRING"; name: string; }; index: { value: number; type: "UNSIGNED\_INT"; name: string; }; event: { value: "Monitor Connect" \| "Monitor Disconnect" \| "Progress Start" \| ... 8 more ... \| "Transport Control Pause"; type: "WSTRING"; name: string; }; } = valueSchema }\> ; `status`: `ZodObject`<{ `name`: `ZodString` = name; `type`: `ZodLiteral`<``"WSTRING"``\> = wstring; `value`: `ZodUnion`<[`ZodLiteral`<``"Completion"``\>, `ZodLiteral`<``"Pending"``\>, `ZodLiteral`<``"Failure"``\>, `ZodLiteral`<``"UnknownOrchestration"``\>]\> }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = name; `type`: ``"WSTRING"`` = wstring; `value`: ``"Completion"`` \| ``"Pending"`` \| ``"Failure"`` \| ``"UnknownOrchestration"`` }, { `name`: `string` = name; `type`: ``"WSTRING"`` = wstring; `value`: ``"Completion"`` \| ``"Pending"`` \| ``"Failure"`` \| ``"UnknownOrchestration"`` }\> = schema.status }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `orchestration`: { value: string; type: "WSTRING"; name: string; } ; `payload`: { value: { playlist\_name: { value: string; type: "WSTRING"; name: string; }; index: { value: number; type: "UNSIGNED\_INT"; name: string; }; event: { value: "Monitor Connect" \| "Monitor Disconnect" \| ... 9 more ... \| "Transport Control Pause"; type: "WSTRING"; name: string; }; }; type: "VARIANT\_MAP"; name: string; } ; `status`: { value: "Completion" \| "Pending" \| "Failure" \| "UnknownOrchestration"; type: "WSTRING"; name: string; } = schema.status }, { `name`: `string` = schema.name; `orchestration`: { value: string; type: "WSTRING"; name: string; } ; `payload`: { value: { playlist\_name: { value: string; type: "WSTRING"; name: string; }; index: { value: number; type: "UNSIGNED\_INT"; name: string; }; event: { value: "Monitor Connect" \| "Monitor Disconnect" \| ... 9 more ... \| "Transport Control Pause"; type: "WSTRING"; name: string; }; }; type: "VARIANT\_MAP"; name: string; } ; `status`: { value: "Completion" \| "Pending" \| "Failure" \| "UnknownOrchestration"; type: "WSTRING"; name: string; } = schema.status }\> + +___ + ### progressUpdateResponse • `Const` **progressUpdateResponse**: `ZodObject`<{ `name`: `ZodString` = schema.name; `orchestration`: `ZodObject`<{ `name`: `ZodString` = schema.name; `type`: `ZodLiteral`<``"WSTRING"``\> = schema.wstring; `value`: `ZodString` }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: `string` }, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: `string` }\> ; `payload`: `ZodObject`<{ `name`: `ZodString` = schema.name; `type`: `ZodLiteral`<``"VARIANT_MAP"``\> = schema.variant\_map; `value`: `ZodObject`<{ `event`: `ZodObject`<{ `name`: `ZodString` = schema.name; `type`: `ZodLiteral`<``"WSTRING"``\> = schema.wstring; `value`: `ZodUnion`<[`ZodLiteral`<``"Monitor Connect"``\>, `ZodLiteral`<``"Monitor Disconnect"``\>, `ZodLiteral`<``"Progress Start"``\>, `ZodLiteral`<``"Progress Completion"``\>, `ZodLiteral`<``"Progress Update"``\>, `ZodLiteral`<``"Playlist Instance"``\>]\> = BridgeEvent }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: ``"Monitor Connect"`` \| ``"Monitor Disconnect"`` \| ``"Progress Start"`` \| ``"Progress Completion"`` \| ``"Progress Update"`` \| ``"Playlist Instance"`` \| ``"Playlist Insert"`` \| ``"Playlist Delete"`` \| ``"Sync/Play Playlist"`` \| ``"Sync/Play Playlist Complete"`` \| ``"Sync/Play Playlist Cancelled"`` \| ``"Transport Control Pause"`` = BridgeEvent }, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: ``"Monitor Connect"`` \| ``"Monitor Disconnect"`` \| ``"Progress Start"`` \| ``"Progress Completion"`` \| ``"Progress Update"`` \| ``"Playlist Instance"`` \| ``"Playlist Insert"`` \| ``"Playlist Delete"`` \| ``"Sync/Play Playlist"`` \| ``"Sync/Play Playlist Complete"`` \| ``"Sync/Play Playlist Cancelled"`` \| ``"Transport Control Pause"`` = BridgeEvent }\> ; `message`: `ZodObject`<{ `name`: `ZodString` = schema.name; `type`: `ZodLiteral`<``"WSTRING"``\> = schema.wstring; `value`: `ZodString` }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: `string` }, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: `string` }\> ; `progress`: `ZodObject`<{ `name`: `ZodString` = schema.name; `type`: `ZodLiteral`<``"FLOAT"``\> = schema.float; `value`: `ZodNumber` }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `type`: ``"FLOAT"`` = schema.float; `value`: `number` }, { `name`: `string` = schema.name; `type`: ``"FLOAT"`` = schema.float; `value`: `number` }\> ; `progress_type`: `ZodObject`<{ `name`: `ZodString` = schema.name; `type`: `ZodLiteral`<``"WSTRING"``\> = schema.wstring; `value`: `ZodString` }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: `string` }, { `name`: `string` = schema.name; `type`: ``"WSTRING"`` = schema.wstring; `value`: `string` }\> }, ``"strip"``, `ZodTypeAny`, { `event`: { value: "Monitor Connect" \| "Monitor Disconnect" \| "Progress Start" \| "Progress Completion" \| "Progress Update" \| "Playlist Instance" \| "Playlist Insert" \| "Playlist Delete" \| "Sync/Play Playlist" \| "Sync/Play Playlist Complete" \| "Sync/Play Playlist Cancelled" \| "Transport Control Pause"; type: "WSTRING"; name: st... ; `message`: { value: string; type: "WSTRING"; name: string; } ; `progress`: { value: number; type: "FLOAT"; name: string; } ; `progress_type`: { value: string; type: "WSTRING"; name: string; } }, { `event`: { value: "Monitor Connect" \| "Monitor Disconnect" \| "Progress Start" \| "Progress Completion" \| "Progress Update" \| "Playlist Instance" \| "Playlist Insert" \| "Playlist Delete" \| "Sync/Play Playlist" \| "Sync/Play Playlist Complete" \| "Sync/Play Playlist Cancelled" \| "Transport Control Pause"; type: "WSTRING"; name: st... ; `message`: { value: string; type: "WSTRING"; name: string; } ; `progress`: { value: number; type: "FLOAT"; name: string; } ; `progress_type`: { value: string; type: "WSTRING"; name: string; } }\> = valueSchema }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `type`: ``"VARIANT_MAP"`` = schema.variant\_map; `value`: { message: { value: string; type: "WSTRING"; name: string; }; event: { value: "Monitor Connect" \| "Monitor Disconnect" \| "Progress Start" \| "Progress Completion" \| "Progress Update" \| "Playlist Instance" \| ... 5 more ... \| "Transport Control Pause"; type: "WSTRING"; name: string; }; progress: { ...; }; progress\_type... = valueSchema }, { `name`: `string` = schema.name; `type`: ``"VARIANT_MAP"`` = schema.variant\_map; `value`: { message: { value: string; type: "WSTRING"; name: string; }; event: { value: "Monitor Connect" \| "Monitor Disconnect" \| "Progress Start" \| "Progress Completion" \| "Progress Update" \| "Playlist Instance" \| ... 5 more ... \| "Transport Control Pause"; type: "WSTRING"; name: string; }; progress: { ...; }; progress\_type... = valueSchema }\> ; `status`: `ZodObject`<{ `name`: `ZodString` = name; `type`: `ZodLiteral`<``"WSTRING"``\> = wstring; `value`: `ZodUnion`<[`ZodLiteral`<``"Completion"``\>, `ZodLiteral`<``"Pending"``\>, `ZodLiteral`<``"Failure"``\>, `ZodLiteral`<``"UnknownOrchestration"``\>]\> }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = name; `type`: ``"WSTRING"`` = wstring; `value`: ``"Completion"`` \| ``"Pending"`` \| ``"Failure"`` \| ``"UnknownOrchestration"`` }, { `name`: `string` = name; `type`: ``"WSTRING"`` = wstring; `value`: ``"Completion"`` \| ``"Pending"`` \| ``"Failure"`` \| ``"UnknownOrchestration"`` }\> = schema.status }, ``"strip"``, `ZodTypeAny`, { `name`: `string` = schema.name; `orchestration`: { value: string; type: "WSTRING"; name: string; } ; `payload`: { value: { message: { value: string; type: "WSTRING"; name: string; }; event: { value: "Monitor Connect" \| "Monitor Disconnect" \| "Progress Start" \| "Progress Completion" \| "Progress Update" \| ... 6 more ... \| "Transport Control Pause"; type: "WSTRING"; name: string; }; progress: { ...; }; progress\_type: { ...; }; }... ; `status`: { value: "Completion" \| "Pending" \| "Failure" \| "UnknownOrchestration"; type: "WSTRING"; name: string; } = schema.status }, { `name`: `string` = schema.name; `orchestration`: { value: string; type: "WSTRING"; name: string; } ; `payload`: { value: { message: { value: string; type: "WSTRING"; name: string; }; event: { value: "Monitor Connect" \| "Monitor Disconnect" \| "Progress Start" \| "Progress Completion" \| "Progress Update" \| ... 6 more ... \| "Transport Control Pause"; type: "WSTRING"; name: string; }; progress: { ...; }; progress\_type: { ...; }; }... ; `status`: { value: "Completion" \| "Pending" \| "Failure" \| "UnknownOrchestration"; type: "WSTRING"; name: string; } = schema.status }\> diff --git a/package.json b/package.json index e23bf60..cbc5735 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lookingglass/bridge", - "version": "0.0.4-alpha", + "version": "0.0.5-alpha", "license": "MIT", "description": "Official Looking Glass Library for interacting with Looking Glass holographic displays.", "types": "./dist/index.d.ts", diff --git a/src/library/client.ts b/src/library/client.ts index d310fdf..46d7962 100644 --- a/src/library/client.ts +++ b/src/library/client.ts @@ -9,6 +9,7 @@ import { HologramParamMap } from "./schemas/schema.parameters" import * as schema from "./schemas/schema.responses" import { z } from "zod" import { Fallback } from "./components/fallback" +import { NewItemPlayingMessageHandler } from "./components/messageHandler" export class BridgeClient { /** The name of the current orchestration */ @@ -25,6 +26,8 @@ export class BridgeClient { public playlists: Playlist[] | undefined /** The index of playlists that is currently active */ public currentPlaylistIndex: number + /**The index of the playlist Item that is currently active */ + public currentPlaylistItemIndex: number /** the instance of the client that we create, BridgeClient is a singleton, there can only be one */ static instance: BridgeClient static fallback: Fallback | undefined @@ -33,7 +36,7 @@ export class BridgeClient { /**control how often we log to the console, 3 is everything, 0 is nothing */ static verbosity: 0 | 1 | 2 | 3 = 3 /**store if we're currently in the middle of a cast */ - private isCastPending = false + public isCastPending = false /**the version of the Looking Glass Driver that's running */ public version: number private currentHologram: HologramType | undefined @@ -50,6 +53,7 @@ export class BridgeClient { this.playlists = [] this.currentPlaylistIndex = 0 + this.currentPlaylistItemIndex = 0 this.version = 0 if (!BridgeClient.instance) { @@ -138,6 +142,8 @@ export class BridgeClient { await this.subscribeToEvents() BridgeClient.eventsource.connectEvent() + new NewItemPlayingMessageHandler({ client: this }) + return { success: true, response: { version: this.version, orchestration: this.orchestration } } } @@ -369,15 +375,14 @@ export class BridgeClient { this.playlists?.splice(this.playlists.indexOf(playlist), 1) } }) - this.currentPlaylistIndex = currentCastItem.index - } - - // if we failed to add the hologram to the playlist, return false - else { + //update the current playlist index value. + this.currentPlaylistIndex = this.playlists?.indexOf(playlist) ?? 0 + //update the current playlistItem Index value. + this.currentPlaylistItemIndex = currentCastItem.index + } else { return { success: false } } - this.isCastPending = false this.currentHologram = hologram return { success: true } } diff --git a/src/library/components/messageHandler.ts b/src/library/components/messageHandler.ts index 7659b0b..7938d5b 100644 --- a/src/library/components/messageHandler.ts +++ b/src/library/components/messageHandler.ts @@ -123,3 +123,24 @@ export class SyncPlayPlaylistCancelledMessageHandler extends MessageHandler<"Syn console.log(message) } } + +export class NewItemPlayingMessageHandler extends MessageHandler<"New Item Playing"> { + constructor(args: { client: BridgeClient }) { + super({ bridgeEventName: "New Item Playing", client: args.client }) + } + + handle(message: BridgeEventMap["New Item Playing"]): void { + console.log("%c New Item Playing ", "color: aqua; font-weight: bold; border: solid;", message) + + let index = this.client.currentPlaylistIndex + let playlistName = this.client.playlists?.[index]?.name + let playlistItemIndex = this.client.currentPlaylistItemIndex + + if ( + message.payload.value.playlist_name.value == playlistName && + message.payload.value.index.value == playlistItemIndex + ) { + this.client.isCastPending = false + } + } +} diff --git a/src/library/schemas/defaults.ts b/src/library/schemas/defaults.ts index a139391..c2e7951 100644 --- a/src/library/schemas/defaults.ts +++ b/src/library/schemas/defaults.ts @@ -22,8 +22,8 @@ export const ASPECT: defaults = { export const DEPTHINESS: defaults = { min: 0.1, - max: 2, - range: numberRange(0.1, 2), + max: 4, + range: numberRange(0.1, 4), type: "float", } diff --git a/src/library/schemas/schema.events.ts b/src/library/schemas/schema.events.ts index 64b4d01..85e2ef8 100644 --- a/src/library/schemas/schema.events.ts +++ b/src/library/schemas/schema.events.ts @@ -180,6 +180,24 @@ const transportControlPause = z.object({ }), }) +const NewItemPlaying = z.object({ + event: z.object({ + name: schema.name, + type: schema.wstring, + value: BridgeEvent, + }), + index: z.object({ + name: schema.name, + type: schema.unsigned_int, + value: z.number(), + }), + playlist_name: z.object({ + name: schema.name, + type: schema.wstring, + value: z.string(), + }), +}) + /** * events contain the same payload structure, up until the value of the payload * this is a helper type to make it easier to define the payload of each event @@ -206,6 +224,7 @@ export const insertPlaylistResponse = PayloadResponse(insertPlaylist) export const instancePlaylistResponse = PayloadResponse(playlistInstance) export const deletePlaylistResponse = PayloadResponse(deletePlaylist) export const transportControlPauseResponse = PayloadResponse(transportControlPause) +export const newItemPlayingResponse = PayloadResponse(NewItemPlaying) // export const all_events = z.union([monitorConnectResponse, progressUpdateResponse]) @@ -222,6 +241,7 @@ export type BridgeEventMap = { "Sync/Play Playlist Complete": z.infer "Sync/Play Playlist Cancelled": z.infer "Transport Control Pause": z.infer + "New Item Playing": z.infer // "All Events": all_events, /**CUSTOM CLIENT EVENTS BELOW THESE ARE NOT PART OF BRIDGE */ "Bridge Connected": z.infer diff --git a/src/react-app/App.tsx b/src/react-app/App.tsx index d45bca4..65ffde3 100644 --- a/src/react-app/App.tsx +++ b/src/react-app/App.tsx @@ -45,6 +45,7 @@ function App() { const [index, setIndex] = useState(0) const [progress, setProgress] = useState(0) const [autoStartPlaylistName, setAutoStartPlaylistName] = useState("") + const [isCastPending, setIsCastPending] = useState(false) // Custom Hologram State const [hologram, setHologram] = useState(quilt) @@ -69,6 +70,8 @@ function App() { setConnectionStatus("✅ Connected") // add an event listener to handle a disconnect event from Bridge. await Bridge.addEventListener("Bridge Disconnected", handleEventDisconnected) + // react-ify the bridge state for cast pending + await Bridge.addEventListener("New Item Playing", handleNewItemPlaying) // Manually call Bridge.displays to query for any connected Looking Glass, await Bridge.getDisplays().then((call) => { if (!call.response || call.response.length == 0) { @@ -79,6 +82,10 @@ function App() { }) } + const handleNewItemPlaying = async () => { + setIsCastPending(Bridge.isCastPending) + } + const handleEventDisconnected = async () => { setConnected(false) setConnectionStatus("⚠️ Bridge Disconnected!") @@ -314,6 +321,8 @@ function App() { hologramType={hologramType} setHologramType={setHologramType} setResponse={setResponse} + isCastPending={isCastPending} + setIsCastPending={setIsCastPending} />

Cast Predefined Holograms

diff --git a/src/react-app/components/HologramForm.tsx b/src/react-app/components/HologramForm.tsx index 7167b8a..8d5aa1e 100644 --- a/src/react-app/components/HologramForm.tsx +++ b/src/react-app/components/HologramForm.tsx @@ -8,6 +8,8 @@ export interface HologramFactoryArgs { setResponse: (response: string | null) => void hologramType: hologramTypes setHologramType: (hologramType: hologramTypes) => void + isCastPending: boolean + setIsCastPending: (isCastPending: boolean) => void } export default function HologramForm({ connected, @@ -16,6 +18,8 @@ export default function HologramForm({ setResponse, hologramType, setHologramType, + isCastPending, + setIsCastPending, }: HologramFactoryArgs) { const [hologramUri, setHologramUri] = useState(hologram.uri) const [hologramSettings, setHologramSettings] = useState(hologram.settings) @@ -144,8 +148,9 @@ export default function HologramForm({ setHologram(hologram) let call = await Bridge.cast(hologram) setResponse(JSON.stringify(call)) + setIsCastPending(Bridge.isCastPending) }} - disabled={!connected}> + disabled={!connected || isCastPending}> Cast hologram