Skip to content

Commit

Permalink
Fixed iOS crash with texture view (#1649)
Browse files Browse the repository at this point in the history
  • Loading branch information
Decoder07 authored Dec 3, 2023
1 parent c599d8a commit 1a772cb
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 60 deletions.
2 changes: 1 addition & 1 deletion packages/hms_room_kit/lib/src/meeting/meeting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ class MeetingStore extends ChangeNotifier

@override
void onHMSError({required HMSException error}) {
log("onHMSError-> error: ${error.code} ${error.message}");
log("onHMSError-> error: ${error.code?.errorCode} ${error.message}");
hmsException = error;
Utilities.showNotification(error.message ?? "", "error");
notifyListeners();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,21 @@ class _ScreenshareGridLayoutState extends State<ScreenshareGridLayout> {
Selector<MeetingStore, int>(
selector: (_, meetingStore) => meetingStore.currentPage,
builder: (_, currentPage, __) {
int dotsCount = (((widget.peerTracks.length -
widget.screenshareCount) ~/
2) +
(widget.peerTracks.length -
widget.screenshareCount) %
2);
return Padding(
padding: const EdgeInsets.only(top: 8.0),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DotsIndicator(
mainAxisSize: MainAxisSize.min,
dotsCount: (((widget.peerTracks.length -
widget.screenshareCount) ~/
2) +
(widget.peerTracks.length -
widget.screenshareCount) %
2),
position: currentPage,
dotsCount: dotsCount,
position:
currentPage > dotsCount ? 0 : currentPage,
decorator: DotsDecorator(
activeColor:
HMSThemeColors.onSurfaceHighEmphasis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class _CustomOneToOneGridState extends State<CustomOneToOneGrid> {
scrollDirection: Axis.horizontal,
child: DotsIndicator(
dotsCount: pageCount,
position: currentPage,
position:
currentPage > pageCount ? 0 : currentPage,
decorator: DotsDecorator(
activeColor:
HMSThemeColors.onSurfaceHighEmphasis,
Expand Down
26 changes: 16 additions & 10 deletions packages/hmssdk_flutter/lib/src/ui/meeting/hms_texture_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,18 @@ class _PlatformViewState extends State<_PlatformView> {
void initState() {
///If controller is null, then we create a new controller
///else we use the controller provided by the app.
if (widget.controller == null) {
viewController =
HMSTextureViewController(track: widget.track as HMSVideoTrack);
} else {
viewController = widget.controller;
/// (Android Only)
if (Platform.isAndroid) {
if (widget.controller == null) {
viewController =
HMSTextureViewController(track: widget.track as HMSVideoTrack);
} else {
viewController = widget.controller;
}

///Here we set the callback method which gets called to set the view
viewController?.setCallbackMethod(setView);
}

///Here we set the callback method which gets called to set the view
viewController?.setCallbackMethod(setView);
super.initState();
}

Expand All @@ -141,8 +144,11 @@ class _PlatformViewState extends State<_PlatformView> {
///
///Note that if the controller is created from app
///then the application needs to call this method explicitly.
if (widget.controller == null) {
viewController?.disposeTextureView();
/// (Android Only)
if (Platform.isAndroid) {
if (widget.controller == null) {
viewController?.disposeTextureView();
}
}
super.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
///Dart imports
import 'dart:io';

///Package imports
import 'package:flutter/services.dart';

Expand All @@ -6,6 +9,7 @@ import 'package:hmssdk_flutter/hmssdk_flutter.dart';
import 'package:hmssdk_flutter/src/enum/hms_video_view_event.dart';
import 'package:hmssdk_flutter/src/service/platform_service.dart';

/// (Android Only)
///[HMSTextureViewController] is used to control the video view. It helps in controlling addTrack, removeTrack functionalities manually.
///It is useful in custom usecases where you wish to control the addTrack and removeTrack functionalities on your own.
///Please note that if you control the view creation, addTrack etc. on application, then application has the responsibility
Expand Down Expand Up @@ -40,6 +44,7 @@ class HMSTextureViewController {
disableAutoSimulcastLayerSelect: disableAutoSimulcastLayerSelect);
}

/// (Android Only)
///[createTextureView] is used to create the texture view. It takes [track] as an optional parameter.
///If [track] is provided, then it will add the track to the texture view by default.
///If [addTrackByDefault] is set to true, then it will add the track to the texture view by default.
Expand All @@ -48,81 +53,101 @@ class HMSTextureViewController {
{HMSTrack? track,
bool addTrackByDefault = true,
bool? disableAutoSimulcastLayerSelect}) async {
var result = await PlatformService.invokeMethod(
PlatformMethod.createTextureView,
arguments: {
"track_id": track?.trackId,
"add_track_by_def": addTrackByDefault,
"disable_auto_simulcast_layer_select":
disableAutoSimulcastLayerSelect ?? false
});
if (result["success"]) {
_textureId = result["data"]["texture_id"];
EventChannel('HMSTextureView/Texture/$textureId')
.receiveBroadcastStream()
.listen(_eventListener);
if (_updateViewCallback != null) {
_updateViewCallback!();
if (Platform.isAndroid) {
var result = await PlatformService.invokeMethod(
PlatformMethod.createTextureView,
arguments: {
"track_id": track?.trackId,
"add_track_by_def": addTrackByDefault,
"disable_auto_simulcast_layer_select":
disableAutoSimulcastLayerSelect ?? false
});
if (result["success"]) {
_textureId = result["data"]["texture_id"];
EventChannel('HMSTextureView/Texture/$textureId')
.receiveBroadcastStream()
.listen(_eventListener);
if (_updateViewCallback != null) {
_updateViewCallback!();
}
}
}
}

/// (Android Only)
///[setCallbackMethod] is used to set the callback method for the texture view.
///This callback method is used to refresh the view when certain properties of the view changes.
void setCallbackMethod(Function callback) {
_updateViewCallback = callback;
if (Platform.isAndroid) {
_updateViewCallback = callback;
}
}

/// (Android Only)
///[disposeTextureView] is used to dispose the texture view.
///It is the responsibility of the application to dispose the texture view if the controller is created
///by the application.
void disposeTextureView() async {
var result = await PlatformService.invokeMethod(
PlatformMethod.disposeTextureView,
arguments: {"texture_id": textureId.toString()});
if (result["success"]) {
_textureId = null;
if (Platform.isAndroid) {
var result = await PlatformService.invokeMethod(
PlatformMethod.disposeTextureView,
arguments: {"texture_id": textureId.toString()});
if (result["success"]) {
_textureId = null;
}
}
}

/// (Android Only)
///[addTrack] is used to add the track to the texture view.
///If [disableAutoSimulcastLayerSelect] is set to true, then it will disable the auto simulcast layer selection.
void addTrack(
{required HMSVideoTrack track,
bool? disableAutoSimulcastLayerSelect}) async {
await PlatformService.invokeMethod(PlatformMethod.addTrack, arguments: {
"track_id": track.trackId,
"texture_id": textureId.toString(),
"disable_auto_simulcast_layer_select":
disableAutoSimulcastLayerSelect ?? false,
"height": _height,
"width": _width
});
if (Platform.isAndroid) {
await PlatformService.invokeMethod(PlatformMethod.addTrack, arguments: {
"track_id": track.trackId,
"texture_id": textureId.toString(),
"disable_auto_simulcast_layer_select":
disableAutoSimulcastLayerSelect ?? false,
"height": _height,
"width": _width
});
}
}

/// (Android Only)
///[_setDisplayResolution] is used to set the display resolution of the texture view.
///It is used internally by the SDK.
void _setDisplayResolution({required int height, required int width}) {
PlatformService.invokeMethod(PlatformMethod.setDisplayResolution,
arguments: {
"texture_id": textureId.toString(),
"height": height,
"width": width
});
if (Platform.isAndroid) {
PlatformService.invokeMethod(PlatformMethod.setDisplayResolution,
arguments: {
"texture_id": textureId.toString(),
"height": height,
"width": width
});
}
}

/// (Android Only)
///[removeTrack] is used to remove the track from the texture view.
void removeTrack() {
PlatformService.invokeMethod(PlatformMethod.removeTrack,
arguments: {"texture_id": textureId.toString()});
if (Platform.isAndroid) {
PlatformService.invokeMethod(PlatformMethod.removeTrack,
arguments: {"texture_id": textureId.toString()});
}
}

/// (Android Only)
///[setHeightWidth] is used to set the height and width of the texture view.
void setHeightWidth({required double height, required double width}) {
if (_height != height.toInt() || _width != width.toInt()) {
_height = height.toInt();
_width = width.toInt();
_setDisplayResolution(height: _height!, width: _width!);
if (Platform.isAndroid) {
if (_height != height.toInt() || _width != width.toInt()) {
_height = height.toInt();
_width = width.toInt();
_setDisplayResolution(height: _height!, width: _width!);
}
}
}

Expand Down

0 comments on commit 1a772cb

Please sign in to comment.