Skip to content

Commit

Permalink
Merge pull request #102 from one-click-studio/95-osc-when-not-on-the-…
Browse files Browse the repository at this point in the history
…same-computer-ko

95 osc when not on the same computer ko
  • Loading branch information
tillderoquefeuil authored Feb 8, 2024
2 parents b30f4b1 + bbc035f commit 5297005
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 74 deletions.
4 changes: 2 additions & 2 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"watch": ["src"],
"ext": ".ts,.js",
"ignore": ["src/tests/*"],
"exec": "npm run preview"
"ignore": ["src/render/dist"],
"exec": "DEBUG=true npm run preview -- -- -- --no-auto-open"
}
41 changes: 35 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"build:server": "tsc && shx cp -R ./src/resources ./build/resources",
"build:client": "npm --prefix ./src/render run build && shx mkdir -p ./build/render/dist && shx cp -R ./src/render/dist ./build/render",
"clean": "shx rm -rf ./out && shx rm -rf ./build && shx rm -rf ./dist && shx rm -rf ./*-dist",
"dev": "nodemon",
"preview": "npm run build && npm run electron:start",
"test": "ts-node ./src/tests/audio.ts --no-auto-open --debug",
"electron:start": "electron-forge start",
Expand All @@ -29,8 +30,8 @@
"electron-squirrel-startup": "^1.0.0",
"fast-xml-parser": "^4.2.0",
"finalhandler": "^1.2.0",
"node-osc": "^9.1.0",
"obs-websocket-js": "^5.0.2",
"osc-js": "^2.4.0",
"rxjs": "^7.8.0",
"serve-static": "^1.15.0",
"simple-json-db": "^2.0.0",
Expand All @@ -47,6 +48,7 @@
"@types/deep-eql": "^4.0.0",
"@types/finalhandler": "^1.2.0",
"@types/node": "^18.13.0",
"@types/node-osc": "^6.0.3",
"@types/serve-static": "^1.15.0",
"@types/wav": "^1.0.1",
"concurrently": "^7.6.0",
Expand Down
36 changes: 27 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getLogger, type Logger } from './utils/logger'
import { Gabin } from './modules/gabin'
import { Profiles } from './modules/profiles'
import { Setup, getAllAudioDevices } from './modules/setup'
import { OscServer } from './servers/OscServer'
import { OscServer, RegisterType } from './servers/OscServer'

import db from './utils/db'
import { Profile, Connection, Asset, MicId, Thresholds, AudioDevice } from '../types/protocol'
Expand Down Expand Up @@ -230,6 +230,23 @@ export class App {
this.osc?.register$.next({ type: request.type, data: getAllAudioDevices() })
} else if (request.type === 'isReady') {
this.osc?.register$.next({ type: request.type, data: true })
} else if (request.type === 'register') {
const type = request.data as RegisterType
switch (type) {
case 'shot':
const shot = this.gabin?.shoot$.getValue()
if (!shot) return
this.osc?.register$.next({ type: type, data: shot.shot.name })
break
case 'autocam':
const autocam = Boolean(this.gabin?.autocam$.getValue())
this.osc?.register$.next({ type: type, data: JSON.stringify(autocam) })
break
case 'mics':
const mics = this.gabin?.availableMics$.getValue()
if (mics) this.osc?.register$.next({ type: type, data: JSON.stringify(Object.fromEntries(mics)) })
break
}
}
})
}
Expand Down Expand Up @@ -364,6 +381,7 @@ export class App {
this.io?.emit('handlePower', p)
})
this.gabin.shoot$.subscribe((shoot) => {
if (!shoot) return
this.io?.to(IO_ROOMS.GABIN).emit('handleNewShot', shoot)
this.osc?.register$.next({ type: 'shot', data: shoot.shot.name })
})
Expand All @@ -379,6 +397,7 @@ export class App {
})
this.gabin.availableMics$.subscribe((availableMics) => {
this.io?.to(IO_ROOMS.GABIN).emit('handleAvailableMics', Object.fromEntries(availableMics))
this.osc?.register$.next({ type: 'mics', data: JSON.stringify(Object.fromEntries(availableMics)) })
})
this.gabin.connections$.subscribe((c) => {
this.io?.to(IO_ROOMS.GABIN).emit('handleObsConnected', c.obs)
Expand Down
8 changes: 4 additions & 4 deletions src/main/clients/OSCClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export class OscClient extends Client {
}

private addCommands() {
this.osc.on('/scene/*', (message: any) => {
this.osc.on('/scene/.*', (message: any) => {
const scene = message.address.split('/').pop()
this.sceneTransition(scene)
})
this.osc.on('/source/*', (message: any) => {
this.osc.on('/source/.*', (message: any) => {
const source = message.address.split('/').pop()
this.sourceTrigger(source)
})
this.osc.on('/mic/*', (message: any) => {
this.osc.on('/mic/.*', (message: any) => {
if (!message.args.length || [0,1].indexOf(message.args[0]) === -1) return

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

const clientIp = this.splitIp(this.config.ip)
this.osc.send(path, clientIp.port)
this.osc.send(path, clientIp.port, clientIp.host)
}

override clean() {
Expand Down
10 changes: 5 additions & 5 deletions src/main/modules/gabin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class Gabin {
connections$: BehaviorSubject<Connections>

power$: BehaviorSubject<boolean>
shoot$: Subject<Shoot>
autocam$: Subject<boolean>
shoot$: BehaviorSubject<Shoot|undefined>
autocam$: BehaviorSubject<boolean>
availableMics$: BehaviorSubject<AvailableMicsMap>
triggeredShot$: BehaviorSubject<Asset['source']>
timeline$: BehaviorSubject<MicId>
Expand All @@ -61,8 +61,8 @@ export class Gabin {
this.isReady = false

this.power$ = new BehaviorSubject<boolean>(false)
this.shoot$ = new Subject<Shoot>()
this.autocam$ = new Subject<boolean>()
this.shoot$ = new BehaviorSubject<Shoot|undefined>(undefined)
this.autocam$ = new BehaviorSubject<boolean>(true)
this.triggeredShot$ = new BehaviorSubject({ name: '' })
this.availableMics$ = new BehaviorSubject<AvailableMicsMap>(new Map())
this.timeline$ = new BehaviorSubject('')
Expand Down Expand Up @@ -201,7 +201,7 @@ export class Gabin {
}

this.subscriptions.push(this.shoot$.subscribe(shoot => {
if (shoot.mode === 'unhandled') return
if (!shoot || shoot.mode === 'unhandled') return

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

Expand Down
Loading

0 comments on commit 5297005

Please sign in to comment.