Skip to content

Commit

Permalink
fix: web build error
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Jun 16, 2021
1 parent 6bb032d commit 8c57eae
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 40 deletions.
44 changes: 26 additions & 18 deletions example/lib/examples/advanced/screen_sharing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ class _State extends State<ScreenSharing> {
_addListeners();
() async {
await _engine.enableVideo();
await _engine.startPreview();
if (kIsWeb) {
await _engine.startScreenCapture(0);
} else {
await _engine.startPreview();
}
await _engine.setChannelProfile(ChannelProfile.LiveBroadcasting);
await _engine.setClientRole(ClientRole.Broadcaster);
setState(() {
Expand Down Expand Up @@ -179,18 +183,21 @@ class _State extends State<ScreenSharing> {
_renderVideo(),
],
),
Align(
alignment: Alignment.bottomRight,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
onPressed: screenSharing ? _stopScreenShare : _startScreenShare,
child: Text('${screenSharing ? 'Stop' : 'Start'} screen share'),
),
],
),
)
if (!kIsWeb)
Align(
alignment: Alignment.bottomRight,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
onPressed:
screenSharing ? _stopScreenShare : _startScreenShare,
child:
Text('${screenSharing ? 'Stop' : 'Start'} screen share'),
),
],
),
)
],
);
}
Expand All @@ -201,11 +208,12 @@ class _State extends State<ScreenSharing> {
children: [
Row(
children: [
Expanded(
flex: 1,
child: kIsWeb
? RtcLocalView.SurfaceView()
: RtcLocalView.TextureView()),
if (startPreview)
Expanded(
flex: 1,
child: kIsWeb
? RtcLocalView.SurfaceView()
: RtcLocalView.TextureView()),
if (screenSharing)
Expanded(flex: 1, child: RtcLocalView.TextureView.screenShare()),
],
Expand Down
9 changes: 5 additions & 4 deletions example/lib/examples/basic/join_channel_audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ class _State extends State<JoinChannelAudio> {
child:
Text(enableSpeakerphone ? 'Speakerphone' : 'Earpiece'),
),
ElevatedButton(
onPressed: this._switchEffect,
child: Text('${playEffect ? 'Stop' : 'Play'} effect'),
),
if (!kIsWeb)
ElevatedButton(
onPressed: this._switchEffect,
child: Text('${playEffect ? 'Stop' : 'Play'} effect'),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Expand Down
2 changes: 1 addition & 1 deletion example/web/AgoraRtcWrapper.bundle.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/rtc_engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export 'src/classes.dart';
export 'src/enums.dart';
export 'src/events.dart' hide RtcChannelEventHandler;
export 'src/rtc_engine.dart' show RtcEngine;
export 'src/rtc_engine_extension.dart';
export 'src/rtc_engine_extension.dart'
if (dart.library.html) 'src/rtc_engine_extension_web.dart';
30 changes: 15 additions & 15 deletions lib/src/rtc_engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2588,14 +2588,14 @@ class RtcEngine with RtcEngineInterface {

@override
Future<void> startScreenCaptureByDisplayId(int displayId,
Rectangle regionRect, ScreenCaptureParameters captureParams) {
[Rectangle? regionRect, ScreenCaptureParameters? captureParams]) {
if (!kIsWeb && (Platform.isWindows || Platform.isMacOS)) {
return _invokeMethod('callApi', {
'apiType': _ApiTypeEngine.kEngineStartScreenCaptureByDisplayId.index,
'params': jsonEncode({
'displayId': displayId,
'regionRect': regionRect.toJson(),
'captureParams': captureParams.toJson(),
'regionRect': regionRect?.toJson(),
'captureParams': captureParams?.toJson(),
}),
});
}
Expand All @@ -2604,14 +2604,14 @@ class RtcEngine with RtcEngineInterface {

@override
Future<void> startScreenCaptureByScreenRect(Rectangle screenRect,
Rectangle regionRect, ScreenCaptureParameters captureParams) {
[Rectangle? regionRect, ScreenCaptureParameters? captureParams]) {
if (!kIsWeb && (Platform.isWindows || Platform.isMacOS)) {
return _invokeMethod('callApi', {
'apiType': _ApiTypeEngine.kEngineStartScreenCaptureByScreenRect.index,
'params': jsonEncode({
'screenRect': screenRect.toJson(),
'regionRect': regionRect.toJson(),
'captureParams': captureParams.toJson(),
'regionRect': regionRect?.toJson(),
'captureParams': captureParams?.toJson(),
}),
});
}
Expand Down Expand Up @@ -2673,15 +2673,15 @@ class RtcEngine with RtcEngineInterface {
}

@override
Future<void> startScreenCapture(
int windowId, int captureFreq, Rect rect, int bitrate) {
Future<void> startScreenCapture(int windowId,
[int? captureFreq, Rect? rect, int? bitrate]) {
if (kIsWeb || (Platform.isWindows || Platform.isMacOS)) {
return _invokeMethod('callApi', {
'apiType': _ApiTypeEngine.kEngineStartScreenCapture.index,
'params': jsonEncode({
'windowId': windowId,
'captureFreq': captureFreq,
'rect': rect.toJson(),
'rect': rect?.toJson(),
'bitrate': bitrate,
}),
});
Expand Down Expand Up @@ -4702,13 +4702,13 @@ mixin RtcStreamMessageInterface {
/// TODO(doc)
mixin RtcScreenSharingInterface {
Future<void> startScreenCaptureByDisplayId(int displayId,
Rectangle regionRect, ScreenCaptureParameters captureParams);
[Rectangle? regionRect, ScreenCaptureParameters? captureParams]);

Future<void> startScreenCaptureByScreenRect(Rectangle screenRect,
Rectangle regionRect, ScreenCaptureParameters captureParams);
[Rectangle? regionRect, ScreenCaptureParameters? captureParams]);

Future<void> startScreenCaptureByWindowId(int windowId, Rectangle regionRect,
ScreenCaptureParameters captureParams);
Future<void> startScreenCaptureByWindowId(int windowId,
[Rectangle? regionRect, ScreenCaptureParameters? captureParams]);

Future<void> setScreenCaptureContentHint(VideoContentHint contentHint);

Expand All @@ -4719,6 +4719,6 @@ mixin RtcScreenSharingInterface {

Future<void> stopScreenCapture();

Future<void> startScreenCapture(
int windowId, int captureFreq, Rect rect, int bitrate);
Future<void> startScreenCapture(int windowId,
[int? captureFreq, Rect? rect, int? bitrate]);
}
23 changes: 23 additions & 0 deletions lib/src/rtc_engine_extension_web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/services.dart';

import 'enums.dart';
import 'rtc_engine.dart';

/// Extension for RtcEngine
extension RtcEngineExtension on RtcEngine {
/// Get the actual absolute path of the asset through the relative path of the asset
///
/// - [assetPath] The resource path configured in the `flutter` -> `assets` field of pubspec.yaml, for example: assets/Sound_Horizon.mp3
/// - Returns the actual absolute path of the asset
Future<String?> getAssetAbsolutePath(String assetPath) {
throw PlatformException(code: ErrorCode.NotSupported.toString());
}

List<dynamic> enumerateDisplays() {
throw PlatformException(code: ErrorCode.NotSupported.toString());
}

List<dynamic> enumerateWindows() {
throw PlatformException(code: ErrorCode.NotSupported.toString());
}
}
2 changes: 1 addition & 1 deletion web

0 comments on commit 8c57eae

Please sign in to comment.