-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRtcChannelEvent.swift
More file actions
249 lines (207 loc) · 12.9 KB
/
RtcChannelEvent.swift
File metadata and controls
249 lines (207 loc) · 12.9 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//
// RtcChannelEvent.swift
// RCTAgora
//
// Created by LXH on 2020/4/10.
// Copyright © 2020 Syan. All rights reserved.
//
import Foundation
import AgoraRtcKit
class RtcChannelEvents {
static let Warning = "Warning"
static let Error = "Error"
static let JoinChannelSuccess = "JoinChannelSuccess"
static let RejoinChannelSuccess = "RejoinChannelSuccess"
static let LeaveChannel = "LeaveChannel"
static let ClientRoleChanged = "ClientRoleChanged"
static let UserJoined = "UserJoined"
static let UserOffline = "UserOffline"
static let ConnectionStateChanged = "ConnectionStateChanged"
static let ConnectionLost = "ConnectionLost"
static let TokenPrivilegeWillExpire = "TokenPrivilegeWillExpire"
static let RequestToken = "RequestToken"
static let ActiveSpeaker = "ActiveSpeaker"
static let VideoSizeChanged = "VideoSizeChanged"
static let RemoteVideoStateChanged = "RemoteVideoStateChanged"
static let RemoteAudioStateChanged = "RemoteAudioStateChanged"
static let LocalPublishFallbackToAudioOnly = "LocalPublishFallbackToAudioOnly"
static let RemoteSubscribeFallbackToAudioOnly = "RemoteSubscribeFallbackToAudioOnly"
static let RtcStats = "RtcStats"
static let NetworkQuality = "NetworkQuality"
static let RemoteVideoStats = "RemoteVideoStats"
static let RemoteAudioStats = "RemoteAudioStats"
static let RtmpStreamingStateChanged = "RtmpStreamingStateChanged"
static let TranscodingUpdated = "TranscodingUpdated"
static let StreamInjectedStatus = "StreamInjectedStatus"
static let StreamMessage = "StreamMessage"
static let StreamMessageError = "StreamMessageError"
static let ChannelMediaRelayStateChanged = "ChannelMediaRelayStateChanged"
static let ChannelMediaRelayEvent = "ChannelMediaRelayEvent"
static let MetadataReceived = "MetadataReceived"
static let AudioPublishStateChanged = "AudioPublishStateChanged"
static let VideoPublishStateChanged = "VideoPublishStateChanged"
static let AudioSubscribeStateChanged = "AudioSubscribeStateChanged"
static let VideoSubscribeStateChanged = "VideoSubscribeStateChanged"
static let RtmpStreamingEvent = "RtmpStreamingEvent"
static let UserSuperResolutionEnabled = "UserSuperResolutionEnabled"
static func toMap() -> Dictionary<String, String> {
return [
"Warning": Warning,
"Error": Error,
"JoinChannelSuccess": JoinChannelSuccess,
"RejoinChannelSuccess": RejoinChannelSuccess,
"LeaveChannel": LeaveChannel,
"ClientRoleChanged": ClientRoleChanged,
"UserJoined": UserJoined,
"UserOffline": UserOffline,
"ConnectionStateChanged": ConnectionStateChanged,
"ConnectionLost": ConnectionLost,
"TokenPrivilegeWillExpire": TokenPrivilegeWillExpire,
"RequestToken": RequestToken,
"ActiveSpeaker": ActiveSpeaker,
"VideoSizeChanged": VideoSizeChanged,
"RemoteVideoStateChanged": RemoteVideoStateChanged,
"RemoteAudioStateChanged": RemoteAudioStateChanged,
"LocalPublishFallbackToAudioOnly": LocalPublishFallbackToAudioOnly,
"RemoteSubscribeFallbackToAudioOnly": RemoteSubscribeFallbackToAudioOnly,
"RtcStats": RtcStats,
"NetworkQuality": NetworkQuality,
"RemoteVideoStats": RemoteVideoStats,
"RemoteAudioStats": RemoteAudioStats,
"RtmpStreamingStateChanged": RtmpStreamingStateChanged,
"TranscodingUpdated": TranscodingUpdated,
"StreamInjectedStatus": StreamInjectedStatus,
"StreamMessage": StreamMessage,
"StreamMessageError": StreamMessageError,
"ChannelMediaRelayStateChanged": ChannelMediaRelayStateChanged,
"ChannelMediaRelayEvent": ChannelMediaRelayEvent,
"MetadataReceived": MetadataReceived,
"AudioPublishStateChanged": AudioPublishStateChanged,
"VideoPublishStateChanged": VideoPublishStateChanged,
"AudioSubscribeStateChanged": AudioSubscribeStateChanged,
"VideoSubscribeStateChanged": VideoSubscribeStateChanged,
"RtmpStreamingEvent": RtmpStreamingEvent,
"UserSuperResolutionEnabled": UserSuperResolutionEnabled
]
}
}
class RtcChannelEventHandler: NSObject {
static let PREFIX = "io.agora.rtc."
var emitter: (_ methodName: String, _ data: Dictionary<String, Any?>?) -> Void
init(_ emitter: @escaping (_ methodName: String, _ data: Dictionary<String, Any?>?) -> Void) {
self.emitter = emitter
}
private func callback(_ methodName: String, _ channel: AgoraRtcChannel, _ data: Any?...) {
emitter(methodName, [
"channelId": channel.getId(),
"data": data
])
}
}
extension RtcChannelEventHandler: AgoraRtcChannelDelegate {
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, didOccurWarning warningCode: AgoraWarningCode) {
callback(RtcChannelEvents.Warning, rtcChannel, warningCode.rawValue)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, didOccurError errorCode: AgoraErrorCode) {
callback(RtcChannelEvents.Error, rtcChannel, errorCode.rawValue)
}
public func rtcChannelDidJoin(_ rtcChannel: AgoraRtcChannel, withUid uid: UInt, elapsed: Int) {
callback(RtcChannelEvents.JoinChannelSuccess, rtcChannel, rtcChannel.getId(), uid, elapsed)
}
public func rtcChannelDidRejoin(_ rtcChannel: AgoraRtcChannel, withUid uid: UInt, elapsed: Int) {
callback(RtcChannelEvents.RejoinChannelSuccess, rtcChannel, rtcChannel.getId(), uid, elapsed)
}
public func rtcChannelDidLeave(_ rtcChannel: AgoraRtcChannel, with stats: AgoraChannelStats) {
callback(RtcChannelEvents.LeaveChannel, rtcChannel, stats.toMap())
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, didClientRoleChanged oldRole: AgoraClientRole, newRole: AgoraClientRole) {
callback(RtcChannelEvents.ClientRoleChanged, rtcChannel, oldRole.rawValue, newRole.rawValue)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, didJoinedOfUid uid: UInt, elapsed: Int) {
callback(RtcChannelEvents.UserJoined, rtcChannel, uid, elapsed)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, didOfflineOfUid uid: UInt, reason: AgoraUserOfflineReason) {
callback(RtcChannelEvents.UserOffline, rtcChannel, uid, reason.rawValue)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, connectionChangedTo state: AgoraConnectionStateType, reason: AgoraConnectionChangedReason) {
callback(RtcChannelEvents.ConnectionStateChanged, rtcChannel, state.rawValue, reason.rawValue)
}
public func rtcChannelDidLost(_ rtcChannel: AgoraRtcChannel) {
callback(RtcChannelEvents.ConnectionLost, rtcChannel)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, tokenPrivilegeWillExpire token: String) {
callback(RtcChannelEvents.TokenPrivilegeWillExpire, rtcChannel, token)
}
public func rtcChannelRequestToken(_ rtcChannel: AgoraRtcChannel) {
callback(RtcChannelEvents.RequestToken, rtcChannel)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, activeSpeaker speakerUid: UInt) {
callback(RtcChannelEvents.ActiveSpeaker, rtcChannel, speakerUid)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, videoSizeChangedOfUid uid: UInt, size: CGSize, rotation: Int) {
callback(RtcChannelEvents.VideoSizeChanged, rtcChannel, uid, Int(size.width), Int(size.height), rotation)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, remoteVideoStateChangedOfUid uid: UInt, state: AgoraVideoRemoteState, reason: AgoraVideoRemoteStateReason, elapsed: Int) {
callback(RtcChannelEvents.RemoteVideoStateChanged, rtcChannel, uid, state.rawValue, reason.rawValue, elapsed)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, remoteAudioStateChangedOfUid uid: UInt, state: AgoraAudioRemoteState, reason: AgoraAudioRemoteStateReason, elapsed: Int) {
callback(RtcChannelEvents.RemoteAudioStateChanged, rtcChannel, uid, state.rawValue, reason.rawValue, elapsed)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, didLocalPublishFallbackToAudioOnly isFallbackOrRecover: Bool) {
callback(RtcChannelEvents.LocalPublishFallbackToAudioOnly, rtcChannel, isFallbackOrRecover)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, didRemoteSubscribeFallbackToAudioOnly isFallbackOrRecover: Bool, byUid uid: UInt) {
callback(RtcChannelEvents.RemoteSubscribeFallbackToAudioOnly, rtcChannel, uid, isFallbackOrRecover)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, reportRtcStats stats: AgoraChannelStats) {
callback(RtcChannelEvents.RtcStats, rtcChannel, stats.toMap())
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, networkQuality uid: UInt, txQuality: AgoraNetworkQuality, rxQuality: AgoraNetworkQuality) {
callback(RtcChannelEvents.NetworkQuality, rtcChannel, uid, txQuality.rawValue, rxQuality.rawValue)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, remoteVideoStats stats: AgoraRtcRemoteVideoStats) {
callback(RtcChannelEvents.RemoteVideoStats, rtcChannel, stats.toMap())
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, remoteAudioStats stats: AgoraRtcRemoteAudioStats) {
callback(RtcChannelEvents.RemoteAudioStats, rtcChannel, stats.toMap())
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, rtmpStreamingChangedToState url: String, state: AgoraRtmpStreamingState, errorCode: AgoraRtmpStreamingErrorCode) {
callback(RtcChannelEvents.RtmpStreamingStateChanged, rtcChannel, url, state.rawValue, errorCode.rawValue)
}
public func rtcChannelTranscodingUpdated(_ rtcChannel: AgoraRtcChannel) {
callback(RtcChannelEvents.TranscodingUpdated, rtcChannel)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, streamInjectedStatusOfUrl url: String, uid: UInt, status: AgoraInjectStreamStatus) {
callback(RtcChannelEvents.StreamInjectedStatus, rtcChannel, url, uid, status.rawValue)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, receiveStreamMessageFromUid uid: UInt, streamId: Int, data: Data) {
callback(RtcChannelEvents.StreamMessage, rtcChannel, uid, streamId, String(data: data, encoding: .utf8))
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, didOccurStreamMessageErrorFromUid uid: UInt, streamId: Int, error: Int, missed: Int, cached: Int) {
callback(RtcChannelEvents.StreamMessageError, rtcChannel, uid, streamId, error, missed, cached)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, channelMediaRelayStateDidChange state: AgoraChannelMediaRelayState, error: AgoraChannelMediaRelayError) {
callback(RtcChannelEvents.ChannelMediaRelayStateChanged, rtcChannel, state.rawValue, error.rawValue)
}
public func rtcChannel(_ rtcChannel: AgoraRtcChannel, didReceive event: AgoraChannelMediaRelayEvent) {
callback(RtcChannelEvents.ChannelMediaRelayEvent, rtcChannel, event.rawValue)
}
func rtcChannel(_ rtcChannel: AgoraRtcChannel, didAudioPublishStateChange oldState: AgoraStreamPublishState, newState: AgoraStreamPublishState, elapseSinceLastState: Int) {
callback(RtcChannelEvents.AudioPublishStateChanged, rtcChannel, rtcChannel.getId(), oldState.rawValue, newState.rawValue, elapseSinceLastState)
}
func rtcChannel(_ rtcChannel: AgoraRtcChannel, didVideoPublishStateChange oldState: AgoraStreamPublishState, newState: AgoraStreamPublishState, elapseSinceLastState: Int) {
callback(RtcChannelEvents.VideoPublishStateChanged, rtcChannel, rtcChannel.getId(), oldState.rawValue, newState.rawValue, elapseSinceLastState)
}
func rtcChannel(_ rtcChannel: AgoraRtcChannel, didAudioSubscribeStateChange uid: UInt, oldState: AgoraStreamSubscribeState, newState: AgoraStreamSubscribeState, elapseSinceLastState: Int) {
callback(RtcChannelEvents.AudioSubscribeStateChanged, rtcChannel, rtcChannel.getId(), uid, oldState.rawValue, newState.rawValue, elapseSinceLastState)
}
func rtcChannel(_ rtcChannel: AgoraRtcChannel, didVideoSubscribeStateChange uid: UInt, oldState: AgoraStreamSubscribeState, newState: AgoraStreamSubscribeState, elapseSinceLastState: Int) {
callback(RtcChannelEvents.VideoSubscribeStateChanged, rtcChannel, rtcChannel.getId(), uid, oldState.rawValue, newState.rawValue, elapseSinceLastState)
}
func rtcChannel(_ rtcChannel: AgoraRtcChannel, rtmpStreamingEventWithUrl url: String, eventCode: AgoraRtmpStreamingEvent) {
callback(RtcChannelEvents.RtmpStreamingEvent, rtcChannel, url, eventCode.rawValue)
}
func rtcChannel(_ rtcChannel: AgoraRtcChannel, superResolutionEnabledOfUid uid: UInt, enabled: Bool, reason: AgoraSuperResolutionStateReason) {
callback(RtcChannelEvents.UserSuperResolutionEnabled, rtcChannel, uid, enabled, reason.rawValue)
}
}