-
Notifications
You must be signed in to change notification settings - Fork 54
SOFIE-47 | add automatic configuration of peripheral devices if there is only 1 studio #1569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anteeek
wants to merge
1
commit into
release53
Choose a base branch
from
feat/SOFIE-47
base: release53
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,6 +166,10 @@ export namespace ServerPeripheralDeviceAPI { | |
|
|
||
| documentationUrl: options.documentationUrl, | ||
| }) | ||
|
|
||
| // If there is only one Studio, assign the device to that studio. | ||
| // Overall plan at the moment is to have only 1 studio per sofie instance in mid-term future | ||
| await assignToStudioIfOnlyOnePresent(deviceId, options) | ||
| } | ||
| if (options.configManifest?.translations) { | ||
| await upsertBundles( | ||
|
|
@@ -175,6 +179,43 @@ export namespace ServerPeripheralDeviceAPI { | |
| } | ||
| return deviceId | ||
| } | ||
|
|
||
| async function assignToStudioIfOnlyOnePresent(deviceId: PeripheralDeviceId, options: PeripheralDeviceInitOptions) { | ||
| if ((await Studios.countDocuments()) !== 1) { | ||
| return | ||
| } | ||
|
|
||
| const studio = await Studios.findOneAsync({}) | ||
|
|
||
| if (!studio) { | ||
| return | ||
| } | ||
|
|
||
| const configId = unprotectString(deviceId) | ||
|
|
||
| await Studios.updateAsync(studio._id, { | ||
| $push: { | ||
| [`peripheralDeviceSettings.deviceSettings.overrides`]: { | ||
| op: 'set', | ||
| path: configId, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the risk is low, it is possible that this will replace an existing config with this empty one. I think this needs to make sure that |
||
| value: { | ||
| name: options.name, | ||
| options: {}, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| await PeripheralDevices.updateAsync(deviceId, { | ||
| $set: { | ||
| studioAndConfigId: { | ||
| configId, | ||
| studioId: studio._id, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| export async function unInitialize( | ||
| context: MethodContext, | ||
| deviceId: PeripheralDeviceId, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how I feel about this creating a config object for itself when attaching..
There are 2 scenarios:
As the recommended approach for blueprints is 1, should we be prioritising that being smoother?
I dont know, Im curious what anyone else thinks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I too feel that this is a false friend in our "Configuration as Code" philosophy. I think we should probably re-think our "first run story": we should have the blueprints be the first thing that gets set up in a System, have them pre-populate the
deviceSettingsfor a Studio and then, on first connection, the Peripheral Devices are matched to a known config.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I dont disagree with that, but even if blueprints are supposed to pre-generate the configurations, there will be cases where they havent so having a fallback to attach them with an empty config is still good.
So I am leaning towards leaving that larger rethinking until we have actually removed support for multiple studios; as that should in theory simplify these things even further
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Julusian @jstarpl guys, given that configIds in blueprints are arbitrary (correct me if I'm wrong) is there a way we can programmatically determine here which configId to hook up?