Skip to content

Commit

Permalink
fix wasm blocking issues
Browse files Browse the repository at this point in the history
  • Loading branch information
timu-jesse-ezell committed Sep 21, 2024
1 parent 14d7c30 commit 55c1df5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 108 deletions.
2 changes: 1 addition & 1 deletion example/lib/widgets/controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class _ControlsWidgetState extends State<ControlsWidget> {
const androidConfig = FlutterBackgroundAndroidConfig(
notificationTitle: 'Screen Sharing',
notificationText: 'LiveKit Example is sharing the screen.',
notificationImportance: AndroidNotificationImportance.normal,
notificationImportance: AndroidNotificationImportance.Default,
notificationIcon: AndroidResource(
name: 'livekit_ic_launcher', defType: 'mipmap'),
);
Expand Down
10 changes: 7 additions & 3 deletions lib/src/support/websocket/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import 'dart:async';
import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import 'package:web/web.dart' as web;

import 'dart:typed_data';
Expand Down Expand Up @@ -46,8 +47,9 @@ class LiveKitWebSocketWeb extends LiveKitWebSocket {
logger.warning('$objectId already disposed, ignoring received data.');
return;
}
dynamic data =
_.data is ByteBuffer ? (_.data as ByteBuffer).asUint8List() : _.data;
dynamic data = _.data.instanceOfString('ArrayBuffer')
? (_.data as JSArrayBuffer).toDart.asUint8List()
: _.data;
options?.onData?.call(data);
});
_closeSubscription = _ws.onClose.listen((_) async {
Expand All @@ -64,7 +66,9 @@ class LiveKitWebSocketWeb extends LiveKitWebSocket {
}

@override
void send(List<int> data) => _ws.send(Uint8List.fromList(data).toJS);
void send(List<int> data) {
_ws.send(Uint8List.fromList(data).toJS);
}

static Future<LiveKitWebSocketWeb> connect(
Uri uri, [
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.2.5"
watcher:
dependency: transitive
description:
Expand Down
104 changes: 4 additions & 100 deletions web/crypto.dart
Original file line number Diff line number Diff line change
@@ -1,109 +1,13 @@
// Copyright 2024 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
import 'dart:async';
import 'dart:js_util' as jsutil;
import 'dart:js_interop';
import 'dart:typed_data';

import 'package:js/js.dart';
import 'package:web/web.dart' as web;
@JS('Promise')
class Promise<T> {
external factory Promise._();
}
@JS('Algorithm')
class Algorithm {
external String get name;
}
@JS('crypto.subtle.encrypt')
external Promise<ByteBuffer> encrypt(
dynamic algorithm,
web.CryptoKey key,
ByteBuffer data,
);
@JS('crypto.subtle.decrypt')
external Promise<ByteBuffer> decrypt(
dynamic algorithm,
web.CryptoKey key,
ByteBuffer data,
);
@JS()
@anonymous
class AesGcmParams {
external factory AesGcmParams({
required String name,
required ByteBuffer iv,
ByteBuffer? additionalData,
int tagLength = 128,
});
}
ByteBuffer jsArrayBufferFrom(List<int> data) {
JSArrayBuffer jsArrayBufferFrom(ByteData data) {
// Avoid copying if possible
if (data is Uint8List &&
data.offsetInBytes == 0 &&
data.lengthInBytes == data.buffer.lengthInBytes) {
return data.buffer;
return data.buffer.toJS;
}
// Copy
return Uint8List.fromList(data).buffer;
}
@JS('crypto.subtle.importKey')
external Promise<web.CryptoKey> importKey(
String format,
ByteBuffer keyData,
dynamic algorithm,
bool extractable,
List<String> keyUsages,
);
@JS('crypto.subtle.exportKey')
external Promise<ByteBuffer> exportKey(
String format,
web.CryptoKey key,
);
@JS('crypto.subtle.deriveKey')
external Promise<web.CryptoKey> deriveKey(
dynamic algorithm,
web.CryptoKey baseKey,
dynamic derivedKeyAlgorithm,
bool extractable,
List<String> keyUsages);
@JS('crypto.subtle.deriveBits')
external Promise<ByteBuffer> deriveBits(
dynamic algorithm,
web.CryptoKey baseKey,
int length,
);
Future<web.CryptoKey> impportKeyFromRawData(List<int> secretKeyData,
{required String webCryptoAlgorithm,
required List<String> keyUsages}) async {
return jsutil.promiseToFuture<web.CryptoKey>(importKey(
'raw',
jsArrayBufferFrom(secretKeyData),
jsutil.jsify({'name': webCryptoAlgorithm}),
false,
keyUsages,
));
return Uint8List.fromList(Uint8List.sublistView(data)).buffer.toJS;
}
*/
2 changes: 1 addition & 1 deletion web/e2ee.logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum LoggerLevel {
kOFF
}

final logger = Logger('VOIP E2EE.Worker');
final logger = Logger('E2EE.Worker');

/// disable logging
void disableLogging() {
Expand Down
2 changes: 1 addition & 1 deletion web/e2ee.worker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void main() async {
logger.info('Got onrtctransform event');
var transformer = (event as web.RTCTransformEvent).transformer;

transformer.handled = true;
transformer.setProperty('handled'.toJS, true.toJS);

var options = transformer.options as JSObject;
var kind = options.getProperty('kind'.toJS) as JSString;
Expand Down

0 comments on commit 55c1df5

Please sign in to comment.