Skip to content

Commit

Permalink
Fix/version naming (#12)
Browse files Browse the repository at this point in the history
* update version handling to support bridge version and api naming
  • Loading branch information
BryanChrisBrown authored Aug 17, 2023
1 parent 686a3db commit ce366d0
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 38 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
- [schemas/schema.requests](modules/schemas_schema_requests.md)
- [schemas/schema.responses](modules/schemas_schema_responses.md)
- [schemas/schema.utils](modules/schemas_schema_utils.md)
- [utilities/general.utils](modules/utilities_general_utils.md)
16 changes: 8 additions & 8 deletions docs/classes/client.BridgeClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ___

### version

**version**: `number`
**version**: [`BridgeVersion`](../modules/components.md#bridgeversion)

the version of the Looking Glass Driver that's running

Expand Down Expand Up @@ -188,13 +188,13 @@ ___

### apiVersion

**apiVersion**(): `Promise`<{ `response`: `number` ; `success`: `boolean` }\>
**apiVersion**(): `Promise`<{ `response`: [`BridgeVersion`](../modules/components.md#bridgeversion) ; `success`: `boolean` }\>

A helper function to get the version of the Looking Glass Bridge API

#### Returns

`Promise`<{ `response`: `number` ; `success`: `boolean` }\>
`Promise`<{ `response`: [`BridgeVersion`](../modules/components.md#bridgeversion) ; `success`: `boolean` }\>

the current version of the Looking Glass API

Expand All @@ -220,13 +220,13 @@ ___

### connect

**connect**(): `Promise`<{ `response`: { `orchestration`: `string` ; `version`: `number` } ; `success`: `boolean` }\>
**connect**(): `Promise`<{ `response`: { `orchestration`: `string` ; `version`: [`BridgeVersion`](../modules/components.md#bridgeversion) } ; `success`: `boolean` }\>

Attempt to connect to Looking Glass Bridge.

#### Returns

`Promise`<{ `response`: { `orchestration`: `string` ; `version`: `number` } ; `success`: `boolean` }\>
`Promise`<{ `response`: { `orchestration`: `string` ; `version`: [`BridgeVersion`](../modules/components.md#bridgeversion) } ; `success`: `boolean` }\>

___

Expand Down Expand Up @@ -366,13 +366,13 @@ ___

### getVersion

**getVersion**(): `Promise`<{ `response`: `number` ; `success`: `boolean` }\>
**getVersion**(): `Promise`<{ `response`: [`BridgeVersion`](../modules/components.md#bridgeversion) ; `success`: `boolean` }\>

A helper function to get the version of Looking Glass Bridge that is running.

#### Returns

`Promise`<{ `response`: `number` ; `success`: `boolean` }\>
`Promise`<{ `response`: [`BridgeVersion`](../modules/components.md#bridgeversion) ; `success`: `boolean` }\>

string of the version of Looking Glass Bridge that is running

Expand Down Expand Up @@ -595,7 +595,7 @@ Update the parameters of the current hologram

| Name | Type |
| :------ | :------ |
| `T` | extends ``"depth_loc"`` \| ``"depth_inversion"`` \| ``"chroma_depth"`` \| ``"depthiness"`` \| ``"focus"`` \| ``"depth_cutoff"`` \| ``"zoom"`` \| ``"crop_pos_x"`` \| ``"crop_pos_y"`` |
| `T` | extends ``"focus"`` \| ``"depth_loc"`` \| ``"depth_inversion"`` \| ``"chroma_depth"`` \| ``"depthiness"`` \| ``"depth_cutoff"`` \| ``"zoom"`` \| ``"crop_pos_x"`` \| ``"crop_pos_y"`` |

#### Parameters

Expand Down
6 changes: 3 additions & 3 deletions docs/classes/components_fallback.Fallback.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This class uses HoloPlay Core to see if the older API endpoint used in HoloPlay

### versionPromise

**versionPromise**: `number` \| `Promise`<`number`\>
**versionPromise**: `string` \| `Promise`<`string`\>

___

Expand All @@ -56,11 +56,11 @@ ___

### getLegacyVersion

**getLegacyVersion**(): `Promise`<`number`\>
**getLegacyVersion**(): `Promise`<`string`\>

#### Returns

`Promise`<`number`\>
`Promise`<`string`\>

___

Expand Down
2 changes: 2 additions & 0 deletions docs/classes/components_hologram.QuiltHologram.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Create a new Quilt Hologram
| `args.settings` | `Object` |
| `args.settings.aspect` | `number` |
| `args.settings.columns` | `number` |
| `args.settings.focus?` | `number` |
| `args.settings.rows` | `number` |
| `args.settings.viewCount` | `number` |
| `args.uri` | `string` |
Expand All @@ -48,6 +49,7 @@ Create a new Quilt Hologram
| :------ | :------ |
| `aspect` | `number` |
| `columns` | `number` |
| `focus?` | `number` |
| `rows` | `number` |
| `viewCount` | `number` |

Expand Down
1 change: 1 addition & 0 deletions docs/classes/playlists_playlistItems.QuiltPlaylistItem.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ PlaylistItem.playlistName
| `depth_inversion?` | ``0`` \| ``1`` |
| `depth_loc?` | ``0`` \| ``2`` \| ``1`` \| ``3`` |
| `depthiness?` | `number` |
| `focus` | `number` |
| `id` | `number` |
| `index` | `number` |
| `isRGBD` | ``0`` \| ``1`` |
Expand Down
1 change: 1 addition & 0 deletions docs/classes/playlists_playlistItems.RGBDPlaylistItem.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ PlaylistItem.playlistName
| `depth_inversion?` | ``0`` \| ``1`` |
| `depth_loc?` | ``0`` \| ``2`` \| ``1`` \| ``3`` |
| `depthiness?` | `number` |
| `focus` | `number` |
| `id` | `number` |
| `index` | `number` |
| `isRGBD` | ``0`` \| ``1`` |
Expand Down
16 changes: 16 additions & 0 deletions docs/modules/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,25 @@
### Type Aliases

- [BridgeType](components.md#bridgetype)
- [BridgeVersion](components.md#bridgeversion)

## Type Aliases

### BridgeType

Ƭ **BridgeType**: ``"BOOLEAN"`` \| ``"CHAR"`` \| ``"SHORT"`` \| ``"UNSIGNED_SHORT"`` \| ``"INT"`` \| ``"LONG"`` \| ``"FLOAT"`` \| ``"DOUBLE"`` \| ``"INT2"`` \| ``"INT3"`` \| ``"INT4"`` \| ``"FLOAT2"`` \| ``"FLOAT3"`` \| ``"FLOAT4"`` \| ``"FLOAT4X4"`` \| ``"STRING"`` \| ``"WSTRING"`` \| ``"VARIANT_MAP"``

___

### BridgeVersion

Ƭ **BridgeVersion**: `Object`

#### Type declaration

| Name | Type |
| :------ | :------ |
| `hotfix?` | `number` |
| `major` | `number` |
| `minor` | `number` |
| `patch?` | `number` |
7 changes: 7 additions & 0 deletions docs/modules/schemas_defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [CROP\_POS\_X](schemas_defaults.md#crop_pos_x)
- [CROP\_POS\_Y](schemas_defaults.md#crop_pos_y)
- [DEPTHINESS](schemas_defaults.md#depthiness)
- [DEPTH\_CUTOFF](schemas_defaults.md#depth_cutoff)
- [FOCUS](schemas_defaults.md#focus)
- [QUILT\_COLS](schemas_defaults.md#quilt_cols)
- [QUILT\_ROWS](schemas_defaults.md#quilt_rows)
Expand Down Expand Up @@ -59,6 +60,12 @@ ___

___

### DEPTH\_CUTOFF

`Const` **DEPTH\_CUTOFF**: [`defaults`](../interfaces/schemas_defaults.defaults.md)

___

### FOCUS

`Const` **FOCUS**: [`defaults`](../interfaces/schemas_defaults.defaults.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/schemas_schema_hologram.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ___

### QuiltHologramArgs

`Const` **QuiltHologramArgs**: `ZodObject`<{ `aspect`: `ZodNumber` ; `columns`: `ZodNumber` ; `rows`: `ZodNumber` ; `viewCount`: `ZodNumber` }, ``"strip"``, `ZodTypeAny`, { `aspect`: `number` ; `columns`: `number` ; `rows`: `number` ; `viewCount`: `number` }, { `aspect`: `number` ; `columns`: `number` ; `rows`: `number` ; `viewCount`: `number` }\>
`Const` **QuiltHologramArgs**: `ZodObject`<{ `aspect`: `ZodNumber` ; `columns`: `ZodNumber` ; `focus`: `ZodOptional`<`ZodNumber`\> ; `rows`: `ZodNumber` ; `viewCount`: `ZodNumber` }, ``"strip"``, `ZodTypeAny`, { `aspect`: `number` ; `columns`: `number` ; `focus?`: `number` ; `rows`: `number` ; `viewCount`: `number` }, { `aspect`: `number` ; `columns`: `number` ; `focus?`: `number` ; `rows`: `number` ; `viewCount`: `number` }\>

___

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/schemas_schema_requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ___

### insert\_playlist\_entry

• `Const` **insert\_playlist\_entry**: `ZodObject`<{ `aspect`: `ZodNumber` ; `chroma_depth`: `ZodOptional`<`ZodUnion`<[`ZodLiteral`<``0``\>, `ZodLiteral`<``1``\>]\>\> ; `cols`: `ZodNumber` ; `depth_inversion`: `ZodOptional`<`ZodUnion`<[`ZodLiteral`<``0``\>, `ZodLiteral`<``1``\>]\>\> ; `depth_loc`: `ZodOptional`<`ZodUnion`<[`ZodLiteral`<``0``\>, `ZodLiteral`<``1``\>, `ZodLiteral`<``2``\>, `ZodLiteral`<``3``\>]\>\> ; `depthiness`: `ZodOptional`<`ZodNumber`\> ; `id`: `ZodNumber` ; `index`: `ZodNumber` ; `isRGBD`: `ZodUnion`<[`ZodLiteral`<``0``\>, `ZodLiteral`<``1``\>]\> ; `name`: `ZodString` ; `orchestration`: `ZodString` ; `rows`: `ZodNumber` ; `uri`: `ZodString` ; `view_count`: `ZodNumber` ; `zoom`: `ZodOptional`<`ZodNumber`\> }, ``"strip"``, `ZodTypeAny`, { `aspect`: `number` ; `chroma_depth?`: ``0`` \| ``1`` ; `cols`: `number` ; `depth_inversion?`: ``0`` \| ``1`` ; `depth_loc?`: ``0`` \| ``2`` \| ``1`` \| ``3`` ; `depthiness?`: `number` ; `id`: `number` ; `index`: `number` ; `isRGBD`: ``0`` \| ``1`` ; `name`: `string` ; `orchestration`: `string` ; `rows`: `number` ; `uri`: `string` ; `view_count`: `number` ; `zoom?`: `number` }, { `aspect`: `number` ; `chroma_depth?`: ``0`` \| ``1`` ; `cols`: `number` ; `depth_inversion?`: ``0`` \| ``1`` ; `depth_loc?`: ``0`` \| ``2`` \| ``1`` \| ``3`` ; `depthiness?`: `number` ; `id`: `number` ; `index`: `number` ; `isRGBD`: ``0`` \| ``1`` ; `name`: `string` ; `orchestration`: `string` ; `rows`: `number` ; `uri`: `string` ; `view_count`: `number` ; `zoom?`: `number` }\>
• `Const` **insert\_playlist\_entry**: `ZodObject`<{ `aspect`: `ZodNumber` ; `chroma_depth`: `ZodOptional`<`ZodUnion`<[`ZodLiteral`<``0``\>, `ZodLiteral`<``1``\>]\>\> ; `cols`: `ZodNumber` ; `depth_inversion`: `ZodOptional`<`ZodUnion`<[`ZodLiteral`<``0``\>, `ZodLiteral`<``1``\>]\>\> ; `depth_loc`: `ZodOptional`<`ZodUnion`<[`ZodLiteral`<``0``\>, `ZodLiteral`<``1``\>, `ZodLiteral`<``2``\>, `ZodLiteral`<``3``\>]\>\> ; `depthiness`: `ZodOptional`<`ZodNumber`\> ; `focus`: `ZodNumber` ; `id`: `ZodNumber` ; `index`: `ZodNumber` ; `isRGBD`: `ZodUnion`<[`ZodLiteral`<``0``\>, `ZodLiteral`<``1``\>]\> ; `name`: `ZodString` ; `orchestration`: `ZodString` ; `rows`: `ZodNumber` ; `uri`: `ZodString` ; `view_count`: `ZodNumber` ; `zoom`: `ZodOptional`<`ZodNumber`\> }, ``"strip"``, `ZodTypeAny`, { `aspect`: `number` ; `chroma_depth?`: ``0`` \| ``1`` ; `cols`: `number` ; `depth_inversion?`: ``0`` \| ``1`` ; `depth_loc?`: ``0`` \| ``2`` \| ``1`` \| ``3`` ; `depthiness?`: `number` ; `focus`: `number` ; `id`: `number` ; `index`: `number` ; `isRGBD`: ``0`` \| ``1`` ; `name`: `string` ; `orchestration`: `string` ; `rows`: `number` ; `uri`: `string` ; `view_count`: `number` ; `zoom?`: `number` }, { `aspect`: `number` ; `chroma_depth?`: ``0`` \| ``1`` ; `cols`: `number` ; `depth_inversion?`: ``0`` \| ``1`` ; `depth_loc?`: ``0`` \| ``2`` \| ``1`` \| ``3`` ; `depthiness?`: `number` ; `focus`: `number` ; `id`: `number` ; `index`: `number` ; `isRGBD`: ``0`` \| ``1`` ; `name`: `string` ; `orchestration`: `string` ; `rows`: `number` ; `uri`: `string` ; `view_count`: `number` ; `zoom?`: `number` }\>

___

Expand Down
30 changes: 30 additions & 0 deletions docs/modules/utilities_general_utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[@lookingglass/bridge](../README.md) / utilities/general.utils

# Module: utilities/general.utils

## Table of contents

### Functions

- [parseBridgeVersion](utilities_general_utils.md#parsebridgeversion)

## Functions

### parseBridgeVersion

**parseBridgeVersion**(`versionString`): [`BridgeVersion`](components.md#bridgeversion)

Parse the version from Bridge's version string
Bridge uses a major, minor, patch, hotfix versioning system

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `versionString` | `string` | The version string to parse |

#### Returns

[`BridgeVersion`](components.md#bridgeversion)

BridgeVersion
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lookingglass/bridge",
"version": "0.0.7-alpha",
"version": "0.0.8-alpha",
"license": "MIT",
"description": "Official Looking Glass Library for interacting with Looking Glass holographic displays.",
"types": "./dist/index.d.ts",
Expand Down
43 changes: 24 additions & 19 deletions src/library/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import * as schema from "./schemas/schema.responses"
import { z } from "zod"
import { Fallback } from "./components/fallback"
import { NewItemPlayingMessageHandler } from "./components/messageHandler"
import { BridgeVersion } from "./components"
import { parseBridgeVersion } from "./utilities/general.utils"

export class BridgeClient {
/** The name of the current orchestration */
Expand Down Expand Up @@ -38,7 +40,7 @@ export class BridgeClient {
/**store if we're currently in the middle of a cast */
public isCastPending = false
/**the version of the Looking Glass Driver that's running */
public version: number
public version: BridgeVersion
private currentHologram: HologramType | undefined
/**a boolean for whether a disconnect was triggered automatically or manually */
public manualDisconnect = false
Expand All @@ -54,7 +56,7 @@ export class BridgeClient {

this.currentPlaylistIndex = 0
this.currentPlaylistItemIndex = 0
this.version = 0
this.version = { major: 0, minor: 0, patch: 0, hotfix: 0 }

if (!BridgeClient.instance) {
BridgeClient.instance = this
Expand Down Expand Up @@ -107,7 +109,7 @@ export class BridgeClient {
*/
public async connect(): Promise<{
success: boolean
response: { version: number; orchestration: string }
response: { version: BridgeVersion; orchestration: string }
}> {
this.log("%c function call: connect ", "color: magenta; font-weight: bold; border: solid")

Expand All @@ -122,7 +124,7 @@ export class BridgeClient {
if (status == false)
return {
success: false,
response: { version: 0, orchestration: "" },
response: { version: { major: 0, minor: 0, patch: 0, hotfix: 0 }, orchestration: "" },
}
this.isConnected = true

Expand All @@ -132,8 +134,8 @@ export class BridgeClient {
if (call.success == false) {
let version = await this.getVersion()
if (version.success == false) {
return { success: false, response: { version: 0, orchestration: "" } }
} else if (version.response < 2.2) {
return { success: false, response: { version: parseBridgeVersion("0"), orchestration: "" } }
} else if (version.response.major < 2 && version.response.minor < 1) {
return { success: false, response: { version: version.response, orchestration: "" } }
}
}
Expand All @@ -157,7 +159,7 @@ export class BridgeClient {
return { success: false, response: null }
}
const version = await this.getVersion()
if (version.response < 2.1) {
if (version.response.major < 2 && version.response.minor < 1) {
console.error(`Unable to get Looking Glass Bridge version, please upgrade Looking Glass Bridge.`)
return { success: false, response: null }
}
Expand Down Expand Up @@ -241,39 +243,41 @@ export class BridgeClient {
* A helper function to get the version of Looking Glass Bridge that is running.
* @returns string of the version of Looking Glass Bridge that is running
*/
public async getVersion(): Promise<{ success: boolean; response: number }> {
public async getVersion(): Promise<{ success: boolean; response: BridgeVersion }> {
this.log("%c function call: getVersion ", "color: magenta; font-weight: bold; border: solid")

let message = await sendMessage({ endpoint: "bridge_version", requestBody: {} })
if (message.success == true) {
this.version = parseFloat(message.response.payload.value)
let response = parseBridgeVersion(message.response.payload.value)
this.version = response
return { success: true, response: this.version }
}
// if the bridge version fails, try the legacy version
else {
let version = await BridgeClient.fallback?.getLegacyVersion()
if (version == undefined) return { success: false, response: 0 }
return { success: true, response: version }
if (version == undefined) return { success: false, response: parseBridgeVersion("0") }
return { success: true, response: parseBridgeVersion(version) }
}
}

/**
* A helper function to get the version of the Looking Glass Bridge API
* @returns the current version of the Looking Glass API
*/
public async apiVersion(): Promise<{ success: boolean; response: number }> {
public async apiVersion(): Promise<{ success: boolean; response: BridgeVersion }> {
this.log("%c function call: apiVersion ", "color: magenta; font-weight: bold; border: solid")
if (this.isConnected == false) {
return { success: false, response: 0 }
return { success: false, response: parseBridgeVersion("0") }
}
if ((await this.isVersionCompatible()) == false) return { success: false, response: 0 }
if ((await this.isVersionCompatible()) == false)
return { success: false, response: parseBridgeVersion("0") }
let response = await sendMessage({ endpoint: "api_version", requestBody: {} })
if (response.success == false) {
console.warn(`this call is only supported in bridge 2.2 or newer, please upgrade Looking Glass Bridge.`)
return { success: false, response: 0 }
return { success: false, response: parseBridgeVersion("0") }
}

let APIVersion = parseFloat(response.response.payload.value)
let APIVersion = parseBridgeVersion(response.response.payload.value)
return { success: true, response: APIVersion }
}

Expand Down Expand Up @@ -385,6 +389,7 @@ export class BridgeClient {
}

this.currentHologram = hologram
this.isCastPending = false
return { success: true }
}

Expand Down Expand Up @@ -743,12 +748,12 @@ export class BridgeClient {
* @returns boolean, true if the version is compatible, false if not
*/
private async isVersionCompatible() {
if (this.version == 0) {
if (this.version.major == 0) {
this.isConnected = false
} else if (this.version < 2.2) {
} else if (this.version.major < 2 && this.version.minor < 1) {
this.warn("Please update to the latest version for the best experience")
this.isConnected = false
} else if (this.version >= 2.2) {
} else if (this.version.major >= 2 && this.version.minor >= 2) {
this.isConnected = true
}

Expand Down
Loading

0 comments on commit ce366d0

Please sign in to comment.