Skip to content

Commit

Permalink
Merge pull request #265 from bryce-seifert/v3.5.0
Browse files Browse the repository at this point in the history
v3.5.0
  • Loading branch information
bryce-seifert authored Jun 2, 2024
2 parents f6cb79d + aecbd7c commit 4e570d2
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 71 deletions.
62 changes: 54 additions & 8 deletions actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ export function getActions() {
id: 'scene',
default: 'Current Scene',
choices: this.sceneChoicesProgramPreview,
allowCustom: true,
},
{
type: 'checkbox',
Expand All @@ -683,6 +684,7 @@ export function getActions() {
id: 'source',
default: this.sourceListDefault,
choices: this.sourceChoices,
allowCustom: true,
isVisible: (options) => options.all === false,
},
{
Expand All @@ -697,9 +699,9 @@ export function getActions() {
],
},
],
callback: (action) => {
let sceneName = action.options.scene
let sourceName = action.options.source
callback: async (action) => {
let sceneName = await this.parseVariablesInString(action.options.scene)
let sourceName = await this.parseVariablesInString(action.options.source)
let enabled = true
let requests = []

Expand Down Expand Up @@ -1071,6 +1073,7 @@ export function getActions() {
id: 'source',
default: this.sourceListDefault,
choices: this.sourceChoicesWithScenes,
allowCustom: true,
},
{
type: 'checkbox',
Expand All @@ -1084,6 +1087,7 @@ export function getActions() {
id: 'filter',
default: this.filterListDefault,
choices: this.filterList,
allowCustom: true,
isVisible: (options) => options.all === false,
},
{
Expand All @@ -1098,8 +1102,11 @@ export function getActions() {
],
},
],
callback: (action) => {
let sourceFilterList = this.sourceFilters[action.options.source]
callback: async (action) => {
let source = await this.parseVariablesInString(action.options.source)
let filterName = await this.parseVariablesInString(action.options.filter)

let sourceFilterList = this.sourceFilters[source]
if (action.options.all) {
let requests = []
sourceFilterList.forEach((filter) => {
Expand All @@ -1112,7 +1119,7 @@ export function getActions() {
}
requests.push({
requestType: 'SetSourceFilterEnabled',
requestData: { sourceName: action.options.source, filterName: name, filterEnabled: filterVisibility },
requestData: { sourceName: source, filterName: name, filterEnabled: filterVisibility },
})
})

Expand All @@ -1123,18 +1130,57 @@ export function getActions() {
filterVisibility = action.options.visible === 'true' ? true : false
} else if (action.options.visible === 'toggle') {
if (sourceFilterList) {
let filter = sourceFilterList.find((item) => item.filterName === action.options.filter)
let filter = sourceFilterList.find((item) => item.filterName === filterName)
if (filter) {
filterVisibility = !filter.filterEnabled
}
}
}

this.sendRequest('SetSourceFilterEnabled', {
sourceName: source,
filterName: filterName,
filterEnabled: filterVisibility,
})
}
},
}
actions['setFilterSettings'] = {
name: 'Set Filter Settings',
options: [
{
type: 'dropdown',
label: 'Source / Scene',
id: 'source',
default: this.sourceListDefault,
choices: this.sourceChoicesWithScenes,
},
{
type: 'dropdown',
label: 'Filter',
id: 'filter',
default: this.filterListDefault,
choices: this.filterList,
},
{
type: 'textinput',
label: 'Filter Settings',
id: 'settings',
default: '{"left": 100, "top": 0, "right": 100, "bottom": 0}',
tooltip: 'Must be a JSON object with the settings for the filter',
},
],
callback: (action) => {
try {
let settings = JSON.parse(action.options.settings)
this.sendRequest('SetSourceFilterSettings', {
sourceName: action.options.source,
filterName: action.options.filter,
filterEnabled: filterVisibility,
filterSettings: settings,
})
} catch (e) {
this.log('warn', `Error parsing JSON for Set Filter Settings (${e.message})`)
return
}
},
}
Expand Down
1 change: 1 addition & 0 deletions companion/HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This module will allow you to control OBS Studio using the obs-websocket plugin.

- Set Source Visibility _(Individual sources, or All Sources within a scene)_
- Set Filter Visibility
- Set Filter Settings
- Set Source Transform (Position / Scale / Rotation)
- Source Mute (Set / Toggle)
- Set Source Volume
Expand Down
2 changes: 1 addition & 1 deletion companion/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "obs-studio",
"shortname": "obs",
"description": "Control OBS Studio using the obs-websocket plugin",
"version": "3.4.3",
"version": "3.5.0",
"license": "MIT",
"repository": "git+https://github.com/bitfocus/companion-module-obs-studio.git",
"bugs": "https://github.com/bitfocus/companion-module-obs-studio/issues",
Expand Down
68 changes: 51 additions & 17 deletions feedbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export function getFeedbacks() {
const feedbacks = {}

const ColorWhite = combineRgb(255, 255, 255)
const ColorGray = combineRgb(72, 72, 72)
const ColorBlack = combineRgb(0, 0, 0)
const ColorRed = combineRgb(200, 0, 0)
const ColorGreen = combineRgb(0, 200, 0)
Expand Down Expand Up @@ -300,6 +301,7 @@ export function getFeedbacks() {
id: 'scene',
default: this.sceneListDefault,
choices: this.sceneChoices,
allowCustom: true,
minChoicesForSearch: 5,
},
{
Expand All @@ -314,30 +316,33 @@ export function getFeedbacks() {
id: 'source',
default: this.sourceListDefault,
choices: this.sourceChoices,
allowCustom: true,
minChoicesForSearch: 5,
isVisible: (options) => !options.any,
},
],
callback: (feedback) => {
callback: async (feedback, context) => {
let sceneName = await this.parseVariablesInString(feedback.options.scene, context)
let sourceName = await this.parseVariablesInString(feedback.options.source, context)

if (feedback.options.any) {
let scene = this.sceneItems[feedback.options.scene]
let scene = this.sceneItems[sceneName]

if (scene) {
let enabled = this.sceneItems[feedback.options.scene].find((item) => item.sceneItemEnabled === true)
let enabled = this.sceneItems[sceneName].find((item) => item.sceneItemEnabled === true)
if (enabled) {
return true
}
}
} else {
if (this.sources[feedback.options.source]?.groupedSource) {
let group = this.sources[feedback.options.source].groupName
let sceneItem = this.groups[group].find((item) => item.sourceName === feedback.options.source)
if (this.sources[sourceName]?.groupedSource) {
let group = this.sources[sourceName].groupName
let sceneItem = this.groups[group].find((item) => item.sourceName === sourceName)
if (sceneItem) {
return sceneItem.sceneItemEnabled
}
} else if (this.sceneItems[feedback.options.scene]) {
let sceneItem = this.sceneItems[feedback.options.scene].find(
(item) => item.sourceName === feedback.options.source
)
} else if (this.sceneItems[sceneName]) {
let sceneItem = this.sceneItems[sceneName].find((item) => item.sourceName === sourceName)
if (sceneItem) {
return sceneItem.sceneItemEnabled
}
Expand Down Expand Up @@ -696,14 +701,43 @@ export function getFeedbacks() {
type: 'advanced',
name: 'Stream Congestion',
description: 'Change the style of the button to show stream congestion',
options: [],
callback: () => {
if (this.states.streamCongestion > 0.8) {
return { bgcolor: ColorRed }
} else if (this.states.congestion > 0.4) {
return { bgcolor: ColorOrange }
options: [
{
type: 'colorpicker',
label: 'Background color (No Stream)',
id: 'colorNoStream',
default: ColorGray,
},
{
type: 'colorpicker',
label: 'Background color (Low Congestion)',
id: 'colorLow',
default: ColorGreen,
},
{
type: 'colorpicker',
label: 'Background color (Medium Congestion)',
id: 'colorMedium',
default: ColorOrange,
},
{
type: 'colorpicker',
label: 'Background color (High Congestion)',
id: 'colorHigh',
default: ColorRed,
},
],
callback: (feedback) => {
if (this.states.streaming === false) {
return { bgcolor: feedback.options.colorNoStream }
} else {
return { bgcolor: ColorGreen }
if (this.states.streamCongestion > 0.8) {
return { bgcolor: feedback.options.colorHigh }
} else if (this.states.congestion > 0.4) {
return { bgcolor: feedback.options.colorMedium }
} else {
return { bgcolor: feedback.options.colorLow }
}
}
},
}
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,12 @@ class OBSInstance extends InstanceBase {
})
this.obs.on('SceneTransitionStarted', () => {
this.states.transitionActive = true
this.setVariableValues({ transition_active: 'True' })
this.checkFeedbacks('transition_active')
})
this.obs.on('SceneTransitionEnded', () => {
this.states.transitionActive = false
this.setVariableValues({ transition_active: 'False' })
this.checkFeedbacks('transition_active')
})
this.obs.on('SceneTransitionVideoEnded', () => {})
Expand Down Expand Up @@ -542,7 +544,7 @@ class OBSInstance extends InstanceBase {
this.states.streaming = data.outputActive

this.setVariableValues({ streaming: this.states.streaming ? 'Live' : 'Off-Air' })
this.checkFeedbacks('streaming')
this.checkFeedbacks('streaming', 'streamCongestion')
})
this.obs.on('RecordStateChanged', (data) => {
if (data.outputActive === true) {
Expand Down Expand Up @@ -1077,7 +1079,8 @@ class OBSInstance extends InstanceBase {
let input = await this.sendRequest('GetInputSettings', { inputName: sourceName })

if (input.inputSettings) {
this.updateInputSettings(sourceName, input.inputSettings)
this.buildInputSettings(sourceName, sceneItem.inputKind, input.inputSettings)
this.updateActionsFeedbacksVariables()
}
}
})
Expand All @@ -1103,6 +1106,7 @@ class OBSInstance extends InstanceBase {
this.setVariableValues({
current_transition: this.states.currentTransition,
transition_duration: this.states.transitionDuration,
transition_active: 'False',
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "obs-studio",
"version": "3.4.3",
"version": "3.5.0",
"main": "index.js",
"type": "module",
"scripts": {
"format": "prettier -w ."
},
"license": "MIT",
"dependencies": {
"@companion-module/base": "~1.7.0",
"@companion-module/base": "~1.8.0",
"obs-websocket-js": "5.0.5"
},
"repository": {
Expand Down
23 changes: 23 additions & 0 deletions upgrades.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ export default [
}
}

return changes
},
function v3_5_0(context, props) {
let changes = {
updatedConfig: null,
updatedActions: [],
updatedFeedbacks: [],
}

for (const feedback of props.feedbacks) {
if (feedback.feedbackId === 'streamCongestion') {
if (!feedback.options.colorNoStream) {
feedback.options = {
colorNoStream: '#484848',
colorLow: '#00c800',
colorMedium: '#ff6600',
colorHigh: '#c80000',
}
}
changes.updatedFeedbacks.push(feedback)
}
}

return changes
},
]
1 change: 1 addition & 0 deletions variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function getVariables() {
variables.push({ variableId: 'scene_collection', name: 'Current scene collection' })
variables.push({ variableId: 'current_transition', name: 'Current transition' })
variables.push({ variableId: 'transition_duration', name: 'Current transition duration' })
variables.push({ variableId: 'transition_active', name: 'Transition in progress' })
variables.push({ variableId: 'current_media_name', name: 'Source name for currently playing media source' })
variables.push({ variableId: 'current_media_time_elapsed', name: 'Time elapsed for currently playing media source' })
variables.push({
Expand Down
Loading

0 comments on commit 4e570d2

Please sign in to comment.