From c68af85295e3a1f971b506fae9640a383c2a52fb Mon Sep 17 00:00:00 2001 From: "Jerry.Luo" <396912848@qq.com> Date: Tue, 18 May 2021 13:34:00 +0800 Subject: [PATCH 1/4] fix(fix): default bool value --- ios/Classes/AgoraRtmPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Classes/AgoraRtmPlugin.m b/ios/Classes/AgoraRtmPlugin.m index 34e6819..9c72ed3 100644 --- a/ios/Classes/AgoraRtmPlugin.m +++ b/ios/Classes/AgoraRtmPlugin.m @@ -438,7 +438,7 @@ -(NSString *)getString:(id)obj{ } -(BOOL)getBool:(id)obj{ if ([obj isEqual:[NSNull null]]) { - return nil; + return NO; } return obj; } From 1e2e295f67eb34cc6b51856fa847636097695155 Mon Sep 17 00:00:00 2001 From: "Bhavin.Concetto" Date: Thu, 15 Apr 2021 14:55:55 +0530 Subject: [PATCH 2/4] Commit for Null-Safety migration --- example/lib/main.dart | 69 ++++++++++++++++++--------------- example/pubspec.yaml | 2 +- lib/src/agora_rtm_channel.dart | 36 ++++++++--------- lib/src/agora_rtm_client.dart | 70 +++++++++++++++++----------------- lib/src/agora_rtm_plugin.dart | 4 +- lib/src/utils.dart | 10 ++--- pubspec.yaml | 2 +- 7 files changed, 100 insertions(+), 93 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 579cf9c..85079dc 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -22,8 +22,8 @@ class _MyAppState extends State { final _infoStrings = []; - AgoraRtmClient _client; - AgoraRtmChannel _channel; + AgoraRtmClient? _client; + AgoraRtmChannel? _channel; @override void initState() { @@ -58,16 +58,16 @@ class _MyAppState extends State { void _createClient() async { _client = await AgoraRtmClient.createInstance(YOUR_APP_ID); - _client.onMessageReceived = (AgoraRtmMessage message, String peerId) { - _log("Peer msg: " + peerId + ", msg: " + message.text); + _client?.onMessageReceived = (AgoraRtmMessage message, String peerId) { + _log("Peer msg: " + peerId + ", msg: " + (message.text??"")); }; - _client.onConnectionStateChanged = (int state, int reason) { + _client?.onConnectionStateChanged = (int state, int reason) { _log('Connection state changed: ' + state.toString() + ', reason: ' + reason.toString()); if (state == 5) { - _client.logout(); + _client?.logout(); _log('Logout.'); setState(() { _isLogin = false; @@ -76,19 +76,24 @@ class _MyAppState extends State { }; } - Future _createChannel(String name) async { - AgoraRtmChannel channel = await _client.createChannel(name); - channel.onMemberJoined = (AgoraRtmMember member) { - _log( - "Member joined: " + member.userId + ', channel: ' + member.channelId); - }; - channel.onMemberLeft = (AgoraRtmMember member) { - _log("Member left: " + member.userId + ', channel: ' + member.channelId); - }; - channel.onMessageReceived = - (AgoraRtmMessage message, AgoraRtmMember member) { - _log("Channel msg: " + member.userId + ", msg: " + message.text); - }; + Future _createChannel(String name) async { + AgoraRtmChannel? channel = await _client?.createChannel(name); + if(channel != null) { + channel.onMemberJoined = (AgoraRtmMember member) { + _log("Member joined: " + + member.userId + + ', channel: ' + + member.channelId); + }; + channel.onMemberLeft = (AgoraRtmMember member) { + _log( + "Member left: " + member.userId + ', channel: ' + member.channelId); + }; + channel.onMessageReceived = + (AgoraRtmMessage message, AgoraRtmMember member) { + _log("Channel msg: " + member.userId + ", msg: " + (message.text??"")); + }; + } return channel; } @@ -210,7 +215,7 @@ class _MyAppState extends State { void _toggleLogin() async { if (_isLogin) { try { - await _client.logout(); + await _client?.logout(); _log('Logout success.'); setState(() { @@ -228,7 +233,7 @@ class _MyAppState extends State { } try { - await _client.login(null, userId); + await _client?.login(null, userId); _log('Login success: ' + userId); setState(() { _isLogin = true; @@ -246,8 +251,8 @@ class _MyAppState extends State { return; } try { - Map result = - await _client.queryPeersOnlineStatus([peerUid]); + Map? result = + await _client?.queryPeersOnlineStatus([peerUid]); _log('Query result: ' + result.toString()); } catch (errorCode) { _log('Query error: ' + errorCode.toString()); @@ -269,8 +274,8 @@ class _MyAppState extends State { try { AgoraRtmMessage message = AgoraRtmMessage.fromText(text); - _log(message.text); - await _client.sendMessageToPeer(peerUid, message, false); + _log(message.text??"Empty"); + await _client?.sendMessageToPeer(peerUid, message, false); _log('Send peer message success.'); } catch (errorCode) { _log('Send peer message error: ' + errorCode.toString()); @@ -280,10 +285,12 @@ class _MyAppState extends State { void _toggleJoinChannel() async { if (_isInChannel) { try { - await _channel.leave(); + await _channel?.leave(); _log('Leave channel success.'); - _client.releaseChannel(_channel.channelId); - _channelMessageController.text = null; + if(_channel != null) { + _client?.releaseChannel(_channel!.channelId!); + } + _channelMessageController.clear(); setState(() { _isInChannel = false; @@ -300,7 +307,7 @@ class _MyAppState extends State { try { _channel = await _createChannel(channelId); - await _channel.join(); + await _channel?.join(); _log('Join channel success.'); setState(() { @@ -314,7 +321,7 @@ class _MyAppState extends State { void _toggleGetMembers() async { try { - List members = await _channel.getMembers(); + List? members = await _channel?.getMembers(); _log('Members: ' + members.toString()); } catch (errorCode) { _log('GetMembers failed: ' + errorCode.toString()); @@ -328,7 +335,7 @@ class _MyAppState extends State { return; } try { - await _channel.sendMessage(AgoraRtmMessage.fromText(text)); + await _channel?.sendMessage(AgoraRtmMessage.fromText(text)); _log('Send channel message success.'); } catch (errorCode) { _log('Send channel message error: ' + errorCode.toString()); diff --git a/example/pubspec.yaml b/example/pubspec.yaml index f4bb945..49fda8d 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,7 +3,7 @@ description: Demonstrates how to use the agora_rtm plugin. publish_to: 'none' environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: diff --git a/lib/src/agora_rtm_channel.dart b/lib/src/agora_rtm_channel.dart index 4350df0..949e556 100644 --- a/lib/src/agora_rtm_channel.dart +++ b/lib/src/agora_rtm_channel.dart @@ -21,30 +21,30 @@ class AgoraRtmChannelException implements Exception { class AgoraRtmChannel { /// Occurs when you receive error events. - void Function(dynamic error) onError; + void Function(dynamic error)? onError; /// Occurs when receiving a channel message. - void Function(AgoraRtmMessage message, AgoraRtmMember fromMember) + void Function(AgoraRtmMessage message, AgoraRtmMember fromMember)? onMessageReceived; /// Occurs when a user joins the channel. - void Function(AgoraRtmMember member) onMemberJoined; + void Function(AgoraRtmMember member)? onMemberJoined; /// Occurs when a channel member leaves the channel. - void Function(AgoraRtmMember member) onMemberLeft; + void Function(AgoraRtmMember member)? onMemberLeft; /// Occurs when channel attribute updated. - void Function(List attributes) onAttributesUpdated; + void Function(List attributes)? onAttributesUpdated; /// Occurs when channel member count updated. - void Function(int count) onMemberCountUpdated; + void Function(int count)? onMemberCountUpdated; - final String channelId; - final int _clientIndex; + final String? channelId; + final int? _clientIndex; - bool _closed; + bool? _closed; - StreamSubscription _eventSubscription; + StreamSubscription? _eventSubscription; EventChannel _addEventChannel() { return new EventChannel( @@ -57,26 +57,26 @@ class AgoraRtmChannel { case 'onMessageReceived': AgoraRtmMessage message = AgoraRtmMessage.fromJson(map['message']); AgoraRtmMember member = AgoraRtmMember.fromJson(map); - this?.onMessageReceived?.call(message, member); + this.onMessageReceived?.call(message, member); break; case 'onMemberJoined': AgoraRtmMember member = AgoraRtmMember.fromJson(map); - this?.onMemberJoined?.call(member); + this.onMemberJoined?.call(member); break; case 'onMemberLeft': AgoraRtmMember member = AgoraRtmMember.fromJson(map); - this?.onMemberLeft?.call(member); + this.onMemberLeft?.call(member); break; case 'onAttributesUpdated': List> attributes = List>.from(map['attributes']); - this?.onAttributesUpdated?.call(attributes + this.onAttributesUpdated?.call(attributes .map((attr) => AgoraRtmChannelAttribute.fromJson(attr)) .toList()); break; case 'onMemberCountUpdated': int count = map['count']; - this?.onMemberCountUpdated?.call(count); + this.onMemberCountUpdated?.call(count); break; } } @@ -104,7 +104,7 @@ class AgoraRtmChannel { } Future sendMessage(AgoraRtmMessage message, - [bool offline, bool historical]) async { + [bool? offline, bool? historical]) async { final res = await _callNative("sendMessage", { 'message': message.text, "offline": offline, @@ -135,8 +135,8 @@ class AgoraRtmChannel { } Future close() async { - if (_closed) return null; - await _eventSubscription.cancel(); + if (_closed??true) return null; + await _eventSubscription?.cancel(); _closed = true; } diff --git a/lib/src/agora_rtm_client.dart b/lib/src/agora_rtm_client.dart index 74053b4..75f8e8a 100644 --- a/lib/src/agora_rtm_client.dart +++ b/lib/src/agora_rtm_client.dart @@ -26,7 +26,7 @@ class AgoraRtmClient { /// Initializes an [AgoraRtmClient] instance /// /// The Agora RTM SDK supports multiple [AgoraRtmClient] instances. - static Future createInstance(String appId) async { + static Future createInstance(String appId) async { final res = await AgoraRtmPlugin.callMethodForStatic( "createInstance", {'appId': appId}); if (res["errorCode"] != 0) @@ -50,56 +50,56 @@ class AgoraRtmClient { } /// Occurs when the connection state between the SDK and the Agora RTM system changes. - void Function(int state, int reason) onConnectionStateChanged; + void Function(int state, int reason)? onConnectionStateChanged; /// Occurs when the local user receives a peer-to-peer message. - void Function(AgoraRtmMessage message, String peerId) onMessageReceived; + void Function(AgoraRtmMessage message, String peerId)? onMessageReceived; /// Occurs when your token expires. - void Function() onTokenExpired; + void Function()? onTokenExpired; /// Occurs when you receive error events. - void Function() onError; + void Function()? onError; /// Callback to the caller: occurs when the caller receives the call invitation. - void Function(AgoraRtmLocalInvitation invite) onLocalInvitationReceivedByPeer; + void Function(AgoraRtmLocalInvitation invite)? onLocalInvitationReceivedByPeer; /// Callback to the caller: occurs when the caller accepts the call invitation. - void Function(AgoraRtmLocalInvitation invite) onLocalInvitationAccepted; + void Function(AgoraRtmLocalInvitation invite)? onLocalInvitationAccepted; /// Callback to the caller: occurs when the caller declines the call invitation. - void Function(AgoraRtmLocalInvitation invite) onLocalInvitationRefused; + void Function(AgoraRtmLocalInvitation invite)? onLocalInvitationRefused; /// Callback to the caller: occurs when the caller cancels a call invitation. - void Function(AgoraRtmLocalInvitation invite) onLocalInvitationCanceled; + void Function(AgoraRtmLocalInvitation invite)? onLocalInvitationCanceled; /// Callback to the caller: occurs when the life cycle of the outgoing call invitation ends in failure. - void Function(AgoraRtmLocalInvitation invite, int errorCode) + void Function(AgoraRtmLocalInvitation invite, int errorCode)? onLocalInvitationFailure; /// Callback to the caller: occurs when the callee receives the call invitation. - void Function(AgoraRtmRemoteInvitation invite) + void Function(AgoraRtmRemoteInvitation invite)? onRemoteInvitationReceivedByPeer; /// Callback to the caller: occurs when the callee accepts the call invitation. - void Function(AgoraRtmRemoteInvitation invite) onRemoteInvitationAccepted; + void Function(AgoraRtmRemoteInvitation invite)? onRemoteInvitationAccepted; /// Callback to the caller: occurs when the callee declines the call invitation. - void Function(AgoraRtmRemoteInvitation invite) onRemoteInvitationRefused; + void Function(AgoraRtmRemoteInvitation invite)? onRemoteInvitationRefused; /// Callback to the caller: occurs when the caller cancels a call invitation. - void Function(AgoraRtmRemoteInvitation invite) onRemoteInvitationCanceled; + void Function(AgoraRtmRemoteInvitation invite)? onRemoteInvitationCanceled; /// Callback to the caller: occurs when the life cycle of the outgoing call invitation ends in failure. - void Function(AgoraRtmRemoteInvitation invite, int errorCode) + void Function(AgoraRtmRemoteInvitation invite, int errorCode)? onRemoteInvitationFailure; var _channels = {}; - bool _closed; + bool? _closed; final int _clientIndex; - StreamSubscription _clientSubscription; + StreamSubscription? _clientSubscription; EventChannel _addEventChannel(name) { return new EventChannel(name); @@ -111,63 +111,63 @@ class AgoraRtmClient { case 'onConnectionStateChanged': int state = map['state']; int reason = map['reason']; - this?.onConnectionStateChanged?.call(state, reason); + this.onConnectionStateChanged?.call(state, reason); break; case 'onMessageReceived': AgoraRtmMessage message = AgoraRtmMessage.fromJson(map["message"]); String peerId = map["peerId"]; - this?.onMessageReceived?.call(message, peerId); + this.onMessageReceived?.call(message, peerId); break; case 'onTokenExpired': - this?.onTokenExpired?.call(); + this.onTokenExpired?.call(); break; case 'onLocalInvitationReceivedByPeer': this - ?.onLocalInvitationReceivedByPeer + .onLocalInvitationReceivedByPeer ?.call(AgoraRtmLocalInvitation.fromJson(map['localInvitation'])); break; case 'onLocalInvitationAccepted': this - ?.onLocalInvitationAccepted + .onLocalInvitationAccepted ?.call(AgoraRtmLocalInvitation.fromJson(map['localInvitation'])); break; case 'onLocalInvitationRefused': this - ?.onLocalInvitationRefused + .onLocalInvitationRefused ?.call(AgoraRtmLocalInvitation.fromJson(map['localInvitation'])); break; case 'onLocalInvitationCanceled': this - ?.onLocalInvitationCanceled + .onLocalInvitationCanceled ?.call(AgoraRtmLocalInvitation.fromJson(map['localInvitation'])); break; case 'onLocalInvitationFailure': - this?.onLocalInvitationFailure?.call( + this.onLocalInvitationFailure?.call( AgoraRtmLocalInvitation.fromJson(map['localInvitation']), map['errorCode']); break; case 'onRemoteInvitationReceivedByPeer': this - ?.onRemoteInvitationReceivedByPeer + .onRemoteInvitationReceivedByPeer ?.call(AgoraRtmRemoteInvitation.fromJson(map['remoteInvitation'])); break; case 'onRemoteInvitationAccepted': this - ?.onRemoteInvitationAccepted + .onRemoteInvitationAccepted ?.call(AgoraRtmRemoteInvitation.fromJson(map['remoteInvitation'])); break; case 'onRemoteInvitationRefused': this - ?.onRemoteInvitationRefused + .onRemoteInvitationRefused ?.call(AgoraRtmRemoteInvitation.fromJson(map['remoteInvitation'])); break; case 'onRemoteInvitationCanceled': this - ?.onRemoteInvitationCanceled + .onRemoteInvitationCanceled ?.call(AgoraRtmRemoteInvitation.fromJson(map['remoteInvitation'])); break; case 'onRemoteInvitationFailure': - this?.onRemoteInvitationFailure?.call( + this.onRemoteInvitationFailure?.call( AgoraRtmRemoteInvitation.fromJson(map['remoteInvitation']), map['errorCode']); break; @@ -188,8 +188,8 @@ class AgoraRtmClient { /// Destroy and stop event to the client with related channels. Future destroy() async { - if (_closed) return null; - await _clientSubscription.cancel(); + if (_closed??true) return null; + await _clientSubscription?.cancel(); _closed = true; for (String channelId in _channels.keys) { await releaseChannel(channelId); @@ -222,7 +222,7 @@ class AgoraRtmClient { /// - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "]", "[", "^", "_", " {", "}", "|", "~", "," /// Do not set userId as null and do not start with a space. /// If you log in with the same user ID from a different instance, you will be kicked out of your previous login and removed from previously joined channels. - Future login(String token, String userId) async { + Future login(String? token, String userId) async { final res = await _callNative("login", {'token': token, 'userId': userId}); if (res["errorCode"] != 0) throw AgoraRtmClientException( @@ -259,7 +259,7 @@ class AgoraRtmClient { /// Allows a user to send a peer-to-peer message to a specific peer user. Future sendMessageToPeer(String peerId, AgoraRtmMessage message, - [bool offline, bool historical]) async { + [bool? offline, bool? historical]) async { final res = await _callNative("sendMessageToPeer", { "peerId": peerId, "message": message.text, @@ -479,7 +479,7 @@ class AgoraRtmClient { /// - Space /// - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "]", "[", "^", "_", " {", "}", "|", "~", "," /// channelId cannot be empty or set as nil. - Future createChannel(String channelId) async { + Future createChannel(String channelId) async { final res = await _callNative("createChannel", {'channelId': channelId}); if (res['errorCode'] != 0) throw AgoraRtmClientException( diff --git a/lib/src/agora_rtm_plugin.dart b/lib/src/agora_rtm_plugin.dart index a08ff83..08fc1c1 100644 --- a/lib/src/agora_rtm_plugin.dart +++ b/lib/src/agora_rtm_plugin.dart @@ -3,11 +3,11 @@ import 'package:flutter/services.dart'; mixin AgoraRtmPlugin { static const MethodChannel _methodChannel = const MethodChannel("io.agora.rtm"); - static Future _sendMethodMessage(String call, String method, Map arguments) { + static Future _sendMethodMessage(String call, String method, Map? arguments) { return _methodChannel.invokeMethod(method, {"call": call, "params": arguments}); } - static Future callMethodForStatic(String name, Map arguments) { + static Future callMethodForStatic(String name, Map? arguments) { return _sendMethodMessage("static", name, arguments); } diff --git a/lib/src/utils.dart b/lib/src/utils.dart index ef92a72..06b88e3 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -1,7 +1,7 @@ class AgoraRtmMessage { - String text; - int ts; - bool offline; + String? text; + int? ts; + bool? offline; AgoraRtmMessage(this.text, this.ts, this.offline); @@ -44,8 +44,8 @@ class AgoraRtmMember { class AgoraRtmChannelAttribute { String key; String value; - String userId; - int updateTs; + String? userId; + int? updateTs; AgoraRtmChannelAttribute(this.key, this.value, {this.userId, this.updateTs}); diff --git a/pubspec.yaml b/pubspec.yaml index ae2546d..f8f23fd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://www.agora.io repository: https://github.com/AgoraIO/Flutter-RTM environment: - sdk: ">=2.7.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" flutter: ">=1.12.13+hotfix.6" dependencies: From eddc7296d3137de9b16a64f75dad29ab3c68d9cb Mon Sep 17 00:00:00 2001 From: HUI Date: Wed, 21 Apr 2021 14:08:43 +0800 Subject: [PATCH 3/4] chore: release 1.0.0-rc.0 --- CHANGELOG.md | 3 +++ pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b468008..758231c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change log +## 1.0.0-rc.0 +* support null safety + ## 0.9.14 * fix iOS build error diff --git a/pubspec.yaml b/pubspec.yaml index f8f23fd..89543d6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: agora_rtm description: Flutter plugin for Agora RTM SDK. -version: 0.9.14 +version: 1.0.0-rc.0 homepage: https://www.agora.io repository: https://github.com/AgoraIO/Flutter-RTM From 55194b38cbbefcf6126f1811f5ac66f694e0fcda Mon Sep 17 00:00:00 2001 From: "Jerry.Luo" <396912848@qq.com> Date: Tue, 18 May 2021 13:40:26 +0800 Subject: [PATCH 4/4] chore: release 1.0.0-rc.1 --- CHANGELOG.md | 3 +++ pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 758231c..9a2b395 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change log +## 1.0.0-rc.1 +* fix error of get value + ## 1.0.0-rc.0 * support null safety diff --git a/pubspec.yaml b/pubspec.yaml index 89543d6..7752c75 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: agora_rtm description: Flutter plugin for Agora RTM SDK. -version: 1.0.0-rc.0 +version: 1.0.0-rc.1 homepage: https://www.agora.io repository: https://github.com/AgoraIO/Flutter-RTM