Skip to content

Commit 5297005

Browse files
author
Till
authored
Merge pull request #102 from one-click-studio/95-osc-when-not-on-the-same-computer-ko
95 osc when not on the same computer ko
2 parents b30f4b1 + bbc035f commit 5297005

File tree

8 files changed

+177
-74
lines changed

8 files changed

+177
-74
lines changed

nodemon.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"watch": ["src"],
33
"ext": ".ts,.js",
4-
"ignore": ["src/tests/*"],
5-
"exec": "npm run preview"
4+
"ignore": ["src/render/dist"],
5+
"exec": "DEBUG=true npm run preview -- -- -- --no-auto-open"
66
}

package-lock.json

Lines changed: 35 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"build:server": "tsc && shx cp -R ./src/resources ./build/resources",
1616
"build:client": "npm --prefix ./src/render run build && shx mkdir -p ./build/render/dist && shx cp -R ./src/render/dist ./build/render",
1717
"clean": "shx rm -rf ./out && shx rm -rf ./build && shx rm -rf ./dist && shx rm -rf ./*-dist",
18+
"dev": "nodemon",
1819
"preview": "npm run build && npm run electron:start",
1920
"test": "ts-node ./src/tests/audio.ts --no-auto-open --debug",
2021
"electron:start": "electron-forge start",
@@ -29,8 +30,8 @@
2930
"electron-squirrel-startup": "^1.0.0",
3031
"fast-xml-parser": "^4.2.0",
3132
"finalhandler": "^1.2.0",
33+
"node-osc": "^9.1.0",
3234
"obs-websocket-js": "^5.0.2",
33-
"osc-js": "^2.4.0",
3435
"rxjs": "^7.8.0",
3536
"serve-static": "^1.15.0",
3637
"simple-json-db": "^2.0.0",
@@ -47,6 +48,7 @@
4748
"@types/deep-eql": "^4.0.0",
4849
"@types/finalhandler": "^1.2.0",
4950
"@types/node": "^18.13.0",
51+
"@types/node-osc": "^6.0.3",
5052
"@types/serve-static": "^1.15.0",
5153
"@types/wav": "^1.0.1",
5254
"concurrently": "^7.6.0",

pnpm-lock.yaml

Lines changed: 27 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/app.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getLogger, type Logger } from './utils/logger'
1313
import { Gabin } from './modules/gabin'
1414
import { Profiles } from './modules/profiles'
1515
import { Setup, getAllAudioDevices } from './modules/setup'
16-
import { OscServer } from './servers/OscServer'
16+
import { OscServer, RegisterType } from './servers/OscServer'
1717

1818
import db from './utils/db'
1919
import { Profile, Connection, Asset, MicId, Thresholds, AudioDevice } from '../types/protocol'
@@ -230,6 +230,23 @@ export class App {
230230
this.osc?.register$.next({ type: request.type, data: getAllAudioDevices() })
231231
} else if (request.type === 'isReady') {
232232
this.osc?.register$.next({ type: request.type, data: true })
233+
} else if (request.type === 'register') {
234+
const type = request.data as RegisterType
235+
switch (type) {
236+
case 'shot':
237+
const shot = this.gabin?.shoot$.getValue()
238+
if (!shot) return
239+
this.osc?.register$.next({ type: type, data: shot.shot.name })
240+
break
241+
case 'autocam':
242+
const autocam = Boolean(this.gabin?.autocam$.getValue())
243+
this.osc?.register$.next({ type: type, data: JSON.stringify(autocam) })
244+
break
245+
case 'mics':
246+
const mics = this.gabin?.availableMics$.getValue()
247+
if (mics) this.osc?.register$.next({ type: type, data: JSON.stringify(Object.fromEntries(mics)) })
248+
break
249+
}
233250
}
234251
})
235252
}
@@ -364,6 +381,7 @@ export class App {
364381
this.io?.emit('handlePower', p)
365382
})
366383
this.gabin.shoot$.subscribe((shoot) => {
384+
if (!shoot) return
367385
this.io?.to(IO_ROOMS.GABIN).emit('handleNewShot', shoot)
368386
this.osc?.register$.next({ type: 'shot', data: shoot.shot.name })
369387
})
@@ -379,6 +397,7 @@ export class App {
379397
})
380398
this.gabin.availableMics$.subscribe((availableMics) => {
381399
this.io?.to(IO_ROOMS.GABIN).emit('handleAvailableMics', Object.fromEntries(availableMics))
400+
this.osc?.register$.next({ type: 'mics', data: JSON.stringify(Object.fromEntries(availableMics)) })
382401
})
383402
this.gabin.connections$.subscribe((c) => {
384403
this.io?.to(IO_ROOMS.GABIN).emit('handleObsConnected', c.obs)

src/main/clients/OSCClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ export class OscClient extends Client {
5959
}
6060

6161
private addCommands() {
62-
this.osc.on('/scene/*', (message: any) => {
62+
this.osc.on('/scene/.*', (message: any) => {
6363
const scene = message.address.split('/').pop()
6464
this.sceneTransition(scene)
6565
})
66-
this.osc.on('/source/*', (message: any) => {
66+
this.osc.on('/source/.*', (message: any) => {
6767
const source = message.address.split('/').pop()
6868
this.sourceTrigger(source)
6969
})
70-
this.osc.on('/mic/*', (message: any) => {
70+
this.osc.on('/mic/.*', (message: any) => {
7171
if (!message.args.length || [0,1].indexOf(message.args[0]) === -1) return
7272

7373
const mic = message.address.split('/').pop()
@@ -90,7 +90,7 @@ export class OscClient extends Client {
9090
if (!this.config) return
9191

9292
const clientIp = this.splitIp(this.config.ip)
93-
this.osc.send(path, clientIp.port)
93+
this.osc.send(path, clientIp.port, clientIp.host)
9494
}
9595

9696
override clean() {

src/main/modules/gabin.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export class Gabin {
3939
connections$: BehaviorSubject<Connections>
4040

4141
power$: BehaviorSubject<boolean>
42-
shoot$: Subject<Shoot>
43-
autocam$: Subject<boolean>
42+
shoot$: BehaviorSubject<Shoot|undefined>
43+
autocam$: BehaviorSubject<boolean>
4444
availableMics$: BehaviorSubject<AvailableMicsMap>
4545
triggeredShot$: BehaviorSubject<Asset['source']>
4646
timeline$: BehaviorSubject<MicId>
@@ -61,8 +61,8 @@ export class Gabin {
6161
this.isReady = false
6262

6363
this.power$ = new BehaviorSubject<boolean>(false)
64-
this.shoot$ = new Subject<Shoot>()
65-
this.autocam$ = new Subject<boolean>()
64+
this.shoot$ = new BehaviorSubject<Shoot|undefined>(undefined)
65+
this.autocam$ = new BehaviorSubject<boolean>(true)
6666
this.triggeredShot$ = new BehaviorSubject({ name: '' })
6767
this.availableMics$ = new BehaviorSubject<AvailableMicsMap>(new Map())
6868
this.timeline$ = new BehaviorSubject('')
@@ -201,7 +201,7 @@ export class Gabin {
201201
}
202202

203203
this.subscriptions.push(this.shoot$.subscribe(shoot => {
204-
if (shoot.mode === 'unhandled') return
204+
if (!shoot || shoot.mode === 'unhandled') return
205205

206206
this.logger.info('has made magic shot change ✨', `${shoot.container.name} | ${shoot.shot.name} | ${shoot.mode} mode`)
207207

0 commit comments

Comments
 (0)