Skip to content

Commit

Permalink
Merge branch 'release/240716' into 'stable'
Browse files Browse the repository at this point in the history
merge release into stable

See merge request sdk/express/zego_express_flutter_sdk!30
  • Loading branch information
javionchen committed Jul 26, 2024
2 parents 434bc7a + 4299232 commit 7e0805b
Show file tree
Hide file tree
Showing 26 changed files with 477 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,22 @@ public void onPlayerStateUpdate(String streamID, ZegoPlayerState state, int erro
sink.success(map);
}

@Override
public void onPlayerSwitched(String streamID, int errorCode) {
super.onPlayerSwitched(streamID, errorCode);
ZegoLog.log("[onPlayerSwitched] streamID: %s, errorCode: %d", streamID, errorCode);

if (guardSink()) { return; }

HashMap<String, Object> map = new HashMap<>();

map.put("method", "onPlayerSwitched");
map.put("streamID", streamID);
map.put("errorCode", errorCode);

sink.success(map);
}

@Override
public void onPlayerQualityUpdate(String streamID, ZegoPlayStreamQuality quality) {
super.onPlayerQualityUpdate(streamID, quality);
Expand Down Expand Up @@ -1416,6 +1432,19 @@ public void onScreenCaptureExceptionOccurred(ZegoScreenCaptureExceptionType exce
sink.success(map);
}

@Override
public void onScreenCaptureStart() {
super.onScreenCaptureStart();
ZegoLog.log("[onMobileScreenCaptureStart]");

if (guardSink()) { return; }

HashMap<String, Object> map = new HashMap<>();
map.put("method", "onMobileScreenCaptureStart");

sink.success(map);
}

/* Private Utils */

private ArrayList<HashMap<String, Object>> mapListFromUserList(ArrayList<ZegoUser> users) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
import im.zego.zegoexpress.constants.ZegoCameraExposureMode;
import im.zego.zegoexpress.constants.ZegoAudioVADStableStateMonitorType;
import im.zego.zegoexpress.constants.ZegoEncodeProfile;
import im.zego.zegoexpress.constants.ZegoCapabilityNegotiationType;
import im.zego.zegoexpress.constants.ZegoStreamCensorshipMode;
import im.zego.zegoexpress.constants.ZegoLowlightEnhancementMode;
import im.zego.zegoexpress.constants.ZegoVideoSourceType;
Expand Down Expand Up @@ -576,6 +577,9 @@ public static void loginRoom(MethodCall call, final Result result) {
roomConfig.isUserStatusNotify = ZegoUtils.boolValue((Boolean)configMap.get("isUserStatusNotify"));
roomConfig.maxMemberCount = ZegoUtils.intValue((Number)configMap.get("maxMemberCount"));
roomConfig.token = (String)configMap.get("token");
if (configMap.containsKey("capabilityNegotiationTypes") && configMap.get("capabilityNegotiationTypes") != null) {
roomConfig.capabilityNegotiationTypes = ZegoUtils.intValue((Number) configMap.get("capabilityNegotiationTypes"));
}

}

Expand Down Expand Up @@ -629,6 +633,9 @@ public static void switchRoom(MethodCall call, Result result) {
roomConfig.isUserStatusNotify = ZegoUtils.boolValue((Boolean)configMap.get("isUserStatusNotify"));
roomConfig.maxMemberCount = ZegoUtils.intValue((Number)configMap.get("maxMemberCount"));
roomConfig.token = (String)configMap.get("token");
if (configMap.containsKey("capabilityNegotiationTypes") && configMap.get("capabilityNegotiationTypes") != null) {
roomConfig.capabilityNegotiationTypes = ZegoUtils.intValue((Number) configMap.get("capabilityNegotiationTypes"));
}
ZegoExpressEngine.getEngine().switchRoom(fromRoomID, toRoomID, roomConfig);
} else {
ZegoExpressEngine.getEngine().switchRoom(fromRoomID, toRoomID);
Expand Down Expand Up @@ -739,6 +746,7 @@ public static void startPublishingStream(MethodCall call, Result result) {
config.roomID = (String) configMap.get("roomID");
config.forceSynchronousNetworkTime = ZegoUtils.intValue((Number)configMap.get("forceSynchronousNetworkTime"));
config.streamCensorshipMode = ZegoStreamCensorshipMode.getZegoStreamCensorshipMode(ZegoUtils.intValue((Number)configMap.get("streamCensorshipMode")));
config.codecNegotiationType = ZegoCapabilityNegotiationType.getZegoCapabilityNegotiationType(ZegoUtils.intValue((Number)configMap.get("codecNegotiationType")));
}

if (config != null) {
Expand Down Expand Up @@ -1546,6 +1554,14 @@ public static void startPlayingStream(MethodCall call, Result result) {
ZegoHttpDNSType.getZegoHttpDNSType(ZegoUtils.intValue((Number) cdnConfigMap.get("httpdns")));
playerConfig.cdnConfig = cdnConfig;
}

playerConfig.adaptiveSwitch = ZegoUtils.intValue((Number) playerConfigMap.get("adaptiveSwitch"));
ArrayList<Integer> adaptiveList = (ArrayList<Integer>)playerConfigMap.get("adaptiveTemplateIDList");
int[] adaptiveList_ = new int[adaptiveList.size()];
for (int i = 0; i < adaptiveList.size(); i++) {
adaptiveList_[i] = adaptiveList.get(i);
}
playerConfig.adaptiveTemplateIDList = adaptiveList_;
}

// Handle ZegoCanvas
Expand Down Expand Up @@ -1626,6 +1642,44 @@ public static void startPlayingStream(MethodCall call, Result result) {
result.success(null);
}

public static void switchPlayingStream(MethodCall call, Result result) {

String fromStreamID = call.argument("fromStreamID");
String toStreamID = call.argument("toStreamID");

// Handle ZegoPlayerConfig

ZegoPlayerConfig playerConfig = null;

HashMap<String, Object> playerConfigMap = call.argument("config");

if (playerConfigMap != null && !playerConfigMap.isEmpty()) {

playerConfig = new ZegoPlayerConfig();
playerConfig.resourceMode = ZegoStreamResourceMode.getZegoStreamResourceMode(ZegoUtils.intValue((Number) playerConfigMap.get("resourceMode")));
playerConfig.roomID = (String) playerConfigMap.get("roomID");
playerConfig.resourceSwitchMode = ZegoStreamResourceSwitchMode.getZegoStreamResourceSwitchMode(ZegoUtils.intValue((Number) playerConfigMap.get("resourceSwitchMode")));

HashMap<String, Object> cdnConfigMap = (HashMap<String, Object>) playerConfigMap.get("cdnConfig");
if (cdnConfigMap != null && !cdnConfigMap.isEmpty()) {

ZegoCDNConfig cdnConfig = new ZegoCDNConfig();
cdnConfig.url = (String) cdnConfigMap.get("url");
cdnConfig.authParam = (String) cdnConfigMap.get("authParam");
cdnConfig.protocol = (String) cdnConfigMap.get("protocol");
cdnConfig.quicVersion = (String) cdnConfigMap.get("quicVersion");
cdnConfig.quicConnectMode = ZegoUtils.intValue((Number) cdnConfigMap.get("quicConnectMode"));
cdnConfig.httpdns =
ZegoHttpDNSType.getZegoHttpDNSType(ZegoUtils.intValue((Number) cdnConfigMap.get("httpdns")));
playerConfig.cdnConfig = cdnConfig;
}
}

ZegoExpressEngine.getEngine().switchPlayingStream(fromStreamID, toStreamID, playerConfig);

result.success(null);
}

@SuppressWarnings("unused")
public static void stopPlayingStream(MethodCall call, Result result) {

Expand Down
8 changes: 4 additions & 4 deletions assets/ZegoExpressWebFlutterWrapper.js

Large diffs are not rendered by default.

38 changes: 26 additions & 12 deletions ios/Classes/internal/ZegoExpressEngineEventHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ - (void)onRoomStreamExtraInfoUpdate:(NSArray<ZegoStream *> *)streamList roomID:(
for (ZegoStream *stream in streamList) {
[streamListArray addObject:@{
@"user": @{
@"userID": stream.user.userID,
@"userName": stream.user.userName
@"userID": stream.user.userID == nil ? @"" : stream.user.userID,
@"userName": stream.user.userName == nil ? @"" : stream.user.userName
},
@"streamID": stream.streamID,
@"extraInfo": stream.extraInfo
Expand All @@ -343,8 +343,8 @@ - (void)onRoomExtraInfoUpdate:(NSArray<ZegoRoomExtraInfo *> *)roomExtraInfoList
@"key": info.key,
@"value": info.value,
@"updateUser": @{
@"userID": info.updateUser.userID,
@"userName": info.updateUser.userName
@"userID": info.updateUser.userID == nil ? @"" : info.updateUser.userID,
@"userName": info.updateUser.userName == nil ? @"" : info.updateUser.userName
},
@"updateTime": @(info.updateTime)
}];
Expand Down Expand Up @@ -643,6 +643,20 @@ - (void)onPlayerStateUpdate:(ZegoPlayerState)state errorCode:(int)errorCode exte
}
}

- (void)onPlayerSwitched:(int)errorCode streamID:(NSString *)streamID {
FlutterEventSink sink = _eventSink;
ZGLog(@"[onPlayerSwitched] errorCode: %d, streamID: %@", errorCode, streamID);

GUARD_SINK
if (sink) {
sink(@{
@"method": @"onPlayerSwitched",
@"streamID": streamID,
@"errorCode": @(errorCode)
});
}
}

- (void)onPlayerQualityUpdate:(ZegoPlayStreamQuality *)quality streamID:(NSString *)streamID {
FlutterEventSink sink = _eventSink;
// High frequency callbacks do not log
Expand Down Expand Up @@ -1159,8 +1173,8 @@ - (void)onIMRecvBroadcastMessage:(NSArray<ZegoBroadcastMessageInfo *> *)messageL
@"messageID": @(info.messageID),
@"sendTime": @(info.sendTime),
@"fromUser": @{
@"userID": info.fromUser.userID,
@"userName": info.fromUser.userName
@"userID": info.fromUser.userID == nil ? @"" : info.fromUser.userID,
@"userName": info.fromUser.userName == nil ? @"" : info.fromUser.userName
}
}];
}
Expand All @@ -1186,8 +1200,8 @@ - (void)onIMRecvBarrageMessage:(NSArray<ZegoBarrageMessageInfo *> *)messageList
@"messageID": info.messageID,
@"sendTime": @(info.sendTime),
@"fromUser": @{
@"userID": info.fromUser.userID,
@"userName": info.fromUser.userName
@"userID": info.fromUser.userID == nil ? @"" : info.fromUser.userID,
@"userName": info.fromUser.userName == nil ? @"" : info.fromUser.userName
}
}];
}
Expand All @@ -1210,8 +1224,8 @@ - (void)onIMRecvCustomCommand:(NSString *)command fromUser:(ZegoUser *)fromUser
@"method": @"onIMRecvCustomCommand",
@"command": command,
@"fromUser": @{
@"userID": fromUser.userID,
@"userName": fromUser.userName
@"userID": fromUser.userID == nil ? @"" : fromUser.userID,
@"userName": fromUser.userName == nil ? @"" : fromUser.userName
},
@"roomID": roomID
});
Expand All @@ -1228,8 +1242,8 @@ - (void)onRecvRoomTransparentMessage:(ZegoRoomRecvTransparentMessage *)message r
@"method": @"onRecvRoomTransparentMessage",
@"message": @{
@"sendUser": @{
@"userID": message.sendUser.userID,
@"userName": message.sendUser.userName
@"userID": message.sendUser.userID == nil ? @"" : message.sendUser.userID,
@"userName": message.sendUser.userName == nil ? @"" : message.sendUser.userName
},
@"content": message.content
},
Expand Down
54 changes: 52 additions & 2 deletions ios/Classes/internal/ZegoExpressEngineMethodHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ - (void)unInit {

// Uninit texture renderer
if (!self.enablePlatformView) {
[[ZegoTextureRendererController sharedInstance] uninitController];
[[ZegoTextureRendererController sharedInstance] uninitController:true];
}
}

Expand Down Expand Up @@ -209,7 +209,7 @@ - (void)destroyEngine:(FlutterMethodCall *)call result:(FlutterResult)result {

// Uninit texture renderer
if (!self.enablePlatformView) {
[[ZegoTextureRendererController sharedInstance] uninitController];
[[ZegoTextureRendererController sharedInstance] uninitController:false];
}

result(nil);
Expand Down Expand Up @@ -426,6 +426,9 @@ - (void)loginRoom:(FlutterMethodCall *)call result:(FlutterResult)result {
configObject.maxMemberCount = maxMemberCount;
configObject.isUserStatusNotify = isUserStatusNotify;
configObject.token = token;
if (configMap[@"capabilityNegotiationTypes"]) {
configObject.capabilityNegotiationTypes = [ZegoUtils unsignedIntValue:configMap[@"capabilityNegotiationTypes"]];
}
}

[[ZegoExpressEngine sharedEngine] loginRoom:roomID user:userObject config:configObject callback: ^(int errorCode, NSDictionary * _Nullable extendedData) {
Expand Down Expand Up @@ -504,6 +507,9 @@ - (void)switchRoom:(FlutterMethodCall *)call result:(FlutterResult)result {
configObject.maxMemberCount = maxMemberCount;
configObject.isUserStatusNotify = isUserStatusNotify;
configObject.token = token;
if (configMap[@"capabilityNegotiationTypes"]) {
configObject.capabilityNegotiationTypes = [ZegoUtils unsignedIntValue:configMap[@"capabilityNegotiationTypes"]];
}

[[ZegoExpressEngine sharedEngine] switchRoom:fromRoomID toRoomID:toRoomID config:configObject];
} else {
Expand Down Expand Up @@ -610,6 +616,7 @@ - (void)startPublishingStream:(FlutterMethodCall *)call result:(FlutterResult)re
config.roomID = configMap[@"roomID"];
config.forceSynchronousNetworkTime = [ZegoUtils intValue:configMap[@"forceSynchronousNetworkTime"]];
config.streamCensorshipMode = (ZegoStreamCensorshipMode)[ZegoUtils intValue:configMap[@"streamCensorshipMode"]];
config.codecNegotiationType = (ZegoCapabilityNegotiationType)[ZegoUtils intValue:configMap[@"codecNegotiationType"]];
}

if (config) {
Expand Down Expand Up @@ -1381,6 +1388,9 @@ - (void)startPlayingStream:(FlutterMethodCall *)call result:(FlutterResult)resul

playerConfig.cdnConfig = cdnConfig;
}

playerConfig.adaptiveSwitch = [ZegoUtils intValue:playerConfigMap[@"adaptiveSwitch"]];
playerConfig.adaptiveTemplateIDList = playerConfigMap[@"adaptiveTemplateIDList"];
}

// Handle ZegoCanvas
Expand Down Expand Up @@ -1458,6 +1468,46 @@ - (void)startPlayingStream:(FlutterMethodCall *)call result:(FlutterResult)resul
result(nil);
}

- (void)switchPlayingStream:(FlutterMethodCall *)call result:(FlutterResult)result {
// TODO: Deprecated since 1.19.0

NSString *fromStreamID = call.arguments[@"fromStreamID"];
NSString *toStreamID = call.arguments[@"toStreamID"];

// Handle ZegoPlayerConfig

ZegoPlayerConfig *playerConfig = nil;

NSDictionary *playerConfigMap = call.arguments[@"config"];

if (playerConfigMap && playerConfigMap.count > 0) {

playerConfig = [[ZegoPlayerConfig alloc] init];
playerConfig.resourceMode = (ZegoStreamResourceMode)[ZegoUtils intValue:playerConfigMap[@"resourceMode"]];
playerConfig.resourceSwitchMode = [ZegoUtils intValue:playerConfigMap[@"resourceSwitchMode"]];
playerConfig.roomID = playerConfigMap[@"roomID"];
NSDictionary * cdnConfigMap = playerConfigMap[@"cdnConfig"];

if (cdnConfigMap && cdnConfigMap.count > 0) {
ZegoCDNConfig *cdnConfig = [[ZegoCDNConfig alloc] init];
cdnConfig.url = cdnConfigMap[@"url"];
cdnConfig.authParam = cdnConfigMap[@"authParam"];
cdnConfig.protocol = cdnConfigMap[@"protocol"];
cdnConfig.quicVersion = cdnConfigMap[@"quicVersion"];
cdnConfig.quicConnectMode = [ZegoUtils intValue:cdnConfigMap[@"quicConnectMode"]];

int httpdnsIndex = [ZegoUtils intValue:cdnConfigMap[@"httpdns"]];
cdnConfig.httpdns = (ZegoHttpDNSType)httpdnsIndex;

playerConfig.cdnConfig = cdnConfig;
}
}

[[ZegoExpressEngine sharedEngine] switchPlayingStream:fromStreamID toStreamID:toStreamID config:playerConfig];

result(nil);
}

- (void)stopPlayingStream:(FlutterMethodCall *)call result:(FlutterResult)result {

NSString *streamID = call.arguments[@"streamID"];
Expand Down
6 changes: 1 addition & 5 deletions ios/Classes/internal/ZegoTextureRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ - (instancetype)initWithTextureRegistry:(id<FlutterTextureRegistry>)registry siz
return self;
}

- (void)dealloc {
[self destroy];
}

- (void)destroy {
@synchronized (self) {
if (_textureID != 0) {
if (_textureID != 0 && self.registry) {
// Release GPU Resource
[self.registry unregisterTexture:_textureID];
_textureID = 0;
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/internal/ZegoTextureRendererController.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)initControllerWithMessenger:(NSObject<FlutterBinaryMessenger> *)messenger;

/// Called when dart invoke `destroyEngine`
- (void)uninitController;
- (void)uninitController:(BOOL)exit;

/// Called when dart invoke `startPreview`
- (BOOL)bindCapturedChannel:(NSNumber *)channel withTexture:(int64_t)textureID;
Expand Down
7 changes: 6 additions & 1 deletion ios/Classes/internal/ZegoTextureRendererController.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ - (void)initControllerWithMessenger:(NSObject<FlutterBinaryMessenger> *)messenge
}
}

- (void)uninitController {
- (void)uninitController:(BOOL)exit {
if (!exit) {
[self.renderers enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull key, ZegoTextureRenderer * _Nonnull obj, BOOL * _Nonnull stop) {
[obj destroy];
}];
}
@synchronized (self) {
[self resetAllRenderFirstFrame];
[self.renderers removeAllObjects];
Expand Down
Loading

0 comments on commit 7e0805b

Please sign in to comment.