Skip to content

Commit

Permalink
Merge pull request #54 from zhuhaichao518/main
Browse files Browse the repository at this point in the history
Fix build error in flutter beta channel caused by "function converted via 'toJS' contains invalid types"
  • Loading branch information
cloudwebrtc authored Dec 16, 2024
2 parents e78507f + f27d27c commit 417d866
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
18 changes: 15 additions & 3 deletions lib/src/media_stream_track_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@ import 'utils.dart';

class MediaStreamTrackWeb extends MediaStreamTrack {
MediaStreamTrackWeb(this.jsTrack) {
jsTrack.addEventListener('ended', ((event) => onEnded?.call()).toJS);
jsTrack.addEventListener('mute', ((event) => onMute?.call()).toJS);
jsTrack.addEventListener('unmute', ((event) => onUnMute?.call()).toJS);
jsTrack.addEventListener(
'ended',
(web.Event event) {
onEnded?.call();
}.toJS);
jsTrack.addEventListener(
'mute',
(web.Event event) {
onMute?.call();
}.toJS);
jsTrack.addEventListener(
'unmute',
(web.Event event) {
onUnMute?.call();
}.toJS);
}

final web.MediaStreamTrack jsTrack;
Expand Down
15 changes: 8 additions & 7 deletions lib/src/rtc_data_channel_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,32 @@ class RTCDataChannelWeb extends RTCDataChannel {
messageStream = _messageController.stream;
_jsDc.addEventListener(
'close',
(_) {
(web.Event _) {
_state = RTCDataChannelState.RTCDataChannelClosed;
_stateChangeController.add(_state);
onDataChannelState?.call(_state);
}.toJS,
false.toJS);
_jsDc.addEventListener(
'open',
(_) {
(web.Event _) {
_state = RTCDataChannelState.RTCDataChannelOpen;
_stateChangeController.add(_state);
onDataChannelState?.call(_state);
}.toJS,
false.toJS);
_jsDc.addEventListener(
'message',
(web.MessageEvent event) async {
var msg = await _parse(event.data);
_messageController.add(msg);
onMessage?.call(msg);
(web.MessageEvent event) {
_parse(event.data).then((msg) {
_messageController.add(msg);
onMessage?.call(msg);
});
}.toJS,
false.toJS);
_jsDc.addEventListener(
'bufferedamountlow',
(_) {
(web.Event _) {
onBufferedAmountLow?.call(bufferedAmount ?? 0);
}.toJS,
false.toJS);
Expand Down
12 changes: 6 additions & 6 deletions lib/src/rtc_peerconnection_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ class RTCPeerConnectionWeb extends RTCPeerConnection {
RTCPeerConnectionWeb(this._peerConnectionId, this._jsPc) {
_jsPc.addEventListener(
'datachannel',
(dataChannelEvent) {
(web.RTCDataChannelEvent dataChannelEvent) {
if (dataChannelEvent.channel != null) {
onDataChannel?.call(RTCDataChannelWeb(dataChannelEvent.channel!));
}
}.toJS);

_jsPc.addEventListener(
'icecandidate',
(iceEvent) {
(web.RTCPeerConnectionIceEvent iceEvent) {
if (iceEvent.candidate != null) {
onIceCandidate?.call(_iceFromJs(iceEvent.candidate!));
}
}.toJS);

_jsPc.addEventListener(
'iceconnectionstatechange',
(_) {
(web.Event _) {
_iceConnectionState =
iceConnectionStateForString(_jsPc.iceConnectionState);
onIceConnectionState?.call(_iceConnectionState!);
Expand Down Expand Up @@ -88,15 +88,15 @@ class RTCPeerConnectionWeb extends RTCPeerConnection {

_jsPc.addEventListener(
'signalingstatechange',
(_) {
(web.Event _) {
_signalingState = signalingStateForString(_jsPc.signalingState);
onSignalingState?.call(_signalingState!);
}.toJS);

if (!browser.isFirefox) {
_jsPc.addEventListener(
'connectionstatechange',
(_) {
(web.Event _) {
_connectionState =
peerConnectionStateForString(_jsPc.connectionState);
onConnectionState?.call(_connectionState!);
Expand All @@ -105,7 +105,7 @@ class RTCPeerConnectionWeb extends RTCPeerConnection {

_jsPc.addEventListener(
'negotiationneeded',
(_) {
(web.Event _) {
onRenegotiationNeeded?.call();
}.toJS);

Expand Down

0 comments on commit 417d866

Please sign in to comment.