-
Notifications
You must be signed in to change notification settings - Fork 8
/
ClientSystem.ts
46 lines (39 loc) · 1.35 KB
/
ClientSystem.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { setSoundFunction } from '@xrengine/client-core/src/components/MediaIconsBox/index.tsx'
import { isBot } from '@xrengine/engine/src/common/functions/isBot.ts'
import { isClient } from '@xrengine/engine/src/common/functions/isClient'
import { Engine } from '@xrengine/engine/src/ecs/classes/Engine'
import { World } from '@xrengine/engine/src/ecs/classes/World'
import { startLipsyncTracking, stopLipsyncTracking } from '@xrengine/engine/src/input/functions/WebcamInput'
import singleton from './speechUtils'
let recording: boolean = false
window.onbeforeunload = () => {
if (recording && !singleton.getInstance().streamStreaming) {
singleton.getInstance().socket?.emit('endGoogleCloudStream', '')
}
}
export default async function ClientSystem(world: World) {
console.log('init client system, isClient:', isClient)
if (!isClient) {
return
}
setSoundFunction(async (on: boolean) => {
recording = on
console.log('setSoundFunction', on)
if (on === true) {
if (!isBot(window) && !Engine.isBot) {
singleton.getInstance().initRecording(async (text) => {
console.log(text)
})
}
startLipsyncTracking()
} else {
if (!isBot(window) && !Engine.isBot) {
singleton.getInstance().stopRecording()
}
stopLipsyncTracking()
}
})
return () => {
return world
}
}