Skip to content

Commit

Permalink
fix: FlutterStandardTypedData & init with wrong appId
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Jun 5, 2023
1 parent 88ed04f commit 3bba6a9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.5.0"
version: "1.5.1"
async:
dependency: transitive
description:
Expand Down
7 changes: 4 additions & 3 deletions ios/Classes/Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import AgoraRtmKit
import Flutter

extension AgoraRtmMessage {
func toJson() -> [String: Any?] {
switch(self){
case let self as AgoraRtmRawMessage: return [
"text": text,
"rawMessage": self.rawData,
"rawMessage": FlutterStandardTypedData(bytes: self.rawData),
"messageType": type.rawValue,
"serverReceivedTs": serverReceivedTs,
"isOfflineMessage": isOfflineMessage,
Expand Down Expand Up @@ -101,8 +102,8 @@ extension AgoraRtmChannelMemberCount {
extension Dictionary where Key == String {
func toRtmMessage() -> AgoraRtmMessage {
let text = self["text"] as? String
if let rawMessage = self["rawMessage"] as? Data {
return AgoraRtmRawMessage(rawData: rawMessage, description: text!)
if let rawMessage = self["rawMessage"] as? FlutterStandardTypedData {
return AgoraRtmRawMessage(rawData: rawMessage.data, description: text!)
} else {
return AgoraRtmMessage(text: text!)
}
Expand Down
8 changes: 5 additions & 3 deletions ios/Classes/RTMClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class RTMClient: NSObject, FlutterStreamHandler, AgoraRtmDelegate {
var call: RTMCallManager?
var channels: [String: AgoraRtmChannel] = [:]

init(_ appId: String?, _ clientIndex: Int, _ messenger: FlutterBinaryMessenger) {
init(_ appId: String?, _ clientIndex: Int, _ messenger: FlutterBinaryMessenger) throws {
super.init()
self.eventChannel = FlutterEventChannel(name: "io.agora.rtm.client\(clientIndex)", binaryMessenger: messenger)
self.eventChannel?.setStreamHandler(self)

self.client = AgoraRtmKit(appId: appId ?? "", delegate: self)
self.call = RTMCallManager(client!, clientIndex, messenger)
guard let client = AgoraRtmKit(appId: appId ?? "", delegate: self) else {
throw NSError(domain: "", code: AgoraRtmLoginErrorCode.invalidAppId.rawValue)
}
self.call = RTMCallManager(client, clientIndex, messenger)
}

deinit {
Expand Down
12 changes: 8 additions & 4 deletions ios/Classes/SwiftAgoraRtmPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ public class SwiftAgoraRtmPlugin: NSObject, FlutterPlugin {
nextClientIndex += 1
}
let appId = params?["appId"] as? String
let agoraClient = RTMClient(appId, nextClientIndex, registrar.messenger())
result(["errorCode": 0, "result": nextClientIndex])
clients[nextClientIndex] = agoraClient
nextClientIndex += 1
do {
let agoraClient = try RTMClient(appId, nextClientIndex, registrar.messenger())
result(["errorCode": 0, "result": nextClientIndex])
clients[nextClientIndex] = agoraClient
nextClientIndex += 1
} catch let error as NSError {
result(["errorCode": error.code])
}
case "getSdkVersion":
result(["errorCode": 0, "result": AgoraRtmKit.getSDKVersion()])
default:
Expand Down

0 comments on commit 3bba6a9

Please sign in to comment.