good spot figuring out how to use the delegate
This commit is contained in:
@@ -15,7 +15,6 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
let firestoreService = FirestoreService()
|
let firestoreService = FirestoreService()
|
||||||
|
|
||||||
var agoraKit: AgoraRtcEngineKit?
|
var agoraKit: AgoraRtcEngineKit?
|
||||||
var agoraDelegate: AgoraRtcEngineDelegate?
|
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
@@ -60,14 +59,14 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
// ensure the convo is active and includes 2 people in it currently...shouldn't be shown if not anyway
|
// ensure the convo is active and includes 2 people in it currently...shouldn't be shown if not anyway
|
||||||
|
|
||||||
// ensure that this user leaves all other channels
|
// ensure that this user leaves all other channels
|
||||||
self.leaveConvo()
|
if self.inCall {
|
||||||
|
self.leaveConvo()
|
||||||
|
}
|
||||||
|
|
||||||
self.agoraKit?.setDefaultAudioRouteToSpeakerphone(true)
|
self.agoraKit?.setDefaultAudioRouteToSpeakerphone(true)
|
||||||
|
|
||||||
// finally join channel
|
// finally join channel
|
||||||
self.agoraKit?.joinChannel(byToken: convoAgoraToken, channelId: "testChannel", info: nil, uid: 0, joinSuccess: {(channel, uid, elapsed) in
|
self.agoraKit?.joinChannel(byToken: convoAgoraToken, channelId: "testChannel", info: nil, uid: 0, joinSuccess: nil)
|
||||||
self.inCall = true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// anyone can leave at any time
|
// anyone can leave at any time
|
||||||
@@ -90,23 +89,29 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
extension ConvoViewModel {
|
extension ConvoViewModel {
|
||||||
func initializeAgoraEngine() {
|
func initializeAgoraEngine() {
|
||||||
// TODO: put app id in environment variables
|
// TODO: put app id in environment variables
|
||||||
agoraKit = AgoraRtcEngineKit.sharedEngine(withAppId: "c8dfd65deb5c4741bd564085627139d0", delegate: agoraDelegate)
|
agoraKit = AgoraRtcEngineKit.sharedEngine(withAppId: "c8dfd65deb5c4741bd564085627139d0", delegate: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ConvoViewModel: AgoraRtcEngineDelegate {
|
extension ConvoViewModel: AgoraRtcEngineDelegate {
|
||||||
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
|
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
|
||||||
print("I did join channel")
|
print("I did join channel")
|
||||||
|
|
||||||
|
// leave channel if it's just me
|
||||||
|
|
||||||
|
self.inCall = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func rtcEngine(_ engine: AgoraRtcEngineKit, didLeaveChannelWith stats: AgoraChannelStats) {
|
func rtcEngine(_ engine: AgoraRtcEngineKit, didLeaveChannelWith stats: AgoraChannelStats) {
|
||||||
|
// leave channel if I am the only one in it
|
||||||
|
|
||||||
print("I did leave channel")
|
print("I did leave channel")
|
||||||
|
|
||||||
|
|
||||||
|
self.inCall = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinedOfUid uid: UInt, elapsed: Int) {
|
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinedOfUid uid: UInt, elapsed: Int) {
|
||||||
// Only one remote video view is available for this
|
|
||||||
// tutorial. Here we check if there exists a surface
|
|
||||||
// view tagged as this uid.
|
|
||||||
print("new user joined \(uid)")
|
print("new user joined \(uid)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user