-
Notifications
You must be signed in to change notification settings - Fork 68
/
RTMCallManager.swift
133 lines (114 loc) · 5.04 KB
/
RTMCallManager.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// RTMCallManager.swift
// agora_rtm
//
// Created by LXH on 2023/5/31.
//
import Foundation
import AgoraRtmKit
import Flutter
class RTMCallManager: NSObject, AgoraRtmCallDelegate, FlutterStreamHandler {
var eventChannel: FlutterEventChannel?
var eventSink: FlutterEventSink?
var client: AgoraRtmKit?
var remoteInvitations: [Int: AgoraRtmRemoteInvitation] = [:]
var localInvitations: [Int: AgoraRtmLocalInvitation] = [:]
var manager: AgoraRtmCallKit? {
get {
return client?.getRtmCall()
}
}
init(_ client: AgoraRtmKit, _ clientIndex: Int, _ messenger: FlutterBinaryMessenger) {
eventChannel = FlutterEventChannel(
name: "io.agora.rtm.client\(clientIndex).call_manager",
binaryMessenger: messenger
)
self.client = client
super.init()
eventChannel?.setStreamHandler(self)
self.manager?.callDelegate = self
}
deinit {
remoteInvitations.removeAll()
localInvitations.removeAll()
eventChannel = nil
client = nil
}
private func sendEvent(eventName: String, params: [String: Any?]) {
let event: [String: Any?] = [
"event": eventName,
"data": params,
]
eventSink?(event)
}
func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
self.eventSink = events
return nil
}
func onCancel(withArguments arguments: Any?) -> FlutterError? {
self.eventSink = nil
return nil
}
func rtmCallKit(_ callKit: AgoraRtmCallKit, localInvitationReceivedByPeer localInvitation: AgoraRtmLocalInvitation) {
localInvitations[localInvitation.hash] = localInvitation
sendEvent(eventName: "onLocalInvitationReceivedByPeer", params: [
"localInvitation": localInvitation.toJson(),
])
}
func rtmCallKit(_ callKit: AgoraRtmCallKit, localInvitationAccepted localInvitation: AgoraRtmLocalInvitation, withResponse response: String?) {
localInvitations.removeValue(forKey: localInvitation.hash)
sendEvent(eventName: "onLocalInvitationAccepted", params: [
"localInvitation": localInvitation.toJson(),
"response": response,
])
}
func rtmCallKit(_ callKit: AgoraRtmCallKit, localInvitationRefused localInvitation: AgoraRtmLocalInvitation, withResponse response: String?) {
localInvitations.removeValue(forKey: localInvitation.hash)
sendEvent(eventName: "onLocalInvitationRefused", params: [
"localInvitation": localInvitation.toJson(),
"response": response,
])
}
func rtmCallKit(_ callKit: AgoraRtmCallKit, localInvitationCanceled localInvitation: AgoraRtmLocalInvitation) {
localInvitations.removeValue(forKey: localInvitation.hash)
sendEvent(eventName: "onLocalInvitationCanceled", params: [
"localInvitation": localInvitation.toJson(),
])
}
func rtmCallKit(_ callKit: AgoraRtmCallKit, localInvitationFailure localInvitation: AgoraRtmLocalInvitation, errorCode: AgoraRtmLocalInvitationErrorCode) {
sendEvent(eventName: "onLocalInvitationFailure", params: [
"localInvitation": localInvitation.toJson(),
"errorCode": errorCode.rawValue,
])
}
func rtmCallKit(_ callKit: AgoraRtmCallKit, remoteInvitationReceived remoteInvitation: AgoraRtmRemoteInvitation) {
remoteInvitations[remoteInvitation.hash] = remoteInvitation
sendEvent(eventName: "onRemoteInvitationReceived", params: [
"remoteInvitation": remoteInvitation.toJson(),
])
}
func rtmCallKit(_ callKit: AgoraRtmCallKit, remoteInvitationAccepted remoteInvitation: AgoraRtmRemoteInvitation) {
remoteInvitations.removeValue(forKey: remoteInvitation.hash)
sendEvent(eventName: "onRemoteInvitationAccepted", params: [
"remoteInvitation": remoteInvitation.toJson(),
])
}
func rtmCallKit(_ callKit: AgoraRtmCallKit, remoteInvitationRefused remoteInvitation: AgoraRtmRemoteInvitation) {
remoteInvitations.removeValue(forKey: remoteInvitation.hash)
sendEvent(eventName: "onRemoteInvitationRefused", params: [
"remoteInvitation": remoteInvitation.toJson(),
])
}
func rtmCallKit(_ callKit: AgoraRtmCallKit, remoteInvitationCanceled remoteInvitation: AgoraRtmRemoteInvitation) {
remoteInvitations.removeValue(forKey: remoteInvitation.hash)
sendEvent(eventName: "onRemoteInvitationCanceled", params: [
"remoteInvitation": remoteInvitation.toJson(),
])
}
func rtmCallKit(_ callKit: AgoraRtmCallKit, remoteInvitationFailure remoteInvitation: AgoraRtmRemoteInvitation, errorCode: AgoraRtmRemoteInvitationErrorCode) {
sendEvent(eventName: "onRemoteInvitationFailure", params: [
"remoteInvitation": remoteInvitation.toJson(),
"errorCode": errorCode.rawValue,
])
}
}