@@ -4,8 +4,6 @@ import 'dart:js_interop_unsafe';
44import 'dart:math' ;
55import 'dart:typed_data' ;
66
7- // ignore: deprecated_member_use
8- import 'package:js/js.dart' ;
97import 'package:web/web.dart' as web;
108import 'e2ee.keyhandler.dart' ;
119import 'e2ee.logger.dart' ;
@@ -75,7 +73,7 @@ const SLICE_LAYER_EXT = 21;
7573// 22, 23 reserved
7674
7775List <int > findNALUIndices (Uint8List stream) {
78- var result = < int > [];
76+ final result = < int > [];
7977 var start = 0 , pos = 0 , searchLength = stream.length - 2 ;
8078 while (pos < searchLength) {
8179 // skip until end of current NALU
@@ -210,15 +208,15 @@ class FrameCryptor {
210208
211209 Uint8List makeIv (
212210 {required int synchronizationSource, required int timestamp}) {
213- var iv = ByteData (IV_LENGTH );
211+ final iv = ByteData (IV_LENGTH );
214212
215213 // having to keep our own send count (similar to a picture id) is not ideal.
216214 if (sendCounts[synchronizationSource] == null ) {
217215 // Initialize with a random offset, similar to the RTP sequence number.
218216 sendCounts[synchronizationSource] = Random .secure ().nextInt (0xffff );
219217 }
220218
221- var sendCount = sendCounts[synchronizationSource] ?? 0 ;
219+ final sendCount = sendCounts[synchronizationSource] ?? 0 ;
222220
223221 iv.setUint32 (0 , synchronizationSource);
224222 iv.setUint32 (4 , timestamp);
@@ -247,9 +245,9 @@ class FrameCryptor {
247245 logger.info ('setting codec on cryptor to $codec ' );
248246 this .codec = codec;
249247 }
250- var transformer = web.TransformStream ({
248+ final transformer = web.TransformStream ({
251249 'transform' :
252- allowInterop (operation == 'encode' ? encodeFunction : decodeFunction)
250+ (operation == 'encode' ? encodeFunction.toJS : decodeFunction.toJS )
253251 }.jsify () as JSObject );
254252 try {
255253 readable
@@ -283,9 +281,9 @@ class FrameCryptor {
283281 }
284282
285283 if (codec != null && codec.toLowerCase () == 'h264' ) {
286- var naluIndices = findNALUIndices (data);
284+ final naluIndices = findNALUIndices (data);
287285 for (var index in naluIndices) {
288- var type = parseNALUType (data[index]);
286+ final type = parseNALUType (data[index]);
289287 switch (type) {
290288 case SLICE_IDR :
291289 case SLICE_NON_IDR :
@@ -364,7 +362,7 @@ class FrameCryptor {
364362 controller.enqueue (frameObj);
365363 }
366364
367- Future < void > encodeFunction (
365+ void encodeFunction (
368366 JSObject frameObj,
369367 web.TransformStreamDefaultController controller,
370368 ) async {
@@ -382,13 +380,13 @@ class FrameCryptor {
382380 return ;
383381 }
384382
385- var srcFrame = readFrameInfo (frameObj);
383+ final srcFrame = readFrameInfo (frameObj);
386384
387385 logger.fine (
388386 'encodeFunction: buffer ${srcFrame .buffer .length }, synchronizationSource ${srcFrame .ssrc } frameType ${srcFrame .frameType }' );
389387
390- var secretKey = keyHandler.getKeySet (currentKeyIndex)? .encryptionKey;
391- var keyIndex = currentKeyIndex;
388+ final secretKey = keyHandler.getKeySet (currentKeyIndex)? .encryptionKey;
389+ final keyIndex = currentKeyIndex;
392390
393391 if (secretKey == null ) {
394392 if (lastError != CryptorError .kMissingKey) {
@@ -406,17 +404,17 @@ class FrameCryptor {
406404 return ;
407405 }
408406
409- var headerLength =
407+ final headerLength =
410408 kind == 'video' ? getUnencryptedBytes (frameObj, codec) : 1 ;
411409
412- var iv = makeIv (
410+ final iv = makeIv (
413411 synchronizationSource: srcFrame.ssrc, timestamp: srcFrame.timestamp);
414412
415- var frameTrailer = ByteData (2 );
413+ final frameTrailer = ByteData (2 );
416414 frameTrailer.setInt8 (0 , IV_LENGTH );
417415 frameTrailer.setInt8 (1 , keyIndex);
418416
419- var cipherText = await worker.crypto.subtle
417+ final cipherText = await worker.crypto.subtle
420418 .encrypt (
421419 {
422420 'name' : 'AES-GCM' ,
@@ -430,7 +428,7 @@ class FrameCryptor {
430428
431429 logger.finer (
432430 'encodeFunction: encrypted buffer: ${srcFrame .buffer .length }, cipherText: ${cipherText .toDart .asUint8List ().length }' );
433- var finalBuffer = BytesBuilder ();
431+ final finalBuffer = BytesBuilder ();
434432
435433 finalBuffer
436434 .add (Uint8List .fromList (srcFrame.buffer.sublist (0 , headerLength)));
@@ -472,11 +470,11 @@ class FrameCryptor {
472470 }
473471 }
474472
475- Future < void > decodeFunction (
473+ void decodeFunction (
476474 JSObject frameObj,
477475 web.TransformStreamDefaultController controller,
478476 ) async {
479- var srcFrame = readFrameInfo (frameObj);
477+ final srcFrame = readFrameInfo (frameObj);
480478 var ratchetCount = 0 ;
481479
482480 logger.fine ('decodeFunction: frame lenght ${srcFrame .buffer .length }' );
@@ -497,21 +495,21 @@ class FrameCryptor {
497495 }
498496
499497 if (keyOptions.uncryptedMagicBytes != null ) {
500- var magicBytes = keyOptions.uncryptedMagicBytes! ;
498+ final magicBytes = keyOptions.uncryptedMagicBytes! ;
501499 if (srcFrame.buffer.length > magicBytes.length + 1 ) {
502- var magicBytesBuffer = srcFrame.buffer.sublist (
500+ final magicBytesBuffer = srcFrame.buffer.sublist (
503501 srcFrame.buffer.length - magicBytes.length - 1 ,
504502 srcFrame.buffer.length - 1 );
505503 logger.finer (
506504 'magicBytesBuffer $magicBytesBuffer , magicBytes $magicBytes ' );
507505 if (magicBytesBuffer.toString () == magicBytes.toString ()) {
508506 sifGuard.recordSif ();
509507 if (sifGuard.isSifAllowed ()) {
510- var frameType =
508+ final frameType =
511509 srcFrame.buffer.sublist (srcFrame.buffer.length - 1 )[0 ];
512510 logger
513511 .finer ('ecodeFunction: skip uncrypted frame, type $frameType ' );
514- var finalBuffer = BytesBuilder ();
512+ final finalBuffer = BytesBuilder ();
515513 finalBuffer.add (Uint8List .fromList (srcFrame.buffer
516514 .sublist (0 , srcFrame.buffer.length - (magicBytes.length + 1 ))));
517515 enqueueFrame (frameObj, controller, finalBuffer);
@@ -530,13 +528,13 @@ class FrameCryptor {
530528 }
531529
532530 try {
533- var headerLength =
531+ final headerLength =
534532 kind == 'video' ? getUnencryptedBytes (frameObj, codec) : 1 ;
535533
536- var frameTrailer = srcFrame.buffer.sublist (srcFrame.buffer.length - 2 );
537- var ivLength = frameTrailer[0 ];
538- var keyIndex = frameTrailer[1 ];
539- var iv = srcFrame.buffer.sublist (
534+ final frameTrailer = srcFrame.buffer.sublist (srcFrame.buffer.length - 2 );
535+ final ivLength = frameTrailer[0 ];
536+ final keyIndex = frameTrailer[1 ];
537+ final iv = srcFrame.buffer.sublist (
540538 srcFrame.buffer.length - ivLength - 2 , srcFrame.buffer.length - 2 );
541539
542540 initialKeySet = keyHandler.getKeySet (keyIndex);
@@ -627,9 +625,9 @@ class FrameCryptor {
627625 throw Exception ('[ratchedKeyInternal] cannot ratchet anymore' );
628626 }
629627
630- var newKeyBuffer = await keyHandler.ratchet (
628+ final newKeyBuffer = await keyHandler.ratchet (
631629 currentkeySet.material, keyOptions.ratchetSalt);
632- var newMaterial = await keyHandler.ratchetMaterial (
630+ final newMaterial = await keyHandler.ratchetMaterial (
633631 currentkeySet.material, newKeyBuffer.buffer);
634632 currentkeySet =
635633 await keyHandler.deriveKeys (newMaterial, keyOptions.ratchetSalt);
@@ -659,7 +657,7 @@ class FrameCryptor {
659657 logger.finer (
660658 'decodeFunction: decryption success, buffer length ${srcFrame .buffer .length }, decrypted: ${decrypted !.asUint8List ().length }' );
661659
662- var finalBuffer = BytesBuilder ();
660+ final finalBuffer = BytesBuilder ();
663661
664662 finalBuffer
665663 .add (Uint8List .fromList (srcFrame.buffer.sublist (0 , headerLength)));
0 commit comments