1
1
import { execSync , spawn } from "child_process" ;
2
2
3
- const LOCAL_DEPLOYMENT_PATH = "../../openvidu-local-deployment/community/docker-compose.yaml" ;
4
- const LIVEKIT_URL = "ws://localhost:7880" ;
5
- const LIVEKIT_API_KEY = "devkey" ;
6
- const LIVEKIT_API_SECRET = "secret" ;
7
-
8
- const execCommand = ( command : string ) : string => {
3
+ export const execCommand = ( command : string ) : string => {
9
4
try {
10
5
return execSync ( command ) . toString ( ) . trim ( ) ;
11
6
} catch ( error ) {
@@ -15,72 +10,32 @@ const execCommand = (command: string): string => {
15
10
}
16
11
} ;
17
12
18
- const execCommandInBackground = ( command : string , args : string [ ] ) : number | undefined => {
19
- const child = spawn ( command , args , { detached : true , stdio : "ignore" } ) ;
20
- // child.unref();
13
+ export const execCommandInBackground = ( command : string , args : string [ ] ) : number | undefined => {
14
+ const child = spawn ( command , args , { detached : true } ) ;
15
+
16
+ child . stdout . on ( "data" , ( data ) => {
17
+ console . log ( `stdout (${ command } ): ${ data } ` ) ;
18
+ } ) ;
19
+ child . stderr . on ( "data" , ( data ) => {
20
+ console . log ( `stderr (${ command } ): ${ data } ` ) ;
21
+ } ) ;
22
+ child . on ( "close" , ( code ) => {
23
+ console . log ( `child process (${ command } ) exited with code ${ code } ` ) ;
24
+ } ) ;
25
+ child . on ( "error" , ( error ) => {
26
+ console . error ( `child process (${ command } ) error: ${ error } ` ) ;
27
+ throw error ;
28
+ } ) ;
29
+
21
30
return child . pid ;
22
31
} ;
23
32
24
33
export const killProcess = ( pid : number ) => {
25
- process . kill ( - pid ) ;
34
+ process . kill ( pid ) ;
26
35
} ;
27
36
28
37
export const sleep = async ( seconds : number ) => {
29
38
return new Promise ( ( resolve ) => {
30
39
setTimeout ( resolve , seconds * 1000 ) ;
31
40
} ) ;
32
41
} ;
33
-
34
- export const startLocalDeployment = async ( ) => {
35
- console . log ( "Starting local deployment..." ) ;
36
- execCommand ( `docker compose -f ${ LOCAL_DEPLOYMENT_PATH } up -d` ) ;
37
- let statusCode : string ;
38
-
39
- // Check that container "ready-check" exited with code 0
40
- do {
41
- await sleep ( 1 ) ;
42
- statusCode = execCommand ( "docker inspect ready-check -f {{.State.Status}}:{{.State.ExitCode}}" ) ;
43
- } while ( statusCode !== "exited:0" ) ;
44
-
45
- console . log ( "Local deployment started" ) ;
46
- } ;
47
-
48
- export const stopLocalDeployment = ( ) => {
49
- console . log ( "Stopping local deployment..." ) ;
50
- execCommand ( `docker compose -f ${ LOCAL_DEPLOYMENT_PATH } down -v` ) ;
51
- } ;
52
-
53
- export const startComposeContainer = ( containerName : string ) => {
54
- console . log ( `Starting container ${ containerName } ...` ) ;
55
- execCommand ( `docker compose -f ${ LOCAL_DEPLOYMENT_PATH } start ${ containerName } ` ) ;
56
- } ;
57
-
58
- export const stopComposeContainer = ( containerName : string ) => {
59
- console . log ( `Stopping container ${ containerName } ...` ) ;
60
- execCommand ( `docker compose -f ${ LOCAL_DEPLOYMENT_PATH } stop ${ containerName } ` ) ;
61
- } ;
62
-
63
- export const joinParticipantToRoom = ( participantIdentity : string , roomName : string ) : number => {
64
- const command = "lk" ;
65
- const args = [
66
- "room" ,
67
- "join" ,
68
- "--url" ,
69
- LIVEKIT_URL ,
70
- "--api-key" ,
71
- LIVEKIT_API_KEY ,
72
- "--api-secret" ,
73
- LIVEKIT_API_SECRET ,
74
- "--publish-demo" ,
75
- "--identity" ,
76
- participantIdentity ,
77
- roomName
78
- ] ;
79
- const pid = execCommandInBackground ( command , args ) ;
80
-
81
- if ( ! pid ) {
82
- throw new Error ( "Error starting participant" ) ;
83
- }
84
-
85
- return pid ;
86
- } ;
0 commit comments