@@ -47,6 +47,10 @@ const PACKET_FLAG_KEY_FRAME = BigInt(1) << BigInt(62);
4747 */
4848interface IEmissions {
4949 frame : ( data : VideoStreamFramePacket ) => void
50+ /**
51+ * since Scrcpy v2.0 an extra event is emitted with the codec, width and height
52+ */
53+ codec : ( data : { codec : string , width : number , height : number } ) => void
5054 config : ( data : H264Configuration ) => void
5155 raw : ( data : Buffer ) => void
5256 error : ( error : Error ) => void
@@ -281,10 +285,8 @@ export default class Scrcpy extends EventEmitter {
281285 args . push ( 'app_process' ) ;
282286 args . push ( '/' ) ;
283287 args . push ( 'com.genymobile.scrcpy.Server' ) ;
284- const versionStr = this . strVersion ;
285-
286288 // first args is the expected version number
287- if ( versionStr === "02.02.00" ) {
289+ if ( this . strVersion === "02.02.00" ) {
288290 // V2.2 is the only version that expect a v prefix
289291 args . push ( "v" + this . config . version ) ;
290292 } else {
@@ -318,7 +320,7 @@ export default class Scrcpy extends EventEmitter {
318320 // args.push(`no_control=${this.config.noControl}`);
319321 }
320322
321- if ( versionStr >= "02.04.00" ) {
323+ if ( this . strVersion >= "02.04.00" ) {
322324 args . push ( `video_source=display` ) ;
323325 }
324326
@@ -349,7 +351,7 @@ export default class Scrcpy extends EventEmitter {
349351 if ( clipboardAutosync !== undefined )
350352 args . push ( `clipboard_autosync=${ clipboardAutosync } ` ) ; // default is True
351353 //if (this.config.version >= 22) {
352- if ( versionStr >= "01.22.00" ) {
354+ if ( this . strVersion >= "01.22.00" ) {
353355 const {
354356 downsizeOnError, sendDeviceMeta, sendDummyByte, rawVideoStream
355357 } = this . config ;
@@ -362,7 +364,7 @@ export default class Scrcpy extends EventEmitter {
362364 if ( rawVideoStream !== undefined )
363365 args . push ( `raw_video_stream=${ rawVideoStream } ` ) ;
364366 }
365- if ( versionStr >= "01.22.00" ) {
367+ if ( this . strVersion >= "01.22.00" ) {
366368 const { cleanup } = this . config ;
367369 if ( cleanup !== undefined )
368370 args . push ( `raw_video_stream=${ cleanup } ` ) ;
@@ -574,7 +576,6 @@ export default class Scrcpy extends EventEmitter {
574576 * get resolve once capture stop
575577 */
576578 private async startStreamWithMeta ( ) : Promise < void > {
577- const strVersion = this . strVersion ;
578579 assert ( this . videoSocket ) ;
579580 this . videoSocket . stream . pause ( ) ;
580581 await Utils . waitforReadable ( this . videoSocket , 0 , 'videoSocket header' ) ;
@@ -635,6 +636,8 @@ export default class Scrcpy extends EventEmitter {
635636 this . setCodec ( codec ) ;
636637 this . setWidth ( width ) ;
637638 this . setHeight ( height ) ;
639+
640+ this . emit ( "codec" , { codec, width, height} ) ;
638641 }
639642
640643 let pts = BigInt ( 0 ) ; // Buffer.alloc(0);
0 commit comments