@@ -6,8 +6,11 @@ import fs from "fs";
6
6
import { CommandLogs , HttpLogs , Logs , Profiling } from "../../models" ;
7
7
import * as path from "path" ;
8
8
import { parseSessionFilterParams } from "../utils/common-utils" ;
9
+ import { MjpegProxy } from "mjpeg-proxy" ;
9
10
10
11
export class SessionController extends BaseController {
12
+ private static mjpegProxyCache : Map < number , any > = new Map ( ) ;
13
+
11
14
public initializeRoutes ( router : Router , config : any ) {
12
15
router . get ( "/" , this . getSessions . bind ( this ) ) ;
13
16
router . get ( "/:sessionId" , this . getSessionBySessionId . bind ( this ) ) ;
@@ -19,6 +22,7 @@ export class SessionController extends BaseController {
19
22
router . get ( "/:sessionId/logs/debug" , this . getDebugLogs . bind ( this ) ) ;
20
23
router . get ( "/:sessionId/profiling_data" , this . getProfilingData . bind ( this ) ) ;
21
24
router . get ( "/:sessionId/http_logs" , this . getHttpLogs . bind ( this ) ) ;
25
+ router . get ( "/:sessionId/live_video" , this . getVideo . bind ( this ) ) ;
22
26
}
23
27
24
28
public async getSessions ( request : Request , response : Response , next : NextFunction ) {
@@ -161,4 +165,23 @@ export class SessionController extends BaseController {
161
165
} ) ;
162
166
this . sendSuccessResponse ( response , logs ) ;
163
167
}
168
+
169
+ public async getVideo ( request : Request , response : Response , next : NextFunction ) {
170
+ let sessionId : string = request . params . sessionId ;
171
+ let session = await Session . findOne ( {
172
+ where : {
173
+ session_id : sessionId ,
174
+ } ,
175
+ } ) ;
176
+ const proxyPort = session ?. live_stream_port ;
177
+ if ( ! proxyPort ) {
178
+ return this . sendFailureResponse ( response , { message : "Live stream not available" } ) ;
179
+ }
180
+
181
+ if ( ! SessionController . mjpegProxyCache . has ( proxyPort ) ) {
182
+ const url = `${ request . protocol } ://${ request . hostname } :${ proxyPort } ` ;
183
+ SessionController . mjpegProxyCache . set ( proxyPort , new MjpegProxy ( url ) ) ;
184
+ }
185
+ SessionController . mjpegProxyCache . get ( proxyPort ) ?. proxyRequest ( request , response ) ;
186
+ }
164
187
}
0 commit comments