Skip to content

Commit

Permalink
Merge pull request #143 from AgoraIO-Community/rtm-fix
Browse files Browse the repository at this point in the history
update RTM, RTC + sendMessage as String
  • Loading branch information
Meherdeep authored Jun 15, 2023
2 parents 12ef5f4 + 2d958a4 commit 5c8b251
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 142 deletions.
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ target 'Example_ScreenSharing_Extension' do
use_modular_headers!

# pod 'AgoraRtcEngine_iOS', '4.1.0'
pod 'AgoraBroadcastExtensionHelper_iOS', '4.0.7'
pod 'AgoraBroadcastExtensionHelper_iOS', '4.1.1'
end
5 changes: 4 additions & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -302,10 +302,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand Down Expand Up @@ -338,6 +340,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@
<true/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
4 changes: 2 additions & 2 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import FlutterMacOS
import Foundation

import agora_rtc_engine
import iris_event
import iris_method_channel

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AgoraRtcNgPlugin.register(with: registry.registrar(forPlugin: "AgoraRtcNgPlugin"))
IrisEventPlugin.register(with: registry.registrar(forPlugin: "IrisEventPlugin"))
IrisMethodChannelPlugin.register(with: registry.registrar(forPlugin: "IrisMethodChannelPlugin"))
}
6 changes: 3 additions & 3 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include "generated_plugin_registrant.h"

#include <agora_rtc_engine/agora_rtc_engine_plugin.h>
#include <iris_event/iris_event_plugin.h>
#include <iris_method_channel/iris_method_channel_plugin_c_api.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
AgoraRtcEnginePluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AgoraRtcEnginePlugin"));
IrisEventPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("IrisEventPlugin"));
IrisMethodChannelPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("IrisMethodChannelPluginCApi"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
}
2 changes: 1 addition & 1 deletion example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
agora_rtc_engine
iris_event
iris_method_channel
permission_handler_windows
)

Expand Down
20 changes: 19 additions & 1 deletion lib/agora_uikit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,25 @@ export 'package:agora_rtc_engine/agora_rtc_engine.dart'
RtmpStreamingEvent,
UploadErrorReason;
export 'package:agora_rtm/agora_rtm.dart'
show AgoraRtmChannelException, AgoraRtmClientException, AgoraRtmMessage;
show
AgoraRtmChannelException,
AgoraRtmClientException,
RtmMessage,
RtmAttribute,
RtmChannelAttribute,
RtmChannelMember,
RtmChannelMemberCount,
RtmAreaCode,
RtmCloudProxyType,
RtmConnectionChangeReason,
RtmConnectionState,
RtmLocalInvitationState,
RtmServiceContext,
RtmLogFilter,
RtmMessageType,
RtmPeerOnlineState,
RtmPeerSubscriptionOption,
RtmRemoteInvitationState;

export 'package:permission_handler/permission_handler.dart';

Expand Down
7 changes: 3 additions & 4 deletions lib/controllers/rtc_event_handlers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ Future<RtcEngineEventHandler> rtcEngineEventHandler(
}, onFirstLocalAudioFramePublished: (connection, elapsed) {
agoraEventHandlers.onFirstLocalAudioFramePublished
?.call(connection, elapsed);
}, onFirstLocalVideoFrame: (connection, width, height, elapsed) {
}, onFirstLocalVideoFrame: (source, width, height, elapsed) {
agoraEventHandlers.onFirstLocalVideoFrame
?.call(connection, width, height, elapsed);
?.call(source, width, height, elapsed);
}, onFirstLocalVideoFramePublished: (connection, elapsed) {
agoraEventHandlers.onFirstLocalVideoFramePublished
?.call(connection, elapsed);
Expand Down Expand Up @@ -109,8 +109,7 @@ Future<RtcEngineEventHandler> rtcEngineEventHandler(
agoraEventHandlers.onCameraExposureAreaChanged?.call(x, y, width, height);
}, onFacePositionChanged:
(imageWidth, imageHeight, vecRectangle, vecDistance, numFaces) {
agoraEventHandlers.onFacePositionChanged
?.call(imageWidth, imageHeight, vecRectangle, vecDistance, numFaces);
agoraEventHandlers.onFacePositionChanged?.call(imageWidth, imageHeight, vecRectangle, vecDistance, numFaces);
}, onRtcStats: (connection, stats) {
agoraEventHandlers.onRtcStats?.call(connection, stats);
}, onLastmileQuality: (quality) {
Expand Down
8 changes: 4 additions & 4 deletions lib/controllers/rtm_channel_event_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Future<void> rtmChannelEventHandler({
required SessionController sessionController,
}) async {
const String tag = "AgoraVideoUIKit";
channel.onMessageReceived = (AgoraRtmMessage message, AgoraRtmMember member) {
channel.onMessageReceived = (RtmMessage message, RtmChannelMember member) {
agoraRtmChannelEventHandler.onMessageReceived?.call(
message,
member,
Expand All @@ -33,7 +33,7 @@ Future<void> rtmChannelEventHandler({
);
};

channel.onMemberJoined = (AgoraRtmMember member) {
channel.onMemberJoined = (RtmChannelMember member) {
agoraRtmChannelEventHandler.onMemberJoined?.call(member);

log(
Expand All @@ -49,7 +49,7 @@ Future<void> rtmChannelEventHandler({
);
};

channel.onMemberLeft = (AgoraRtmMember member) {
channel.onMemberLeft = (RtmChannelMember member) {
agoraRtmChannelEventHandler.onMemberLeft?.call(member);

log(
Expand Down Expand Up @@ -86,7 +86,7 @@ Future<void> rtmChannelEventHandler({
);
};

channel.onAttributesUpdated = (List<AgoraRtmChannelAttribute> attributes) {
channel.onAttributesUpdated = (List<RtmChannelAttribute> attributes) {
agoraRtmChannelEventHandler.onAttributesUpdated?.call(attributes);

log(
Expand Down
71 changes: 11 additions & 60 deletions lib/controllers/rtm_client_event_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,30 @@ Future<void> rtmClientEventHandler({
}) async {
const String tag = "AgoraVideoUIKit";

agoraRtmClient.onMessageReceived = (AgoraRtmMessage message, String peerId) {
agoraRtmClient.onMessageReceived = (RtmMessage message, String peerId) {
agoraRtmClientEventHandler.onMessageReceived?.call(message, peerId);
Message msg = Message(text: message.text);
String? messageType;

message.toJson().forEach((key, val) {
if (key == "text") {
var json = jsonDecode(val.toString());
messageType = json['messageType'];
}
});
final body = json.decode(message.text);
messageType = body['messageType'];

messageReceived(
messageType: messageType!,
message: msg.toJson(),
sessionController: sessionController,
);
};

agoraRtmClient.onConnectionStateChanged = (int state, int reason) {
agoraRtmClientEventHandler.onConnectionStateChanged?.call(state, reason);
agoraRtmClient.onConnectionStateChanged2 = (state, reason) {
agoraRtmClientEventHandler.onConnectionStateChanged2?.call(state, reason);

log(
'Connection state changed : ${state.toString()}, reason : ${reason.toString()}',
level: Level.info.value,
name: tag,
);
if (state == 5) {
if (state == RtmConnectionState.aborted) {
agoraRtmClient.logout();
}
};
Expand All @@ -66,57 +63,11 @@ Future<void> rtmClientEventHandler({
);
};

agoraRtmClient.onLocalInvitationReceivedByPeer =
(AgoraRtmLocalInvitation invitation) {
agoraRtmClientEventHandler.onLocalInvitationReceivedByPeer
?.call(invitation);
};

agoraRtmClient.onLocalInvitationAccepted =
(AgoraRtmLocalInvitation invitation) {
agoraRtmClientEventHandler.onLocalInvitationAccepted?.call(invitation);
};

agoraRtmClient.onLocalInvitationRefused =
(AgoraRtmLocalInvitation invitation) {
agoraRtmClientEventHandler.onLocalInvitationRefused?.call(invitation);
};

agoraRtmClient.onLocalInvitationCanceled =
(AgoraRtmLocalInvitation invitation) {
agoraRtmClientEventHandler.onLocalInvitationCanceled?.call(invitation);
};

agoraRtmClient.onLocalInvitationFailure =
(AgoraRtmLocalInvitation invitation, int errorCode) {
agoraRtmClientEventHandler.onLocalInvitationFailure
?.call(invitation, errorCode);
};

agoraRtmClient.onRemoteInvitationReceivedByPeer =
(AgoraRtmRemoteInvitation invitation) {
agoraRtmClientEventHandler.onRemoteInvitationReceivedByPeer
?.call(invitation);
};

agoraRtmClient.onRemoteInvitationAccepted =
(AgoraRtmRemoteInvitation invitation) {
agoraRtmClientEventHandler.onRemoteInvitationAccepted?.call(invitation);
};

agoraRtmClient.onRemoteInvitationRefused =
(AgoraRtmRemoteInvitation invitation) {
agoraRtmClientEventHandler.onRemoteInvitationRefused?.call(invitation);
};

agoraRtmClient.onRemoteInvitationCanceled =
(AgoraRtmRemoteInvitation invitation) {
agoraRtmClientEventHandler.onRemoteInvitationCanceled?.call(invitation);
agoraRtmClient.onPeersOnlineStatusChanged = (peersStatus) {
agoraRtmClientEventHandler.onPeersOnlineStatusChanged?.call(peersStatus);
};

agoraRtmClient.onRemoteInvitationFailure =
(AgoraRtmRemoteInvitation invitation, int errorCode) {
agoraRtmClientEventHandler.onRemoteInvitationFailure
?.call(invitation, errorCode);
agoraRtmClient.onTokenPrivilegeWillExpire = () {
agoraRtmClientEventHandler.onTokenPrivilegeWillExpire?.call();
};
}
6 changes: 3 additions & 3 deletions lib/controllers/rtm_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ Future<void> sendUserData({
var json = jsonEncode(userData);

Message message = Message(text: json, ts: ts, offline: false);
AgoraRtmMessage msg = AgoraRtmMessage.fromJson(message.toJson());
RtmMessage msg = RtmMessage.fromText(message.text);

if (sessionController.value.agoraRtmChannel != null && toChannel) {
await sessionController.value.agoraRtmChannel?.sendMessage(msg);
await sessionController.value.agoraRtmChannel?.sendMessage2(msg);
log('User data sent to channel', level: Level.info.value);
} else if (sessionController.value.agoraRtmClient != null &&
!toChannel &&
peerRtmId != null) {
await sessionController.value.agoraRtmClient
?.sendMessageToPeer(peerRtmId, msg);
?.sendMessageToPeer2(peerRtmId, msg);
log('User data sent to peer', level: Level.info.value);
} else {
log("No user in the channel", level: Level.warning.value);
Expand Down
5 changes: 3 additions & 2 deletions lib/controllers/rtm_mute_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ void hostControl({

var json = jsonEncode(muteRequest);
Message message = Message(text: json);
AgoraRtmMessage msg = AgoraRtmMessage.fromJson(message.toJson());
RtmMessage msg = RtmMessage.fromText(message.text);
sessionController.value.uidToUserIdMap!.forEach((key, val) {
if (key == sessionController.value.users[index].uid) {
peerId = val;
if (sessionController.value.isLoggedIn) {
sessionController.value.agoraRtmClient?.sendMessageToPeer(peerId!, msg);
sessionController.value.agoraRtmClient
?.sendMessageToPeer2(peerId!, msg);
} else {
log("User not logged in", level: Level.warning.value);
}
Expand Down
15 changes: 9 additions & 6 deletions lib/models/agora_rtc_event_handlers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,12 @@ class AgoraRtcEventHandlers {
/// Occurs when the first local video frame is displayed on the local video view.
/// The SDK triggers this callback when the first local video frame is displayed on the local video view.
///
/// * [source] The capture type of the custom video source. See VideoSourceType .
/// * [connection] The connection information. See RtcConnection .
/// * [source] The type of the video source. See VideoSourceType .
/// * [width] The width (px) of the first local video frame.
/// * [height] The height (px) of the first local video frame.
/// * [elapsed] Time elapsed (ms) from the local user calling joinChannel [2/2] until the SDK triggers this callback. If you call startPreview before calling joinChannel [2/2], then this parameter is the time elapsed from calling the startPreview method until the SDK triggers this callback.
/// * [elapsed] Time elapsed (ms) from the local user calling joinChannel until the SDK triggers this callback. If you call startPreview before calling joinChannel, then this parameter is the time elapsed from calling the startPreview method until the SDK triggers this callback.
final void Function(
RtcConnection connection, int width, int height, int elapsed)?
VideoSourceType source, int width, int height, int elapsed)?
onFirstLocalVideoFrame;

/// Occurs when the first video frame is published.
Expand Down Expand Up @@ -331,8 +330,12 @@ class AgoraRtcEventHandlers {
/// * [vecRectangle] The information of the detected human face. See Rectangle .
/// * [vecDistance] The distance between the human face and the device screen (cm).
/// * [numFaces] The number of faces detected. If the value is 0, it means that no human face is detected.
final void Function(int imageWidth, int imageHeight, Rectangle vecRectangle,
int vecDistance, int numFaces)? onFacePositionChanged;
final void Function(
int imageWidth,
int imageHeight,
List<Rectangle> vecRectangle,
List<int> vecDistance,
int numFaces)? onFacePositionChanged;

/// Occurs when the video stops playing.
/// Deprecated:Use localVideoStreamStateStopped(0) in the onLocalVideoStateChanged callback instead.The application can use this callback to change the configuration of the view (for example, displaying other pictures in the view) after the video stops playing.
Expand Down
9 changes: 4 additions & 5 deletions lib/models/agora_rtm_channel_event_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ class AgoraRtmChannelEventHandler {
final Function(dynamic error)? onError;

/// Occurs when receiving a channel message.
final Function(AgoraRtmMessage message, AgoraRtmMember fromMember)?
final Function(RtmMessage message, RtmChannelMember fromMember)?
onMessageReceived;

/// Occurs when a user joins the channel.
final Function(AgoraRtmMember member)? onMemberJoined;
final Function(RtmChannelMember member)? onMemberJoined;

/// Occurs when a channel member leaves the channel.
final Function(AgoraRtmMember member)? onMemberLeft;
final Function(RtmChannelMember member)? onMemberLeft;

/// Occurs when channel attribute updated.
final Function(List<AgoraRtmChannelAttribute> attributes)?
onAttributesUpdated;
final Function(List<RtmChannelAttribute> attributes)? onAttributesUpdated;

/// Occurs when channel member count updated.
final Function(int count)? onMemberCountUpdated;
Expand Down
Loading

0 comments on commit 5c8b251

Please sign in to comment.