@cisl/io-display
Advanced tools
Comparing version 1.4.0 to 1.4.1
@@ -51,3 +51,3 @@ import { Io } from '@cisl/io/io'; | ||
* @property {Number} [videoOptions.preload] - Specify the current video preload ('auto' | 'metadata' | 'none') (default: 'auto') | ||
*/ | ||
*/ | ||
interface ContextWindowSettings extends WindowOptions { | ||
@@ -89,18 +89,14 @@ windowName: string; | ||
/** | ||
* Creates an instance of DisplayContext. | ||
* @param {String} name Display context name | ||
* @param {Object.<String, window_settings>} windowSettings - a collection of named window settings | ||
* @param {Object} io CELIO object instance | ||
*/ | ||
* Creates an instance of DisplayContext. | ||
* @param {String} name Display context name | ||
* @param {Object.<String, window_settings>} windowSettings - a collection of named window settings | ||
* @param {Object} io CELIO object instance | ||
*/ | ||
constructor(io: Io, name: string, settings: DisplayOptions); | ||
displayUrl(windowName: string, url: string, options: DisplayUrlOptions): Promise<ViewObject>; | ||
private validQueue; | ||
_clean(closedDisplay: string): void; | ||
_postRequest<T = any>(displayName: string, data: any): Promise<T>; | ||
private _clean; | ||
private _postRequest; | ||
restoreFromDisplayWorkerStates(reset?: boolean): Promise<any>; | ||
_executeInAvailableDisplays<T = any>(cmd: { | ||
command: string; | ||
options: { | ||
context: string; | ||
}; | ||
}): Promise<T[]>; | ||
private _executeInAvailableDisplays; | ||
/** | ||
@@ -131,5 +127,5 @@ * gets a map of windowName with bounds | ||
/** | ||
* closes all windows of a display context | ||
* @returns {display_rpc_result} returns a status object | ||
*/ | ||
* closes all windows of a display context | ||
* @returns {display_rpc_result} returns a status object | ||
*/ | ||
close(): Promise<{ | ||
@@ -141,17 +137,17 @@ status: string; | ||
/** | ||
* reloads all viewObjects of a display context | ||
* @returns {display_rpc_result} returns a status object | ||
*/ | ||
* reloads all viewObjects of a display context | ||
* @returns {display_rpc_result} returns a status object | ||
*/ | ||
reloadAll(): Promise<ViewObjectRequestResponse[]>; | ||
initialize(options: DisplayContextSettings): Promise<Record<string, InitializeReturn>>; | ||
/** | ||
* gets a viewObject | ||
* @param {String} id - an uuid of the viewobject | ||
* @returns {ViewObject} returns the ViewObject instance | ||
*/ | ||
* gets a viewObject | ||
* @param {String} id - an uuid of the viewobject | ||
* @returns {ViewObject} returns the ViewObject instance | ||
*/ | ||
getViewObject(id: string): ViewObject; | ||
/** | ||
* gets all viewObjects | ||
* @returns {Map.<String, ViewObject>} returns the collection of ViewObject instances | ||
*/ | ||
* gets all viewObjects | ||
* @returns {Map.<String, ViewObject>} returns the collection of ViewObject instances | ||
*/ | ||
getViewObjects(): Map<string, ViewObject>; | ||
@@ -170,3 +166,2 @@ /** | ||
createViewObject(options: ViewObjectOptions, windowName?: string): Promise<ViewObject>; | ||
displayUrl(windowName: string, url: string, options: DisplayUrlOptions): Promise<ViewObject>; | ||
/** | ||
@@ -173,0 +168,0 @@ * DisplayContext closed event |
@@ -15,7 +15,7 @@ "use strict"; | ||
/** | ||
* Creates an instance of DisplayContext. | ||
* @param {String} name Display context name | ||
* @param {Object.<String, window_settings>} windowSettings - a collection of named window settings | ||
* @param {Object} io CELIO object instance | ||
*/ | ||
* Creates an instance of DisplayContext. | ||
* @param {String} name Display context name | ||
* @param {Object.<String, window_settings>} windowSettings - a collection of named window settings | ||
* @param {Object} io CELIO object instance | ||
*/ | ||
constructor(io, name, settings) { | ||
@@ -35,5 +35,7 @@ if (!io.rabbit) { | ||
}, {}); | ||
this.io.rabbit.onTopic('display.removed', (response) => { | ||
this.io.rabbit | ||
.onTopic('display.removed', (response) => { | ||
this._clean(response.content); | ||
}).catch((err) => { | ||
}) | ||
.catch((err) => { | ||
console.error('Failed to remove display', err); | ||
@@ -48,4 +50,36 @@ }); | ||
} | ||
async displayUrl(windowName, url, options) { | ||
const uniformGridCellSize = await this.displayWindows | ||
.get(windowName) | ||
.getUniformGridCellSize(); | ||
if ((options.width === undefined || options.height === undefined) && | ||
uniformGridCellSize === undefined) { | ||
throw new Error('Uniform grid cell size must be initialized'); | ||
} | ||
if (options.width === undefined && options.widthFactor === undefined) { | ||
throw new Error('width or widthFactor is required'); | ||
} | ||
if (options.height === undefined && options.heightFactor === undefined) { | ||
throw new Error('height or heightFactor is required'); | ||
} | ||
return await this.createViewObject(Object.assign(Object.assign(Object.assign({ nodeIntegration: false, uiDraggable: true, uiClosable: true }, (options.top === undefined && options.left === undefined | ||
? { | ||
position: { | ||
gridLeft: 1, | ||
gridTop: 1, | ||
}, | ||
} | ||
: {})), options), { width: options.width !== undefined | ||
? typeof options.width === 'string' | ||
? options.width | ||
: `${options.width}px` | ||
: `${options.widthFactor * uniformGridCellSize.width}px`, height: options.height !== undefined | ||
? typeof options.height === 'string' | ||
? options.height | ||
: `${options.height}px` | ||
: `${options.heightFactor * uniformGridCellSize.height}px`, url }), windowName); | ||
} | ||
validQueue(queueName) { | ||
return (queueName.indexOf('rpc-display-') > -1) && this.displayNames.has(queueName.replace('rpc-display-', '')); | ||
return (queueName.indexOf('rpc-display-') > -1 && | ||
this.displayNames.has(queueName.replace('rpc-display-', ''))); | ||
} | ||
@@ -59,3 +93,3 @@ _clean(closedDisplay) { | ||
} | ||
closedWindows.forEach(w => this.displayWindows.delete(w)); | ||
closedWindows.forEach((w) => this.displayWindows.delete(w)); | ||
const vboToRemove = []; | ||
@@ -67,3 +101,3 @@ for (const [k, v] of this.viewObjects) { | ||
} | ||
vboToRemove.forEach(v => this.viewObjects.delete(v)); | ||
vboToRemove.forEach((v) => this.viewObjects.delete(v)); | ||
if (this.displayWorkerQuitHandler) { | ||
@@ -80,3 +114,4 @@ const obj = { | ||
const response = await this.io.rabbit.publishRpc(`rpc-display-${displayName}`, data); | ||
if (Buffer.isBuffer(response.content) || typeof response.content !== 'object') { | ||
if (Buffer.isBuffer(response.content) || | ||
typeof response.content !== 'object') { | ||
throw new Error('Invalid response type'); | ||
@@ -99,3 +134,3 @@ } | ||
let windowCount = 0; | ||
states.forEach(state => { | ||
states.forEach((state) => { | ||
if (state.context !== this.name) { | ||
@@ -121,3 +156,3 @@ return; | ||
}; | ||
this.viewObjects.set(k, new view_object_1.ViewObject(this.io, opts)); | ||
this.viewObjects.set(k, new view_object_1.ViewObject(this.io, wn, opts)); | ||
} | ||
@@ -144,4 +179,5 @@ } | ||
const availableDisplayNames = []; | ||
qs.forEach(queue => { | ||
if ((queue.state === 'running' || queue.state === 'live') && this.validQueue(queue.name)) { | ||
qs.forEach((queue) => { | ||
if ((queue.state === 'running' || queue.state === 'live') && | ||
this.validQueue(queue.name)) { | ||
availableDisplayNames.push(queue.name); | ||
@@ -154,4 +190,4 @@ } | ||
const _ps = []; | ||
availableDisplayNames.forEach(dm => { | ||
_ps.push(this.io.rabbit.publishRpc(dm, cmd).then(response => { | ||
availableDisplayNames.forEach((dm) => { | ||
_ps.push(this.io.rabbit.publishRpc(dm, cmd).then((response) => { | ||
return response.content; | ||
@@ -239,5 +275,5 @@ })); | ||
/** | ||
* closes all windows of a display context | ||
* @returns {display_rpc_result} returns a status object | ||
*/ | ||
* closes all windows of a display context | ||
* @returns {display_rpc_result} returns a status object | ||
*/ | ||
async close() { | ||
@@ -261,3 +297,5 @@ const cmd = { | ||
this.viewObjects.clear(); | ||
this.io.redis.get('display:activeDisplayContext').then(x => { | ||
this.io.redis | ||
.get('display:activeDisplayContext') | ||
.then((x) => { | ||
if (x === this.name) { | ||
@@ -269,9 +307,12 @@ // clearing up active display context in store | ||
} | ||
}).catch(() => { | ||
}) | ||
.catch(() => { | ||
// ignore | ||
}); | ||
this.io.rabbit.publishTopic('display.displayContext.closed', JSON.stringify({ | ||
'type': 'displayContextClosed', | ||
'details': m, | ||
})).catch(() => { | ||
this.io.rabbit | ||
.publishTopic('display.displayContext.closed', JSON.stringify({ | ||
type: 'displayContextClosed', | ||
details: m, | ||
})) | ||
.catch(() => { | ||
// ignore | ||
@@ -283,5 +324,5 @@ }); | ||
/** | ||
* reloads all viewObjects of a display context | ||
* @returns {display_rpc_result} returns a status object | ||
*/ | ||
* reloads all viewObjects of a display context | ||
* @returns {display_rpc_result} returns a status object | ||
*/ | ||
reloadAll() { | ||
@@ -317,6 +358,6 @@ const _ps = []; | ||
/** | ||
* gets a viewObject | ||
* @param {String} id - an uuid of the viewobject | ||
* @returns {ViewObject} returns the ViewObject instance | ||
*/ | ||
* gets a viewObject | ||
* @param {String} id - an uuid of the viewobject | ||
* @returns {ViewObject} returns the ViewObject instance | ||
*/ | ||
getViewObject(id) { | ||
@@ -330,5 +371,5 @@ const viewObject = this.viewObjects.get(id); | ||
/** | ||
* gets all viewObjects | ||
* @returns {Map.<String, ViewObject>} returns the collection of ViewObject instances | ||
*/ | ||
* gets all viewObjects | ||
* @returns {Map.<String, ViewObject>} returns the collection of ViewObject instances | ||
*/ | ||
getViewObjects() { | ||
@@ -348,3 +389,3 @@ return this.viewObjects; | ||
} | ||
return Promise.all(_ps).then(m => { | ||
return Promise.all(_ps).then((m) => { | ||
const resMap = new Map(); | ||
@@ -379,24 +420,2 @@ for (let i = 0; i < m.length && i < _dispNames.length; i++) { | ||
} | ||
async displayUrl(windowName, url, options) { | ||
const uniformGridCellSize = await this.displayWindows.get(windowName).getUniformGridCellSize(); | ||
if ((options.width === undefined || options.height === undefined) && uniformGridCellSize === undefined) { | ||
throw new Error('Uniform grid cell size must be initialized'); | ||
} | ||
if (options.width === undefined && options.widthFactor === undefined) { | ||
throw new Error('width or widthFactor is required'); | ||
} | ||
if (options.height === undefined && options.heightFactor === undefined) { | ||
throw new Error('height or heightFactor is required'); | ||
} | ||
return await this.createViewObject(Object.assign(Object.assign(Object.assign({ nodeIntegration: false, uiDraggable: true, uiClosable: true }, (options.top === undefined && options.left === undefined ? { | ||
position: { | ||
gridLeft: 1, | ||
gridTop: 1, | ||
}, | ||
} : {})), options), { width: options.width !== undefined | ||
? (typeof options.width === 'string' ? options.width : `${options.width}px`) | ||
: `${options.widthFactor * uniformGridCellSize.width}px`, height: options.height !== undefined | ||
? (typeof options.height === 'string' ? options.height : `${options.height}px`) | ||
: `${options.heightFactor * uniformGridCellSize.height}px`, url }), windowName); | ||
} | ||
/** | ||
@@ -407,3 +426,4 @@ * DisplayContext closed event | ||
onClosed(handler) { | ||
this.io.rabbit.onTopic('display.displayContext.closed', (response) => { | ||
this.io.rabbit | ||
.onTopic('display.displayContext.closed', (response) => { | ||
if (handler != null) { | ||
@@ -415,3 +435,6 @@ const content = response.content; | ||
} | ||
}).catch(() => { }); | ||
}) | ||
.catch(() => { | ||
/* pass */ | ||
}); | ||
} | ||
@@ -423,3 +446,4 @@ /** | ||
onActivated(handler) { | ||
this.io.rabbit.onTopic('display.displayContext.changed', (response) => { | ||
this.io.rabbit | ||
.onTopic('display.displayContext.changed', (response) => { | ||
if (handler != null) { | ||
@@ -431,3 +455,6 @@ const content = response.content; | ||
} | ||
}).catch(() => { }); | ||
}) | ||
.catch(() => { | ||
/* pass */ | ||
}); | ||
} | ||
@@ -439,3 +466,4 @@ /** | ||
onDeactivated(handler) { | ||
this.io.rabbit.onTopic('display.displayContext.changed', (response) => { | ||
this.io.rabbit | ||
.onTopic('display.displayContext.changed', (response) => { | ||
if (handler != null) { | ||
@@ -447,3 +475,6 @@ const content = response.content; | ||
} | ||
}).catch(() => { }); | ||
}) | ||
.catch(() => { | ||
/* pass */ | ||
}); | ||
} | ||
@@ -450,0 +481,0 @@ /** |
@@ -46,2 +46,3 @@ import { Io } from '@cisl/io/io'; | ||
displayName: string; | ||
uniformGridCellSize: UniformGridCellSize; | ||
constructor(io: Io, options: DisplayWindowOptions); | ||
@@ -157,29 +158,29 @@ _postRequest<T = object>(data: object): Promise<T>; | ||
/** | ||
* Creates a view object in the window | ||
* | ||
* options: | ||
* - url | ||
* - position (label or grid-top & gridLeft) | ||
* - width // in px or em | ||
* - height // in px or em | ||
* - cssText (string) | ||
* - nodeintegration (boolean) | ||
* | ||
* @param {Object} options | ||
* @param {String} options.url | ||
* @param {Object|String} [options.position] | ||
* @param {Number} options.position.gridTop | ||
* @param {Number} options.position.gridLeft | ||
* @param {String} options.width - in pixels or em | ||
* @param {String} options.height - in pixels or em | ||
* @param {boolean} options.nodeintegration | ||
* @param {String} options.cssText | ||
* @param {boolean} options.uiDraggable | ||
* @param {boolean} options.uiClosable | ||
* @param {object} options.deviceEmulation | ||
* @param {Number} options.deviceEmulation.scale | ||
* @returns {ViewObject} View object | ||
*/ | ||
* Creates a view object in the window | ||
* | ||
* options: | ||
* - url | ||
* - position (label or grid-top & gridLeft) | ||
* - width // in px or em | ||
* - height // in px or em | ||
* - cssText (string) | ||
* - nodeintegration (boolean) | ||
* | ||
* @param {Object} options | ||
* @param {String} options.url | ||
* @param {Object|String} [options.position] | ||
* @param {Number} options.position.gridTop | ||
* @param {Number} options.position.gridLeft | ||
* @param {String} options.width - in pixels or em | ||
* @param {String} options.height - in pixels or em | ||
* @param {boolean} options.nodeintegration | ||
* @param {String} options.cssText | ||
* @param {boolean} options.uiDraggable | ||
* @param {boolean} options.uiClosable | ||
* @param {object} options.deviceEmulation | ||
* @param {Number} options.deviceEmulation.scale | ||
* @returns {ViewObject} View object | ||
*/ | ||
createViewObject(options: ViewObjectOptions): Promise<ViewObject>; | ||
} | ||
export {}; |
@@ -18,6 +18,10 @@ "use strict"; | ||
this.displayContext = options.displayContext; | ||
this.uniformGridCellSize = null; | ||
} | ||
_postRequest(data) { | ||
return this.io.rabbit.publishRpc(`rpc-display-${this.displayName}`, data).then((response) => { | ||
if (Buffer.isBuffer(response.content) || typeof response.content !== 'object') { | ||
return this.io.rabbit | ||
.publishRpc(`rpc-display-${this.displayName}`, data) | ||
.then((response) => { | ||
if (Buffer.isBuffer(response.content) || | ||
typeof response.content !== 'object') { | ||
throw new Error('invalid response content'); | ||
@@ -158,3 +162,3 @@ } | ||
*/ | ||
getUniformGridCellSize() { | ||
async getUniformGridCellSize() { | ||
const cmd = { | ||
@@ -166,3 +170,4 @@ command: 'uniform-grid-cell-size', | ||
}; | ||
return this._postRequest(cmd); | ||
this.uniformGridCellSize = await this._postRequest(cmd); | ||
return this.uniformGridCellSize; | ||
} | ||
@@ -294,3 +299,4 @@ /** | ||
const response = await this.io.rabbit.publishRpc(`rpc-display-${this.displayName}`, cmd); | ||
if (Buffer.isBuffer(response.content) || typeof response.content !== 'object') { | ||
if (Buffer.isBuffer(response.content) || | ||
typeof response.content !== 'object') { | ||
throw new Error('invalid response type'); | ||
@@ -301,27 +307,27 @@ } | ||
/** | ||
* Creates a view object in the window | ||
* | ||
* options: | ||
* - url | ||
* - position (label or grid-top & gridLeft) | ||
* - width // in px or em | ||
* - height // in px or em | ||
* - cssText (string) | ||
* - nodeintegration (boolean) | ||
* | ||
* @param {Object} options | ||
* @param {String} options.url | ||
* @param {Object|String} [options.position] | ||
* @param {Number} options.position.gridTop | ||
* @param {Number} options.position.gridLeft | ||
* @param {String} options.width - in pixels or em | ||
* @param {String} options.height - in pixels or em | ||
* @param {boolean} options.nodeintegration | ||
* @param {String} options.cssText | ||
* @param {boolean} options.uiDraggable | ||
* @param {boolean} options.uiClosable | ||
* @param {object} options.deviceEmulation | ||
* @param {Number} options.deviceEmulation.scale | ||
* @returns {ViewObject} View object | ||
*/ | ||
* Creates a view object in the window | ||
* | ||
* options: | ||
* - url | ||
* - position (label or grid-top & gridLeft) | ||
* - width // in px or em | ||
* - height // in px or em | ||
* - cssText (string) | ||
* - nodeintegration (boolean) | ||
* | ||
* @param {Object} options | ||
* @param {String} options.url | ||
* @param {Object|String} [options.position] | ||
* @param {Number} options.position.gridTop | ||
* @param {Number} options.position.gridLeft | ||
* @param {String} options.width - in pixels or em | ||
* @param {String} options.height - in pixels or em | ||
* @param {boolean} options.nodeintegration | ||
* @param {String} options.cssText | ||
* @param {boolean} options.uiDraggable | ||
* @param {boolean} options.uiClosable | ||
* @param {object} options.deviceEmulation | ||
* @param {Number} options.deviceEmulation.scale | ||
* @returns {ViewObject} View object | ||
*/ | ||
async createViewObject(options) { | ||
@@ -336,5 +342,5 @@ const cmd = { | ||
} | ||
return new view_object_1.ViewObject(this.io, content); | ||
return new view_object_1.ViewObject(this.io, this, content); | ||
} | ||
} | ||
exports.DisplayWindow = DisplayWindow; |
import { Io } from '@cisl/io/io'; | ||
import { UniformGridCellSize } from './display-window'; | ||
import { ViewObject } from './view-object'; | ||
import { DisplayOptions, DisplayUrlOptions } from './types'; | ||
import { DisplayOptions } from './types'; | ||
import { DisplayContext } from './display-context'; | ||
@@ -106,2 +105,4 @@ import { BaseResponse, Bounds } from './types'; | ||
* Class representing the DisplayContextFactory object. | ||
* | ||
* The main function to use is {@link openDisplayContext} | ||
*/ | ||
@@ -112,6 +113,12 @@ export declare class DisplayWorker { | ||
private uniformGridCellSize?; | ||
private uniformGridCellSizeByWindow; | ||
constructor(io: Io); | ||
/** | ||
* Open a new or existing display context. | ||
* | ||
* @param displayContextName - Name of the display context | ||
* @param displayOptions - Options for the display context | ||
*/ | ||
openDisplayContext(displayContextName: string, displayOptions: DisplayOptions): Promise<DisplayContext>; | ||
/** | ||
* @deprecated This will be removed in 2.0 | ||
* | ||
@@ -125,25 +132,23 @@ * @param name The name of the display worker to communicate with | ||
}>; | ||
displayUrl(url: string, options: DisplayUrlOptions): Promise<ViewObject>; | ||
displayUrl(windowName: string, url: string, options: DisplayUrlOptions): Promise<ViewObject>; | ||
/** | ||
* gets the Display Workers details running in the environment. | ||
* @returns {Promise} A ES2015 Map object with displayNames as keys and bounds as values. | ||
*/ | ||
* gets the Display Workers details running in the environment. | ||
* @returns {Promise} A ES2015 Map object with displayNames as keys and bounds as values. | ||
*/ | ||
getDisplays(): Promise<Map<string, Bounds>>; | ||
/** | ||
* list display contexts live in the environment. | ||
* @returns {Promise} An array of String containing display context names. | ||
*/ | ||
* list display contexts live in the environment. | ||
* @returns {Promise} An array of String containing display context names. | ||
*/ | ||
list(): Promise<string[]>; | ||
/** | ||
* gets the activelist display contexts. | ||
* @returns {Promise} An array of String containing display context names. | ||
*/ | ||
* gets the activelist display contexts. | ||
* @returns {Promise} An array of String containing display context names. | ||
*/ | ||
getActive(): Promise<DisplayContext>; | ||
/** | ||
* sets a display context active. Making a display context active ensures only windows of the display context are visible. Windows from other display contexts are hidden. | ||
* @param display_ctx_name - display context name. | ||
* @param reset=false if the viewObjects of the displayContext need to be reloaded. | ||
* @returns return false if the display context name is already active. | ||
*/ | ||
* sets a display context active. Making a display context active ensures only windows of the display context are visible. Windows from other display contexts are hidden. | ||
* @param display_ctx_name - display context name. | ||
* @param reset=false if the viewObjects of the displayContext need to be reloaded. | ||
* @returns return false if the display context name is already active. | ||
*/ | ||
setActive(displayContextName: string, reset?: boolean): Promise<string | false>; | ||
@@ -204,5 +209,5 @@ /** | ||
/** | ||
* hides all display contexts. If the display context already exists, it is made active and a DisplayContext Object is restored from store. | ||
* @returns {Promise<Object>} A array of JSON object containing status of hide function execution at all display workers. | ||
*/ | ||
* hides all display contexts. If the display context already exists, it is made active and a DisplayContext Object is restored from store. | ||
* @returns {Promise<Object>} A array of JSON object containing status of hide function execution at all display workers. | ||
*/ | ||
hideAll(): Promise<BaseResponse[]>; | ||
@@ -297,3 +302,6 @@ /** | ||
} | ||
/** | ||
* It is not suggested to call this function directly, and it will be removed in the future. | ||
*/ | ||
export declare function registerDisplay(io: Io): void; | ||
export {}; |
127
index.js
@@ -11,2 +11,4 @@ "use strict"; | ||
* Class representing the DisplayContextFactory object. | ||
* | ||
* The main function to use is {@link openDisplayContext} | ||
*/ | ||
@@ -17,4 +19,9 @@ class DisplayWorker { | ||
this.io.rabbit.setTimeout(10000); | ||
this.uniformGridCellSizeByWindow = new Map(); | ||
} | ||
/** | ||
* Open a new or existing display context. | ||
* | ||
* @param displayContextName - Name of the display context | ||
* @param displayOptions - Options for the display context | ||
*/ | ||
async openDisplayContext(displayContextName, displayOptions) { | ||
@@ -41,2 +48,3 @@ const displays = await this.getDisplays(); | ||
/** | ||
* @deprecated This will be removed in 2.0 | ||
* | ||
@@ -64,44 +72,19 @@ * @param name The name of the display worker to communicate with | ||
const uniformGridCellSize = await displayWindow.getUniformGridCellSize(); | ||
this.uniformGridCellSizeByWindow.set(windowName, uniformGridCellSize); | ||
this.uniformGridCellSize = uniformGridCellSize; | ||
} | ||
return { displayContext: this.displayContext, uniformGridCellSize: this.uniformGridCellSize }; | ||
return { | ||
displayContext: this.displayContext, | ||
uniformGridCellSize: this.uniformGridCellSize, | ||
}; | ||
} | ||
async displayUrl(windowNameOrUrl, urlOrOptions, options) { | ||
const windowName = options ? windowNameOrUrl : 'main'; | ||
const url = options ? urlOrOptions : windowNameOrUrl; | ||
options = options || urlOrOptions; | ||
const uniformGridCellSize = this.uniformGridCellSizeByWindow.get(windowName); | ||
if (!this.displayContext) { | ||
throw new Error('Display context must be initialized'); | ||
} | ||
if ((options.width === undefined || options.height === undefined) && uniformGridCellSize === undefined) { | ||
throw new Error('Uniform grid cell size must be initialized'); | ||
} | ||
if (options.width === undefined && options.widthFactor === undefined) { | ||
throw new Error('width or widthFactor is required'); | ||
} | ||
if (options.height === undefined && options.heightFactor === undefined) { | ||
throw new Error('height or heightFactor is required'); | ||
} | ||
return await this.displayContext.createViewObject(Object.assign(Object.assign(Object.assign({ nodeIntegration: false, uiDraggable: true, uiClosable: true }, (options.top === undefined && options.left === undefined ? { | ||
position: { | ||
gridLeft: 1, | ||
gridTop: 1, | ||
}, | ||
} : {})), options), { width: options.width !== undefined | ||
? (typeof options.width === 'string' ? options.width : `${options.width}px`) | ||
: `${options.widthFactor * uniformGridCellSize.width}px`, height: options.height !== undefined | ||
? (typeof options.height === 'string' ? options.height : `${options.height}px`) | ||
: `${options.heightFactor * uniformGridCellSize.height}px`, url }), windowName); | ||
} | ||
/** | ||
* gets the Display Workers details running in the environment. | ||
* @returns {Promise} A ES2015 Map object with displayNames as keys and bounds as values. | ||
*/ | ||
* gets the Display Workers details running in the environment. | ||
* @returns {Promise} A ES2015 Map object with displayNames as keys and bounds as values. | ||
*/ | ||
async getDisplays() { | ||
const queues = await this.io.rabbit.getQueues(); | ||
const availableDisplayNames = []; | ||
queues.forEach(queue => { | ||
if ((queue.state === 'running' || queue.state === 'live') && queue.name.indexOf('rpc-display-') > -1) { | ||
queues.forEach((queue) => { | ||
if ((queue.state === 'running' || queue.state === 'live') && | ||
queue.name.indexOf('rpc-display-') > -1) { | ||
availableDisplayNames.push(queue.name); | ||
@@ -115,8 +98,8 @@ } | ||
const _ps = []; | ||
availableDisplayNames.forEach(dm => { | ||
_ps.push(this.io.rabbit.publishRpc(dm, cmd).then(response => { | ||
availableDisplayNames.forEach((dm) => { | ||
_ps.push(this.io.rabbit.publishRpc(dm, cmd).then((response) => { | ||
return response.content; | ||
})); | ||
}); | ||
const bounds = await Promise.all(_ps); | ||
const bounds = (await Promise.all(_ps)); | ||
const boundMap = new Map(); | ||
@@ -129,10 +112,11 @@ for (const bound of bounds) { | ||
/** | ||
* list display contexts live in the environment. | ||
* @returns {Promise} An array of String containing display context names. | ||
*/ | ||
* list display contexts live in the environment. | ||
* @returns {Promise} An array of String containing display context names. | ||
*/ | ||
async list() { | ||
const qs = await this.io.rabbit.getQueues(); | ||
const availableDisplayNames = []; | ||
qs.forEach(queue => { | ||
if ((queue.state === 'running' || queue.state === 'live') && queue.name.indexOf('rpc-display-') > -1) { | ||
qs.forEach((queue) => { | ||
if ((queue.state === 'running' || queue.state === 'live') && | ||
queue.name.indexOf('rpc-display-') > -1) { | ||
availableDisplayNames.push(queue.name); | ||
@@ -146,4 +130,4 @@ } | ||
const _ps = []; | ||
availableDisplayNames.forEach(dm => { | ||
_ps.push(this.io.rabbit.publishRpc(dm, cmd).then(response => { | ||
availableDisplayNames.forEach((dm) => { | ||
_ps.push(this.io.rabbit.publishRpc(dm, cmd).then((response) => { | ||
return response.content; | ||
@@ -160,5 +144,5 @@ })); | ||
/** | ||
* gets the activelist display contexts. | ||
* @returns {Promise} An array of String containing display context names. | ||
*/ | ||
* gets the activelist display contexts. | ||
* @returns {Promise} An array of String containing display context names. | ||
*/ | ||
async getActive() { | ||
@@ -174,7 +158,7 @@ const m = await this.io.redis.get('display:activeDisplayContext'); | ||
/** | ||
* sets a display context active. Making a display context active ensures only windows of the display context are visible. Windows from other display contexts are hidden. | ||
* @param display_ctx_name - display context name. | ||
* @param reset=false if the viewObjects of the displayContext need to be reloaded. | ||
* @returns return false if the display context name is already active. | ||
*/ | ||
* sets a display context active. Making a display context active ensures only windows of the display context are visible. Windows from other display contexts are hidden. | ||
* @param display_ctx_name - display context name. | ||
* @param reset=false if the viewObjects of the displayContext need to be reloaded. | ||
* @returns return false if the display context name is already active. | ||
*/ | ||
async setActive(displayContextName, reset = false) { | ||
@@ -187,4 +171,5 @@ // since setState first gets old value and sets the new value at the sametime, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const m = await (new display_context_1.DisplayContext(this.io, displayContextName, {})).restoreFromDisplayWorkerStates(reset); | ||
this.io.rabbit.publishTopic('display.displayContext.changed', { | ||
const m = await new display_context_1.DisplayContext(this.io, displayContextName, {}).restoreFromDisplayWorkerStates(reset); | ||
this.io.rabbit | ||
.publishTopic('display.displayContext.changed', { | ||
type: 'displayContextChanged', | ||
@@ -195,3 +180,6 @@ details: { | ||
}, | ||
}).catch(() => { }); | ||
}) | ||
.catch(() => { | ||
/* pass */ | ||
}); | ||
// TODO | ||
@@ -268,5 +256,5 @@ // eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
/** | ||
* hides all display contexts. If the display context already exists, it is made active and a DisplayContext Object is restored from store. | ||
* @returns {Promise<Object>} A array of JSON object containing status of hide function execution at all display workers. | ||
*/ | ||
* hides all display contexts. If the display context already exists, it is made active and a DisplayContext Object is restored from store. | ||
* @returns {Promise<Object>} A array of JSON object containing status of hide function execution at all display workers. | ||
*/ | ||
async hideAll() { | ||
@@ -279,3 +267,5 @@ const cmd = { | ||
for (const [k] of displays) { | ||
_ps.push(this.io.rabbit.publishRpc(`rpc-display-${k}`, cmd).then(m => m.content)); | ||
_ps.push(this.io.rabbit | ||
.publishRpc(`rpc-display-${k}`, cmd) | ||
.then((m) => m.content)); | ||
} | ||
@@ -309,3 +299,5 @@ const m = await Promise.all(_ps); | ||
for (const [k] of displays) { | ||
_ps.push(this.io.rabbit.publishRpc(`rpc-display-${k}`, cmd).then(m => m.content)); | ||
_ps.push(this.io.rabbit | ||
.publishRpc(`rpc-display-${k}`, cmd) | ||
.then((m) => m.content)); | ||
} | ||
@@ -315,7 +307,11 @@ return Promise.all(_ps); | ||
_on(topic, handler) { | ||
this.io.rabbit.onTopic(topic, (response) => { | ||
this.io.rabbit | ||
.onTopic(topic, (response) => { | ||
if (handler != null) { | ||
handler(response.content, response); | ||
} | ||
}).catch(() => { }); | ||
}) | ||
.catch(() => { | ||
/* pass */ | ||
}); | ||
} | ||
@@ -429,2 +425,5 @@ /** | ||
exports.DisplayWorker = DisplayWorker; | ||
/** | ||
* It is not suggested to call this function directly, and it will be removed in the future. | ||
*/ | ||
function registerDisplay(io) { | ||
@@ -431,0 +430,0 @@ if (!io.rabbit || !io.redis) { |
{ | ||
"name": "@cisl/io-display", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,2 +6,3 @@ # @cisl/io-display | ||
## Installation | ||
```bash | ||
@@ -12,2 +13,3 @@ npm install @cisl/io-display | ||
## Usage | ||
```javascript | ||
@@ -52,1 +54,16 @@ import cislio, { registerPlugins } from '@cisl/io'; | ||
You can see additional example usages of this module in the [display-worker/examples](https://github.com/bishopcais/display-worker/tree/master/examples) folder. | ||
## Display Hierarchy | ||
This module aims to enable the following hierarchy: | ||
- There are some number of display contexts | ||
- Within a display context, there is m displays (backed by display-worker per display) | ||
- Within each display, there are n windows | ||
- Within each window, there are o view objects | ||
An example of the possibility of configuration is shown below: | ||
![](img/hierarchy.png) | ||
Here, we have one display context that has two displays. In the display w-A, we have two windows w-A and w-B. In w-A, there are two view objects. In w-B, there is only one view object. In display d-B, there is one window that takes up the entire display. In this window w-C, there is two view objects. You may create multiple contexts, but only one context can be active at a time. |
import { Io } from '@cisl/io/io'; | ||
import { RabbitMessage } from '@cisl/io/types'; | ||
import { DisplayWindow } from './display-window'; | ||
export interface DeviceEmulationOptions { | ||
@@ -68,5 +69,6 @@ screenPosition: 'desktop' | 'mobile'; | ||
displayName: string; | ||
private window; | ||
windowName: string; | ||
private displayContextName; | ||
constructor(io: Io, options: { | ||
constructor(io: Io, window: DisplayWindow, options: { | ||
viewId: string; | ||
@@ -98,3 +100,3 @@ displayName: string; | ||
* @returns {display_rpc_result} | ||
*/ | ||
*/ | ||
enableDeviceEmulation(options: DeviceEmulationOptions): Promise<object>; | ||
@@ -132,5 +134,10 @@ /** | ||
setBounds(options: { | ||
width: number; | ||
height: number; | ||
viewId?: string; | ||
gridLeft?: number; | ||
gridTop?: number; | ||
left?: number; | ||
top?: number; | ||
widthFactor?: number; | ||
width?: number; | ||
heightFactor?: number; | ||
height?: number; | ||
}): Promise<object>; | ||
@@ -153,5 +160,5 @@ /** | ||
/** | ||
* opens debug console | ||
* @returns {display_rpc_result} | ||
*/ | ||
* opens debug console | ||
* @returns {display_rpc_result} | ||
*/ | ||
openDevTools(): Promise<object>; | ||
@@ -170,31 +177,31 @@ /** | ||
/** | ||
* gets if audio muted | ||
* @returns {display_rpc_result} | ||
*/ | ||
* gets if audio muted | ||
* @returns {display_rpc_result} | ||
*/ | ||
isAudioMuted(): Promise<object>; | ||
private _on; | ||
/** | ||
* viewObject hidden event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
* viewObject hidden event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
onHidden(handler: (response: RabbitMessage) => void): void; | ||
/** | ||
* viewObject became visible event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
* viewObject became visible event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
onShown(handler: (response: RabbitMessage) => void): void; | ||
/** | ||
* viewObject closed event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
* viewObject closed event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
onClosed(handler: (response: RabbitMessage) => void): void; | ||
/** | ||
* viewObject bounds changed event | ||
* @param {viewObjectBoundsEventCallback} handler | ||
*/ | ||
* viewObject bounds changed event | ||
* @param {viewObjectBoundsEventCallback} handler | ||
*/ | ||
onBoundsChanged(handler: (response: RabbitMessage) => void): void; | ||
/** | ||
* viewObject URL changed event | ||
* @param {viewObjectURLEventCallback} handler | ||
*/ | ||
* viewObject URL changed event | ||
* @param {viewObjectURLEventCallback} handler | ||
*/ | ||
onUrlChanged(handler: (response: RabbitMessage) => void): void; | ||
@@ -217,6 +224,6 @@ /** | ||
/** | ||
* viewObject plugin crashed event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
* viewObject plugin crashed event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
onPluginCrashed(handler: (response: RabbitMessage) => void): void; | ||
} |
@@ -9,3 +9,3 @@ "use strict"; | ||
class ViewObject { | ||
constructor(io, options) { | ||
constructor(io, window, options) { | ||
if (!io.rabbit) { | ||
@@ -18,3 +18,4 @@ throw new Error('Could not find RabbitMQ instance'); | ||
this.displayContextName = options.displayContextName; | ||
this.windowName = options.windowName; | ||
this.window = window; | ||
this.windowName = window.windowName; | ||
} | ||
@@ -74,3 +75,3 @@ async _postRequest(data) { | ||
* @returns {display_rpc_result} | ||
*/ | ||
*/ | ||
enableDeviceEmulation(options) { | ||
@@ -163,3 +164,22 @@ const cmd = { | ||
// } | ||
options.viewId = this.viewId; | ||
console.log(this.window.uniformGridCellSize); | ||
if (options.gridLeft) { | ||
options.left = this.window.uniformGridCellSize.width * (options.gridLeft - 1); | ||
delete options.gridLeft; | ||
} | ||
if (options.gridTop) { | ||
options.top = this.window.uniformGridCellSize.height * (options.gridTop - 1); | ||
delete options.gridTop; | ||
} | ||
if (options.widthFactor) { | ||
options.width = | ||
this.window.uniformGridCellSize.width * options.widthFactor; | ||
delete options.widthFactor; | ||
} | ||
if (options.heightFactor) { | ||
options.height = | ||
this.window.uniformGridCellSize.height * options.heightFactor; | ||
delete options.heightFactor; | ||
} | ||
console.log(options); | ||
const cmd = { | ||
@@ -211,5 +231,5 @@ command: 'set-bounds', | ||
/** | ||
* opens debug console | ||
* @returns {display_rpc_result} | ||
*/ | ||
* opens debug console | ||
* @returns {display_rpc_result} | ||
*/ | ||
openDevTools() { | ||
@@ -255,5 +275,5 @@ const cmd = { | ||
/** | ||
* gets if audio muted | ||
* @returns {display_rpc_result} | ||
*/ | ||
* gets if audio muted | ||
* @returns {display_rpc_result} | ||
*/ | ||
isAudioMuted() { | ||
@@ -269,15 +289,21 @@ const cmd = { | ||
_on(topic, handler) { | ||
this.io.rabbit.onTopic(topic, (response) => { | ||
if (Buffer.isBuffer(response.content) || typeof response.content !== 'object') { | ||
this.io.rabbit | ||
.onTopic(topic, (response) => { | ||
if (Buffer.isBuffer(response.content) || | ||
typeof response.content !== 'object') { | ||
throw new Error('invalid response received'); | ||
} | ||
if (handler != null && response.content.details.viewId == this.viewId) { | ||
if (handler != null && | ||
response.content.details.viewId == this.viewId) { | ||
handler(response); | ||
} | ||
}).catch(() => { }); | ||
}) | ||
.catch(() => { | ||
/* pass */ | ||
}); | ||
} | ||
/** | ||
* viewObject hidden event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
* viewObject hidden event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
onHidden(handler) { | ||
@@ -287,5 +313,5 @@ this._on(`display.${this.displayContextName}.viewObjectHidden.${this.viewId}`, handler); | ||
/** | ||
* viewObject became visible event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
* viewObject became visible event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
onShown(handler) { | ||
@@ -295,5 +321,5 @@ this._on(`display.${this.displayContextName}.viewObjectShown.${this.viewId}`, handler); | ||
/** | ||
* viewObject closed event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
* viewObject closed event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
onClosed(handler) { | ||
@@ -303,5 +329,5 @@ this._on(`display.${this.displayContextName}.viewObjectClosed.${this.viewId}`, handler); | ||
/** | ||
* viewObject bounds changed event | ||
* @param {viewObjectBoundsEventCallback} handler | ||
*/ | ||
* viewObject bounds changed event | ||
* @param {viewObjectBoundsEventCallback} handler | ||
*/ | ||
onBoundsChanged(handler) { | ||
@@ -311,5 +337,5 @@ this._on(`display.${this.displayContextName}.viewObjectBoundsChanged.${this.viewId}`, handler); | ||
/** | ||
* viewObject URL changed event | ||
* @param {viewObjectURLEventCallback} handler | ||
*/ | ||
* viewObject URL changed event | ||
* @param {viewObjectURLEventCallback} handler | ||
*/ | ||
onUrlChanged(handler) { | ||
@@ -340,5 +366,5 @@ this._on(`display.${this.displayContextName}.viewObjectUrlChanged.${this.viewId}`, handler); | ||
/** | ||
* viewObject plugin crashed event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
* viewObject plugin crashed event | ||
* @param {viewObjectBasicEventCallback} handler | ||
*/ | ||
onPluginCrashed(handler) { | ||
@@ -345,0 +371,0 @@ this._on(`display.${this.displayContextName}.viewObjectPluginCrashed.${this.viewId}`, handler); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
89037
2547
67
0