Skip to content

Commit d71a141

Browse files
committed
fix: resolve type conversion issues
1 parent 9d4ea8d commit d71a141

File tree

9 files changed

+36
-19
lines changed

9 files changed

+36
-19
lines changed

android/src/main/java/io/agora/agora_rtc_ng/AgoraRTECanvas.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public Map<String, Object> getConfigs(String canvasId) {
112112
canvas.getConfigs(config);
113113

114114
Map<String, Object> map = new HashMap<>();
115-
map.put("videoRenderMode", Constants.VideoRenderMode.getValue(config.getVideoRenderMode()));
116-
map.put("videoMirrorMode", Constants.VideoMirrorMode.getValue(config.getVideoMirrorMode()));
115+
map.put("videoRenderMode", config.getVideoRenderMode() != null ? Constants.VideoRenderMode.getValue(config.getVideoRenderMode()) : 0);
116+
map.put("videoMirrorMode", config.getVideoMirrorMode() != null ? Constants.VideoMirrorMode.getValue(config.getVideoMirrorMode()) : 0);
117117

118118
// Get crop area
119119
Rect cropArea = config.getCropArea();
@@ -151,7 +151,7 @@ public int getVideoRenderMode(String canvasId) {
151151
try {
152152
CanvasConfig config = new CanvasConfig();
153153
canvas.getConfigs(config);
154-
return Constants.VideoRenderMode.getValue(config.getVideoRenderMode());
154+
return config.getVideoRenderMode() != null ? Constants.VideoRenderMode.getValue(config.getVideoRenderMode()) : 0;
155155
} catch (RteException e) {
156156
return 0;
157157
}
@@ -176,7 +176,7 @@ public int getVideoMirrorMode(String canvasId) {
176176
try {
177177
CanvasConfig config = new CanvasConfig();
178178
canvas.getConfigs(config);
179-
return Constants.VideoMirrorMode.getValue(config.getVideoMirrorMode());
179+
return config.getVideoMirrorMode() != null ? Constants.VideoMirrorMode.getValue(config.getVideoMirrorMode()) : 0;
180180
} catch (RteException e) {
181181
return 0;
182182
}

android/src/main/java/io/agora/agora_rtc_ng/AgoraRTEPlayer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public Map<String, Object> getInfo(String playerId) {
294294
map.put("audioSampleRate", info.audioSampleRate());
295295
map.put("audioChannels", info.audioChannels());
296296
map.put("audioBitsPerSample", info.audioBitsPerSample());
297-
map.put("abrSubscriptionLayer", Constants.AbrSubscriptionLayer.getValue(info.abrSubscriptionLayer()));
297+
map.put("abrSubscriptionLayer", info.abrSubscriptionLayer() != null ? Constants.AbrSubscriptionLayer.getValue(info.abrSubscriptionLayer()) : 0);
298298
map.put("currentUrl", info.currentUrl() != null ? info.currentUrl() : "");
299299
return map;
300300
} catch (RteException e) {
@@ -403,8 +403,8 @@ public Map<String, Object> getConfigs(String playerId) {
403403
map.put("publishVolume", config.getPublishVolume());
404404
map.put("loopCount", config.getLoopCount());
405405
map.put("jsonParameter", config.getJsonParameter() != null ? config.getJsonParameter() : "");
406-
map.put("abrSubscriptionLayer", Constants.AbrSubscriptionLayer.getValue(config.getAbrSubscriptionLayer()));
407-
map.put("abrFallbackLayer", Constants.AbrFallbackLayer.getValue(config.getAbrFallbackLayer()));
406+
map.put("abrSubscriptionLayer", config.getAbrSubscriptionLayer() != null ? Constants.AbrSubscriptionLayer.getValue(config.getAbrSubscriptionLayer()) : 0);
407+
map.put("abrFallbackLayer", config.getAbrFallbackLayer() != null ? Constants.AbrFallbackLayer.getValue(config.getAbrFallbackLayer()) : 0);
408408
return map;
409409
} catch (RteException e) {
410410
return null;
@@ -781,7 +781,7 @@ public int getAbrSubscriptionLayer(String playerId) {
781781
try {
782782
PlayerConfig config = new PlayerConfig();
783783
player.getConfigs(config);
784-
return Constants.AbrSubscriptionLayer.getValue(config.getAbrSubscriptionLayer());
784+
return config.getAbrSubscriptionLayer() != null ? Constants.AbrSubscriptionLayer.getValue(config.getAbrSubscriptionLayer()) : 0;
785785
} catch (RteException e) {
786786
return 0;
787787
}
@@ -806,7 +806,7 @@ public int getAbrFallbackLayer(String playerId) {
806806
try {
807807
PlayerConfig config = new PlayerConfig();
808808
player.getConfigs(config);
809-
return Constants.AbrFallbackLayer.getValue(config.getAbrFallbackLayer());
809+
return config.getAbrFallbackLayer() != null ? Constants.AbrFallbackLayer.getValue(config.getAbrFallbackLayer()) : 0;
810810
} catch (RteException e) {
811811
return 0;
812812
}
@@ -832,7 +832,7 @@ public void onStateChanged(int oldState, int newState, Error error) {
832832
playerId,
833833
oldState,
834834
newState,
835-
error != null ? Constants.ErrorCode.getValue(error.code()) : 0,
835+
error != null && error.code() != null ? Constants.ErrorCode.getValue(error.code()) : 0,
836836
error != null ? error.message() : ""
837837
);
838838
});

android/src/main/java/io/agora/agora_rtc_ng/AgoraRteController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.os.Handler;
55
import android.os.Looper;
6+
import android.util.Log;
67
import android.view.View;
78
import io.flutter.plugin.common.MethodChannel;
89

@@ -494,7 +495,7 @@ public void playerGetStats(String playerId, PlayerGetStatsResultCallback callbac
494495
public void onResult(io.agora.rte.PlayerStats stats, Error error) {
495496
if (callback != null) {
496497
// Check if there's a real error (error != null and code != 0)
497-
if (error != null && Constants.ErrorCode.getValue(error.code()) != 0) {
498+
if (error != null && (error.code() == null || Constants.ErrorCode.getValue(error.code()) != 0)) {
498499
callback.onResult(null, error);
499500
} else if (stats != null) {
500501
// TODO: Add actual stats fields when PlayerStats API is confirmed
@@ -804,12 +805,15 @@ public boolean canvasAddView(String canvasId, View view, Map<String, Object> con
804805

805806
public boolean canvasAddView(String canvasId, long viewPtr, Map<String, Object> config) {
806807
if (rteCanvas == null || videoViewController == null) {
808+
Log.e("AgoraRteController", "canvasAddView failed: rteCanvas or videoViewController is null");
807809
return false;
808810
}
809811
View view = videoViewController.getViewByPtr(viewPtr);
810812
if (view == null) {
813+
Log.e("AgoraRteController", "canvasAddView failed: view not found for ptr " + viewPtr);
811814
return false;
812815
}
816+
Log.i("AgoraRteController", "canvasAddView success: adding view " + view + " to canvas " + canvasId);
813817
return rteCanvas.addView(canvasId, view, config);
814818
}
815819

android/src/main/java/io/agora/agora_rtc_ng/VideoViewController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ boolean deViewRef(int platformViewId) {
100100
simpleRef.deRef();
101101

102102
if (simpleRef.getRefCount() <= 0) {
103+
viewPtrToRef.remove(simpleRef.getNativeHandle());
103104
simpleRef.releaseRef();
104105
renders.remove(platformViewId);
105106
}

ios/agora_rtc_engine/Sources/agora_rtc_engine/AgoraRTE.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,15 @@ - (NSDictionary *)getConfigs:(NSError **)error {
151151
}
152152

153153
AgoraRteError *getError = [[AgoraRteError alloc] init];
154+
BOOL useStringUidValue = [config useStringUid:getError];
154155
return @{
155156
@"appId": [config appId:getError] ?: @"",
156157
@"logFolder": [config logFolder:getError] ?: @"",
157158
@"logFileSize": @([config logFileSize:getError]),
158159
@"areaCode": @([config areaCode:getError]),
159160
@"cloudProxy": [config cloudProxy:getError] ?: @"",
160161
@"jsonParameter": [config jsonParameter:getError] ?: @"",
161-
@"useStringUid": @([config useStringUid:getError] ? YES : NO)
162+
@"useStringUid": [NSNumber numberWithBool:useStringUidValue]
162163
};
163164
}
164165

ios/agora_rtc_engine/Sources/agora_rtc_engine/AgoraRTECanvas.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ - (NSDictionary *)getConfigs:(NSString *)canvasId error:(NSError **)error {
125125
AgoraRteError *getError = [[AgoraRteError alloc] init];
126126
AgoraRteRect *cropArea = [config cropArea:getError];
127127

128-
return @{
128+
NSDictionary *result = @{
129129
@"videoRenderMode": @([config videoRenderMode:getError]),
130130
@"videoMirrorMode": @([config videoMirrorMode:getError]),
131131
@"cropArea": @{
@@ -135,6 +135,7 @@ - (NSDictionary *)getConfigs:(NSString *)canvasId error:(NSError **)error {
135135
@"height": @([cropArea height])
136136
}
137137
};
138+
return result;
138139
}
139140

140141
// Individual Config Setters/Getters

ios/agora_rtc_engine/Sources/agora_rtc_engine/AgoraRTEController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ - (BOOL)useStringUid:(NSError **)error {
221221
if (error) *error = RTE_NSERROR_FROM_RTE_ERROR(getError);
222222
return NO;
223223
}
224-
return useStringUid ? YES : NO;
224+
return [NSNumber numberWithBool:useStringUid];
225225
}
226226

227227

lib/src/impl/agora_rte_canvas_impl.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,27 @@ class AgoraRteCanvasImpl implements AgoraRteCanvas {
104104

105105
@override
106106
Future<void> addView(int viewPtr, {AgoraRteViewConfig? config}) async {
107-
await _channel.invokeMethod('rteCanvasAddView', {
107+
final result = await _channel.invokeMethod<bool>('rteCanvasAddView', {
108108
'canvasId': canvasId,
109109
'viewPtr': viewPtr,
110110
'config': config?.toJson(),
111111
});
112+
if (result != true) {
113+
throw PlatformException(
114+
code: 'RTE_ERROR', message: 'Failed to add view to canvas');
115+
}
112116
}
113117

114118
@override
115119
Future<void> removeView(int viewPtr, {AgoraRteViewConfig? config}) async {
116-
await _channel.invokeMethod('rteCanvasRemoveView', {
120+
final result = await _channel.invokeMethod<bool>('rteCanvasRemoveView', {
117121
'canvasId': canvasId,
118122
'viewPtr': viewPtr,
119123
'config': config?.toJson(),
120124
});
125+
if (result != true) {
126+
throw PlatformException(
127+
code: 'RTE_ERROR', message: 'Failed to remove view from canvas');
128+
}
121129
}
122130
}

lib/src/impl/agora_rte_core_impl.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ class AgoraRteCoreImpl {
2929
AgoraRteCanvasImpl? getCanvas(String canvasId) => _canvases[canvasId];
3030

3131
Future<dynamic> _handleMethodCall(MethodCall call) async {
32-
final args = call.arguments as Map?;
32+
final args = call.arguments != null
33+
? Map<String, dynamic>.from(call.arguments)
34+
: null;
3335
final playerId = args?['playerId'] as String?;
3436
final canvasId = args?['canvasId'] as String?;
3537

@@ -98,8 +100,8 @@ class AgoraRteCoreImpl {
98100

99101
/// Get all configurations
100102
Future<AgoraRteConfig> getConfigs() async {
101-
Map<String, dynamic> result = await _channel.invokeMethod('rteGetConfigs');
102-
return AgoraRteConfig.fromJson(result);
103+
final result = await _channel.invokeMethod('rteGetConfigs');
104+
return AgoraRteConfig.fromJson(Map<String, dynamic>.from(result));
103105
}
104106

105107
/// Create player

0 commit comments

Comments
 (0)