Skip to content

Commit

Permalink
Add an option to include groups in server listings in the caspar plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Boberg <[email protected]>
  • Loading branch information
axelboberg committed Jan 16, 2024
1 parent b49e6bf commit 112d22c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
9 changes: 8 additions & 1 deletion plugins/caspar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Enables communication with Caspar CG and provides caspar-specific type options t
## API
This plugin exposes a number of commands that can be invoked using the commands api.

### `caspar.listServers()`
### `caspar.listServers([groups])`
Add a new server to the workspace and returns
its id for further reference

Expand All @@ -22,6 +22,13 @@ Variable 'servers' gets defined as
an array of server descriptor objects
*/
const servers = await bridge.commands.executeCommand('caspar.listServers')

/*
Variable 'serversAndGroups' gets defined
as an array of server descriptor objects,
including groups
*/
const serversAndGroups = await bridge.commands.executeCommand('caspar.listServers', true)
```

### `caspar.addServer(serverDescription)`
Expand Down
4 changes: 2 additions & 2 deletions plugins/caspar/app/components/ServerSelector/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './style.css'

import { SharedContext } from '../../sharedContext'

const STATIC_SERVERS = [
const SERVER_GROUPS = [
{
id: 'group:0',
name: 'Group: Primary'
Expand All @@ -27,7 +27,7 @@ export const ServerSelector = ({ value = '__none', multipleValuesSelected = fals
<option value='__multiple-values' disabled>Multiple values</option>
}
{
[...STATIC_SERVERS, ...servers].map(server => {
[...SERVER_GROUPS, ...servers].map(server => {
return <option key={server.id} value={server?.id}>{server?.name || 'Unnamed'}</option>
})
}
Expand Down
20 changes: 18 additions & 2 deletions plugins/caspar/lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ const cache = new Cache()

const CommandError = require('./error/CommandError')

const SERVER_GROUPS = [
{
id: 'group:0',
name: 'Group: Primary'
},
{
id: 'group:1',
name: 'Group: Secondary'
}
]

/**
* Setup a server instance
* from an init-object,
Expand Down Expand Up @@ -156,10 +167,15 @@ bridge.commands.registerCommand('caspar.editServer', editServer)

/**
* Get a list of all configured servers
* @param { Boolean } groups Whether or not to include groups
* @returns { Promise.<ServerDescription[]> }
*/
async function listServers () {
return (await bridge.state.get(`${paths.STATE_SETTINGS_PATH}.servers`)) || []
async function listServers (groups = false) {
const servers = (await bridge.state.get(`${paths.STATE_SETTINGS_PATH}.servers`)) || []
return [
...(groups ? SERVER_GROUPS : []),
...servers
]
}
exports.listServers = listServers
bridge.commands.registerCommand('caspar.listServers', listServers)
Expand Down

0 comments on commit 112d22c

Please sign in to comment.