Skip to content

Commit

Permalink
feat: updateProps only updates the valid properties (according to the…
Browse files Browse the repository at this point in the history
… mask). Returns true if anything was changed
  • Loading branch information
Julusian committed Dec 7, 2019
1 parent 416a520 commit 7d48ff6
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test('setSuperSourceProperties - 7.2', async () => {
expect(conn.sendCommand).toHaveBeenCalledTimes(1)
expect(conn.sendCommand).toHaveBeenNthCalledWith(1, {
flag: 12,
properties: {
_properties: {
artOption: 0,
artPreMultiplied: true
}
Expand All @@ -64,7 +64,7 @@ test('setSuperSourceProperties - 8.0', async () => {
expect(conn.sendCommand).toHaveBeenNthCalledWith(1, {
ssrcId: 2,
flag: 12,
properties: {
_properties: {
artOption: 0,
artPreMultiplied: true
}
Expand All @@ -86,7 +86,7 @@ test('setSuperSourceBorder - 7.2', async () => {
expect(conn.sendCommand).toHaveBeenCalledTimes(1)
expect(conn.sendCommand).toHaveBeenNthCalledWith(1, {
flag: 139264,
properties: {
_properties: {
borderBevelSoftness: 12,
borderLuma: 3
}
Expand All @@ -109,7 +109,7 @@ test('setSuperSourceBorder - 8.0', async () => {
expect(conn.sendCommand).toHaveBeenNthCalledWith(1, {
ssrcId: 2,
flag: 1088,
properties: {
_properties: {
borderBevelSoftness: 12,
borderLuma: 3
}
Expand Down
1 change: 0 additions & 1 deletion src/commands/Audio/AudioMixerInputCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class AudioMixerInputCommand extends WritableCommand<AudioChannel> {
super()

this.index = index
this.properties = {}
}

serialize () {
Expand Down
24 changes: 14 additions & 10 deletions src/commands/CommandBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ export abstract class BasicWritableCommand<T> implements ISerializableCommand {
static readonly MaskFlags?: { [key: string]: number }
static readonly minimumVersion?: ProtocolVersion

properties: T
protected _properties: T

public get properties (): Readonly<T> {
return this._properties
}

constructor (properties: T) {
this.properties = properties
this._properties = properties
}

abstract serialize (version: ProtocolVersion): Buffer
Expand All @@ -47,24 +51,24 @@ export abstract class WritableCommand<T> extends BasicWritableCommand<Partial<T>
this.flag = 0
}

public updateProps (newProps: Partial<T>) {
this._updateProps(newProps)
public updateProps (newProps: Partial<T>): boolean {
return this._updateProps(newProps)
}

protected _updateProps (newProps: Object) {
this.properties = {
...this.properties,
...newProps
}
protected _updateProps (newProps: { [key: string]: any }): boolean {
const maskFlags = (this.constructor as any).MaskFlags as { [key: string]: number }

let hasChanges = false
if (maskFlags) {
for (const key in newProps) {
const key2 = key as keyof T
if (key in maskFlags) {
this.flag = this.flag | maskFlags[key]
this._properties[key2] = newProps[key]
hasChanges = true
}
}
}
return hasChanges
}

}
1 change: 0 additions & 1 deletion src/commands/Inputs/InputPropertiesCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class InputPropertiesCommand extends WritableCommand<InputChannel> {
super()

this.inputId = inputId
this.properties = {}
}

serialize () {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Media/MediaPlayerStatusCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class MediaPlayerStatusCommand extends WritableCommand<MediaPlayer> {
playing: 1 << 0,
loop: 1 << 1,
atBeginning: 1 << 2,
frame: 1 << 3
clipFrame: 1 << 3
}
static readonly rawName = 'SCPS'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class FadeToBlackRateCommand extends BasicWritableCommand<{ rate: number
super({ rate })

this.mixEffect = mixEffect
this.properties = { rate }
}

serialize () {
Expand Down
1 change: 0 additions & 1 deletion src/commands/MixEffects/Key/MixEffectKeyDVECommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class MixEffectKeyDVECommand extends WritableCommand<UpstreamKeyerDVESett

this.mixEffect = mixEffect
this.upstreamKeyerId = upstreamKeyerId
this.properties = {}
}

serialize () {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/MixEffects/Key/MixEffectKeyTypeSetCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UpstreamKeyerTypeSettings } from '../../../state/video/upstreamKeyers'

export class MixEffectKeyTypeSetCommand extends WritableCommand<UpstreamKeyerTypeSettings> {
static MaskFlags = {
keyType: 1 << 0,
mixEffectKeyType: 1 << 0,
flyEnabled: 1 << 1
}

Expand Down
10 changes: 4 additions & 6 deletions src/commands/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ const commandConverters: CommandTestConverterSet = {
'mixEffect': 'mixEffectIndex',
'upstreamKeyerId': 'keyerIndex'
},
propertyAliases: {}
propertyAliases: {
'keyType': (v: number) => ({ val: v, name: 'mixEffectKeyType' })
}
},
'KeOn': {
idAliases: {
Expand Down Expand Up @@ -644,11 +646,7 @@ const commandConverters: CommandTestConverterSet = {
idAliases: {
'mediaPool': 'index'
},
propertyAliases: {},
customMutate: (obj: any) => {
obj.frames = []
return obj
}
propertyAliases: {}
},
'SMPC': {
idAliases: {
Expand Down

0 comments on commit 7d48ff6

Please sign in to comment.