184 lines
6.2 KiB
JavaScript
184 lines
6.2 KiB
JavaScript
// import axios from 'axios';
|
|
// import { callbackify } from 'util';
|
|
// import { ConnectionManager_Connection } from '../../../../ConnectionManager';
|
|
// import { Log } from '../../../../Logger';
|
|
// import { ActionAPI } from '../../../ActionAPI';
|
|
// import { EditorAPI, EditorAPI_Field } from '../../../EditorAPI';
|
|
// module.exports = (actionAPI: ActionAPI) => {
|
|
// actionAPI.handle(
|
|
// (properties: Publish_Properties, status: (text: string, type?: 'info' | 'error' | 'warn') => void) => {
|
|
// var connectionID = properties.connectionID;
|
|
// var sceneID = properties.sceneID;
|
|
// var displayIDs = properties.displayIDs;
|
|
// var connection = actionAPI.getConnection('channel', connectionID);
|
|
// if (connection && connectionID != undefined && sceneID != undefined && displayIDs != undefined) {
|
|
// var url = `${getBaseURL(connection)}/scenes/publish/${sceneID}/${displayIDs.join(',')}`;
|
|
// axios
|
|
// .get(url)
|
|
// .then((response) => {
|
|
// if (response.data != undefined) {
|
|
// if (response.data.succeed == true) {
|
|
// status(`Scene ${sceneID} was published to display(s) ${displayIDs.join(', ')}`);
|
|
// } else status(response.data.error, 'error');
|
|
// }
|
|
// })
|
|
// .catch((error) => {
|
|
// status('Unable to reach Getiyo server', 'error');
|
|
// });
|
|
// }
|
|
// }
|
|
// );
|
|
// var channelSceneCache = {};
|
|
// actionAPI.onOpenEditor((editorAPI: EditorAPI, properties: Publish_Properties) => {
|
|
// var connectionID = properties.connectionID != undefined ? properties.connectionID : 'none';
|
|
// var sceneID = properties.sceneID != undefined ? properties.sceneID : 'none';
|
|
// var displayIDs = properties.displayIDs != undefined ? properties.displayIDs : [];
|
|
// var connection: ConnectionManager_Connection = null;
|
|
// var lastConnectionID: string = connectionID;
|
|
// editorAPI.onFieldChanges((newFields: EditorAPI_Field[]) => {
|
|
// var fieldObject = editorAPI.tools.objectifyFieldsValues(newFields);
|
|
// editorAPI.saveProperties({
|
|
// connectionID: fieldObject.connection,
|
|
// sceneID: fieldObject.sceneID,
|
|
// displayIDs: fieldObject.displayIDs
|
|
// });
|
|
// fields[0].value = fieldObject.connection;
|
|
// if (lastConnectionID != fieldObject.connection) {
|
|
// getConnection(fieldObject.connection, () => {
|
|
// editorAPI.setFields(fields);
|
|
// });
|
|
// }
|
|
// });
|
|
// function getConnection(connectionID: string, callback: () => void) {
|
|
// var newConnection = actionAPI.getConnection('channel', connectionID);
|
|
// if (connectionID == 'none') {
|
|
// fields[1].values = [];
|
|
// fields[2].values = [];
|
|
// callback();
|
|
// } else if (newConnection != null) {
|
|
// lastConnectionID = connectionID;
|
|
// connection = newConnection;
|
|
// updateScenes(() => updateDisplays(callback));
|
|
// } else callback();
|
|
// }
|
|
// function updateScenes(callback: () => void) {
|
|
// var baseURL = getBaseURL(connection);
|
|
// if (baseURL) {
|
|
// axios
|
|
// .get(`${baseURL}/scenes`)
|
|
// .then((response) => {
|
|
// if (response.data != undefined) {
|
|
// if (response.data.succeed == true) {
|
|
// var scenes: Channel_Scene[] = response.data.response.map((scene) => {
|
|
// return { id: scene.id, text: `${scene.id} - ${scene.name}` };
|
|
// });
|
|
// fields[1].values = scenes;
|
|
// channelSceneCache[connection.properties.channel] = scenes;
|
|
// callback();
|
|
// } else {
|
|
// Log('error', response.data.error);
|
|
// callback();
|
|
// }
|
|
// }
|
|
// })
|
|
// .catch((error) => {
|
|
// Log(
|
|
// 'error',
|
|
// `Error whilst fetching Getiyo scenes for channel '${connection.properties.channel}'`,
|
|
// error
|
|
// );
|
|
// callback();
|
|
// });
|
|
// }
|
|
// }
|
|
// function updateDisplays(callback: () => void) {
|
|
// var baseURL = getBaseURL(connection);
|
|
// if (baseURL) {
|
|
// axios
|
|
// .get(`${baseURL}/displays`)
|
|
// .then((response) => {
|
|
// if (response.data != undefined) {
|
|
// if (response.data.succeed == true) {
|
|
// var scenes: Channel_Display[] = response.data.response.map((display) => {
|
|
// return { id: display.id, text: `${display.id} - ${display.name}` };
|
|
// });
|
|
// fields[2].values = scenes;
|
|
// channelSceneCache[connection.properties.channel] = scenes;
|
|
// callback();
|
|
// } else {
|
|
// Log('error', response.data.error);
|
|
// callback();
|
|
// }
|
|
// }
|
|
// })
|
|
// .catch((error) => {
|
|
// Log(
|
|
// 'error',
|
|
// `Error whilst fetching Getiyo displays for channel '${connection.properties.channel}'`,
|
|
// error
|
|
// );
|
|
// callback();
|
|
// });
|
|
// }
|
|
// }
|
|
// var defaultSceneValues = [];
|
|
// if (connection != null && connection.properties != null) {
|
|
// if (channelSceneCache[connection.properties.channel] != undefined) {
|
|
// defaultSceneValues = channelSceneCache[connection.properties.channel];
|
|
// }
|
|
// }
|
|
// var fields: EditorAPI_Field[] = [
|
|
// {
|
|
// id: 'connection',
|
|
// name: 'Connection',
|
|
// type: 'connection',
|
|
// value: connectionID,
|
|
// connectionType: 'channel'
|
|
// },
|
|
// {
|
|
// id: 'sceneID',
|
|
// name: 'Scene',
|
|
// type: 'select',
|
|
// value: sceneID,
|
|
// values: defaultSceneValues
|
|
// },
|
|
// {
|
|
// id: 'displayIDs',
|
|
// name: 'Displays',
|
|
// type: 'select',
|
|
// multi: true,
|
|
// value: displayIDs,
|
|
// values: []
|
|
// }
|
|
// ];
|
|
// getConnection(connectionID, () => editorAPI.setFields(fields));
|
|
// });
|
|
// function getBaseURL(connection) {
|
|
// if (connection != null) {
|
|
// var addressString = <string>connection.properties.address;
|
|
// var address =
|
|
// !addressString.startsWith('http://') && !addressString.startsWith('https://')
|
|
// ? `https://${addressString}`
|
|
// : addressString;
|
|
// var fullQuery = `${address}:${connection.properties.port}/api/v1/${connection.properties.key}/${connection
|
|
// .properties.channel}`;
|
|
// return fullQuery;
|
|
// }
|
|
// return null;
|
|
// }
|
|
// };
|
|
// interface Publish_Properties {
|
|
// connectionID: string;
|
|
// sceneID: string;
|
|
// displayIDs: string[];
|
|
// }
|
|
// interface Channel_Scene {
|
|
// id: string;
|
|
// text: string;
|
|
// }
|
|
// interface Channel_Display {
|
|
// id: string;
|
|
// text: string;
|
|
// scene: string;
|
|
// }
|
|
//# sourceMappingURL=publish.js.map
|