Skip to content

Commit

Permalink
Add support for looping videos and remove debug logs
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Boberg <[email protected]>
  • Loading branch information
axelboberg committed Jan 8, 2024
1 parent bc8305f commit 9cf3d00
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 12 deletions.
1 change: 0 additions & 1 deletion lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ function factory (workspace) {
const res = await handler(...args)
executeCommand(transaction, res)
} catch (err) {
console.log('Got error', err)
executeCommand(transaction, undefined, err)
}
removeCommand(transaction)
Expand Down
2 changes: 1 addition & 1 deletion lib/schemas/type.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"properties": {
"type": {
"type": "string",
"enum": ["string", "number", "text", "color", "enum"]
"enum": ["string", "number", "text", "color", "enum", "boolean"]
},
"name": {
"type": "string"
Expand Down
1 change: 0 additions & 1 deletion plugins/caspar/app/components/LibraryListItem/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function calculateDurationMs (item) {

export const LibraryListItem = ({ item = {} }) => {
async function handleDragStart (e) {
console.log('Item', item)
e.dataTransfer.setData('bridge/item', JSON.stringify({
type: 'bridge.caspar.media',
data: {
Expand Down
24 changes: 23 additions & 1 deletion plugins/caspar/lib/AMCP.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ exports.info = opts => `INFO ${layerString(opts)}`
*/
exports.clear = opts => `CLEAR ${layerString(opts)}`

/**
* Load a media item in the background
* @see https://github.com/CasparCG/help/wiki/AMCP-Protocol#loadbg
* @param { String } file The file to play
* @param { Boolean } loop
* @param { Number } seek
* @param { Number } length
* @param { String } filter
* @param { Boolean } auto
* @param { AMCPOptions } opts
* @returns { String }
*/
exports.loadbg = (file, loop, seek, length, filter, auto, opts) => `LOADBG ${layerString(opts)} ${file} ${loop && 'LOOP'} ${seek ? `SEEK ${seek}` : ''} ${length ? `LENGTH ${length}` : ''} ${filter ? `FILTER ${filter}` : ''} ${transitionString(opts)} ${auto && 'AUTO'}`

/**
* Play a media item in the foreground
* @see https://github.com/CasparCG/help/wiki/AMCP-Protocol#play
Expand All @@ -93,6 +107,15 @@ exports.clear = opts => `CLEAR ${layerString(opts)}`
*/
exports.play = (file, opts) => `PLAY ${layerString(opts)} ${file} ${transitionString(opts)}`

/**
* Play a media item in the foreground that
* has already been loaded in the background
* @see https://github.com/CasparCG/help/wiki/AMCP-Protocol#play
* @param { AMCPOptions } opts
* @returns { String }
*/
exports.playLoaded = (file, opts) => `PLAY ${layerString(opts)}`

/**
* Stop an item running in the foreground
* @see https://github.com/CasparCG/help/wiki/AMCP-Protocol#stop
Expand Down Expand Up @@ -127,6 +150,5 @@ exports.cgStop = opts => `CG ${layerString(opts)} STOP ${opts.cgLayer ?? 1}`
* @returns { String }
*/
exports.cgUpdate = (data, opts) => {
console.log('Sending data', data)
return `CG ${layerString(opts)} UPDATE ${opts.cgLayer ?? 1} ${JSON.stringify(JSON.stringify(data))}`
}
28 changes: 23 additions & 5 deletions plugins/caspar/lib/Caspar.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,23 @@ class Caspar extends EventEmitter {
this.emit('status', newStatus)
}

/**
* @private
* Resolve a response
* object from Caspar
* @param {{
* status: String | Number,
* action: String
* }} responseObject

Check failure on line 217 in plugins/caspar/lib/Caspar.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Trailing spaces not allowed

Check failure on line 217 in plugins/caspar/lib/Caspar.js

View workflow job for this annotation

GitHub Actions / test (15.x)

Trailing spaces not allowed
*/
_resolveResponseObject (responseObject) {
if (responseObject.code >= 200 && responseObject.code <= 299) {
this._resolveTransaction(responseObject.transaction, responseObject)
} else {
this._rejectTransaction(responseObject.transaction, responseObject)
}
}

/**
* @private
*/
Expand Down Expand Up @@ -236,11 +253,7 @@ class Caspar extends EventEmitter {
waiting for more lines
*/
if (line === '' && this._currentResponseObject) {
if (this._currentResponseObject.code >= 200 && this._currentResponseObject.code <= 299) {
this._resolveTransaction(this._currentResponseObject.transaction, this._currentResponseObject)
} else {
this._rejectTransaction(this._currentResponseObject.transaction, this._currentResponseObject)
}
this._resolveResponseObject(this._currentResponseObject)
this._currentResponseObject = undefined
continue
}
Expand All @@ -255,6 +268,11 @@ class Caspar extends EventEmitter {
...header,
data: []
}

if (this._unfinishedLine === '') {
this._resolveResponseObject(this._currentResponseObject)
this._currentResponseObject = undefined
}
} else {
this._currentResponseObject.data.push(line)
}
Expand Down
5 changes: 3 additions & 2 deletions plugins/caspar/lib/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ const PLAY_HANDLERS = {
'bridge.caspar.amcp': item => {
return commands.sendString(item?.data?.caspar?.server, item?.data?.caspar?.amcp)
},
'bridge.caspar.media': item => {
return commands.sendCommand(item?.data?.caspar?.server, 'play', item?.data?.caspar?.target, item?.data?.caspar)
'bridge.caspar.media': async item => {
await commands.sendCommand(item?.data?.caspar?.server, 'loadbg', item?.data?.caspar?.target, item?.data?.caspar?.loop, 0, undefined, undefined, undefined, item?.data?.caspar)
return commands.sendCommand(item?.data?.caspar?.server, 'playLoaded', '', item?.data?.caspar)
},
'bridge.caspar.template': item => {
return commands.sendCommand(item?.data?.caspar?.server, 'cgAdd', item?.data?.caspar?.target, item?.data?.caspar?.templateData, true, item?.data?.caspar)
Expand Down
5 changes: 5 additions & 0 deletions plugins/caspar/lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ function init (htmlPath) {
category: 'Caspar',
inherits: 'bridge.caspar.playable',
properties: {
'caspar.loop': {
name: 'Loop',
type: 'boolean',
'ui.group': 'Timing'
},
'caspar.transitionName': {
name: 'Transition',
type: 'enum',
Expand Down
25 changes: 25 additions & 0 deletions plugins/inspector/app/components/BooleanInput/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* SPDX-FileCopyrightText: 2022 Sveriges Television AB
*
* SPDX-License-Identifier: MIT
*/

import React from 'react'
import './style.css'

export function BooleanInput ({
htmlFor,
value = '',
onChange = () => {},
large
}) {
return (
<input
type='checkbox'
htmlFor={htmlFor}
className='BooleanInput'
checked={!!value}
onChange={e => onChange(e.target.checked)}
/>
)
}
5 changes: 5 additions & 0 deletions plugins/inspector/app/components/BooleanInput/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Sveriges Television AB
*
* SPDX-License-Identifier: MIT
*/
4 changes: 3 additions & 1 deletion plugins/inspector/app/components/Form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ import { TextInput } from '../TextInput'
import { ColorInput } from '../ColorInput'
import { StringInput } from '../StringInput'
import { SelectInput } from '../SelectInput'
import { BooleanInput } from '../BooleanInput'

const INPUT_COMPONENTS = {
boolean: BooleanInput,
string: StringInput,
color: ColorInput,
enum: SelectInput,
text: TextInput,
enum: SelectInput
}

/**
Expand Down

0 comments on commit 9cf3d00

Please sign in to comment.