-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for xkeys, streamdeck and spacemouse
- Loading branch information
Showing
14 changed files
with
1,024 additions
and
85 deletions.
There are no files selected for viewing
This file contains 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
2 changes: 1 addition & 1 deletion
2
packages/apps/client/src/components/ScriptEditor/plugins/updateModel.ts
This file contains 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 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 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 |
---|---|---|
@@ -1,12 +1,22 @@ | ||
/* eslint-disable no-mixed-spaces-and-tabs */ | ||
|
||
export type TriggerAction = | ||
| { | ||
type: 'prompterMove' | ||
/** The speed to move the prompter */ | ||
speed: number | ||
} | ||
| { | ||
type: 'prompterJump' | ||
// todo | ||
} | ||
export type AnyTriggerAction = | ||
| TriggerAction< | ||
'prompterMove', | ||
{ | ||
/** The speed to move the prompter */ | ||
speed: number | ||
} | ||
> | ||
| TriggerAction< | ||
'prompterJump', | ||
{ | ||
// todo | ||
} | ||
> | ||
| TriggerAction<'movePrompterToHere', {}> | ||
|
||
type TriggerAction<Type extends string, Payload extends Record<string, any>> = { | ||
type: Type | ||
payload: Payload | ||
} |
This file contains 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
17 changes: 17 additions & 0 deletions
17
packages/apps/client/src/lib/triggers/triggerHandlers/TriggerHandler.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { EventEmitter } from 'eventemitter3' | ||
import { AnyTriggerAction } from '../triggerActions' | ||
import { TriggerConfig } from '../triggerConfig.ts' | ||
|
||
export interface TriggerHandlerEvents { | ||
action: [action: AnyTriggerAction] | ||
|
||
requestXkeysAccess: [] | ||
requestStreamdeckAccess: [] | ||
requestSpacemouseAccess: [] | ||
} | ||
|
||
export abstract class TriggerHandler extends EventEmitter<TriggerHandlerEvents> { | ||
protected triggers: TriggerConfig[] = [] | ||
abstract initialize(triggers?: TriggerConfig[]): Promise<void> | ||
abstract destroy(): Promise<void> | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/apps/client/src/lib/triggers/triggerHandlers/TriggerHandlerKeyboard.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Sorensen from '@sofie-automation/sorensen' | ||
import { TriggerHandler } from './TriggerHandler' | ||
import { TriggerConfig, TriggerConfigType } from '../triggerConfig' | ||
|
||
export class TriggerHandlerKeyboard extends TriggerHandler { | ||
async initialize(triggers?: TriggerConfig[]): Promise<void> { | ||
if (triggers) this.triggers = triggers | ||
// hot-module-reload fix: | ||
if (!(window as any).sorensenInitialized) { | ||
;(window as any).sorensenInitialized = true | ||
await Sorensen.init() | ||
} else { | ||
await Sorensen.destroy() | ||
await Sorensen.init() | ||
} | ||
|
||
for (const trigger of this.triggers) { | ||
if (trigger.type !== TriggerConfigType.KEYBOARD) continue | ||
|
||
Sorensen.bind( | ||
trigger.keys, | ||
() => { | ||
this.emit('action', trigger.action) | ||
}, | ||
{ | ||
up: trigger.up, | ||
global: trigger.global, | ||
|
||
exclusive: true, | ||
ordered: 'modifiersFirst', | ||
preventDefaultPartials: false, | ||
preventDefaultDown: true, | ||
} | ||
) | ||
} | ||
} | ||
async destroy(): Promise<void> { | ||
Sorensen.destroy().catch((e: Error) => console.error('Sorensen.destroy', e)) | ||
} | ||
} |
Oops, something went wrong.