Skip to content

Commit

Permalink
Merge pull request #40 from AgoraIO-Community/ngsdk-betterdelegates
Browse files Browse the repository at this point in the history
4.0.0-preview.4 
- Delegate calls from 1.6.4
  • Loading branch information
maxxfrazer authored Sep 30, 2021
2 parents 2f14795 + 3f63f7f commit 877ad32
Show file tree
Hide file tree
Showing 23 changed files with 485 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .AgoraUIKit_macOS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'AgoraUIKit_macOS'
s.version = '1.6.3'
s.version = '1.6.4'
s.summary = 'Agora video session AppKit template.'

s.description = <<-DESC
Expand Down
4 changes: 3 additions & 1 deletion .jazzy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
podspec: AgoraUIKit_iOS.podspec
exclude:
- Sources/Agora-UIKit/iOS+macOS+typealiases.swift
- Sources/Agora-UIKit/AgoraUIKit+MD5.swift
- Sources/Agora-UIKit/AgoraUIKit+MD5.swift
- Sources/Agora-UIKit/AgoraRtmController+RtmDelegateOverflows.swift
- Sources/Agora-UIKit/AgoraVideoViewer+RtcEngineDelegateOverflow.swift
2 changes: 2 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ line_length:
excluded:
- Agora-*-Example
- Sources/Agora-UIKit/AgoraUIKit+MD5.swift
- Sources/Agora-UIKit/AgoraRtmController+RtmDelegateOverflows.swift
- Sources/Agora-UIKit/AgoraVideoViewer+RtcEngineDelegateOverflow.swift
- .build
2 changes: 1 addition & 1 deletion AgoraUIKit_iOS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'AgoraUIKit_iOS'
s.version = '4.0.0-preview.3'
s.version = '4.0.0-preview.4'
s.summary = 'Agora video session UIKit template.'

s.description = <<-DESC
Expand Down
24 changes: 14 additions & 10 deletions Sources/Agora-UIKit/AgoraCollectionViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AgoraCollectionViewer: MPCollectionView {
self.backgroundColor = UIColor.secondarySystemBackground.withAlphaComponent(0.9)
self.register(AgoraCollectionItem.self, forCellWithReuseIdentifier: "collectionCell")
}
#else
#elseif os(macOS)
init(frame: CGRect, collectionViewLayout layout: MPCollectionViewLayout) {
super.init(frame: frame)
self.collectionViewLayout = layout
Expand Down Expand Up @@ -90,7 +90,7 @@ open class AgoraCollectionItem: MPCollectionViewCell {
#if os(iOS)
avv.frame = self.bounds
self.addSubview(avv)
#else
#elseif os(macOS)
avv.frame = self.view.bounds
self.view.addSubview(avv)
#endif
Expand All @@ -114,7 +114,7 @@ open class AgoraCollectionItem: MPCollectionViewCell {
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
#else
#elseif os(macOS)
override public func loadView() {
self.view = NSView(frame: .zero)
}
Expand Down Expand Up @@ -188,7 +188,7 @@ extension AgoraVideoViewer: MPCollectionViewDelegate, MPCollectionViewDataSource
fatalError("cell not valid")
}
}
#else
#elseif os(macOS)
public func collectionView(
_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath
) -> NSCollectionViewItem {
Expand Down Expand Up @@ -219,14 +219,18 @@ extension AgoraVideoViewer: MPCollectionViewDelegate, MPCollectionViewDataSource
}
#endif

/// Video views to be displayed in the floating collection view.
var collectionViewVideos: [AgoraSingleVideoView] {
internal func refreshCollectionData() {
switch self.style {
case .floating, .collection:
return Array(self.userVideoLookup.values)
if self.agSettings.showSelf {
self.collectionViewVideos = Array(self.userVideoLookup.values)
} else {
self.collectionViewVideos = Array(self.userVideoLookup.filter { $0.key != self.userID}.values)
}
default:
return []
self.collectionViewVideos.removeAll()
}
self.floatingVideoHolder.reloadData()
}

/// Both AppKit and UIKit delegate methods call this function, to have it all in one place
Expand All @@ -236,7 +240,7 @@ extension AgoraVideoViewer: MPCollectionViewDelegate, MPCollectionViewDataSource
internal func displayItem(_ item: MPCollectionViewCell, at indexPath: IndexPath) {
#if os(iOS)
let newVid = self.collectionViewVideos[indexPath.row]
#else
#elseif os(macOS)
let newVid = self.collectionViewVideos[indexPath.item]
#endif
guard let cell = item as? AgoraCollectionItem else {
Expand Down Expand Up @@ -272,7 +276,7 @@ extension AgoraVideoViewer: MPCollectionViewDelegate, MPCollectionViewDataSource
guard let agoraColItem = collectionView.cellForItem(at: indexPath) as? AgoraCollectionItem else {
return
}
#else
#elseif os(macOS)
guard let agoraColItem = collectionView.item(at: indexPath) as? AgoraCollectionItem else {
return
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Agora-UIKit/AgoraConnectionData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if os(iOS)
import UIKit.UIDevice
#else
#elseif os(macOS)
import IOKit
#endif

Expand Down Expand Up @@ -116,7 +116,7 @@ public struct AgoraConnectionData {
guard let vendorId = UIDevice.current.identifierForVendor?.uuidString else {
fatalError("Could not generate vendor Id")
}
#else
#elseif os(macOS)
let vendorId = AgoraConnectionData.fetchSerialMd5()
#endif
self.rtcId = AgoraConnectionData.uidFrom(vendor: vendorId)
Expand Down
7 changes: 5 additions & 2 deletions Sources/Agora-UIKit/AgoraRtmController+AgoraRtmDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if os(iOS)
import UIKit.UIDevice
#else
#elseif os(macOS)
import IOKit
#endif
import AgoraRtmKit
Expand All @@ -22,6 +22,7 @@ extension AgoraRtmController: AgoraRtmDelegate, AgoraRtmChannelDelegate {
callback: self.newTokenFetched(result:)
)
}
self.delegate.agSettings.rtmDelegate?.rtmKitTokenDidExpire?(kit)
}

/**
Expand All @@ -35,6 +36,7 @@ extension AgoraRtmController: AgoraRtmDelegate, AgoraRtmChannelDelegate {
if let rawMsg = message as? AgoraRtmRawMessage {
self.decodeRawMessage(rawMsg: rawMsg, from: peerId)
}
self.delegate.agSettings.rtmDelegate?.rtmKit?(kit, messageReceived: message, fromPeer: peerId)
}

/**
Expand All @@ -51,6 +53,7 @@ extension AgoraRtmController: AgoraRtmDelegate, AgoraRtmChannelDelegate {
*/
open func channel(_ channel: AgoraRtmChannel, memberJoined member: AgoraRtmMember) {
self.sendPersonalData(to: member.userId)
self.delegate.agSettings.rtmChannelDelegate?.channel?(channel, memberJoined: member)
}

/**
Expand All @@ -70,6 +73,7 @@ extension AgoraRtmController: AgoraRtmDelegate, AgoraRtmChannelDelegate {
if let rawMsg = message as? AgoraRtmRawMessage {
self.decodeRawMessage(rawMsg: rawMsg, from: member.userId)
}
self.delegate.agSettings.rtmChannelDelegate?.channel?(channel, messageReceived: message, from: member)
}

/// Decode an incoming AgoraRtmRawMessage
Expand Down Expand Up @@ -108,5 +112,4 @@ extension AgoraRtmController: AgoraRtmDelegate, AgoraRtmChannelDelegate {
}
}
}

}
4 changes: 2 additions & 2 deletions Sources/Agora-UIKit/AgoraRtmController+MuteRequests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if os(iOS)
import UIKit
#else
#elseif os(macOS)
import AppKit
#endif

Expand Down Expand Up @@ -147,7 +147,7 @@ extension AgoraVideoViewer {
alert.addAction(UIAlertAction(title: "Accept", style: .default, handler: setDevice))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.presentAlert(alert: alert, animated: true)
#else
#elseif os(macOS)
let alert = NSAlert()
alert.addButton(withTitle: "Confirm")
alert.addButton(withTitle: "Cancel")
Expand Down
48 changes: 48 additions & 0 deletions Sources/Agora-UIKit/AgoraRtmController+RtmDelegateOverflows.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// AgoraRtmController+RtmDelegateOverflows.swift
//
//
// Created by Max Cobb on 29/09/2021.
//

import AgoraRtmKit

extension AgoraRtmController {
open func rtmKit(_ kit: AgoraRtmKit, peersOnlineStatusChanged onlineStatus: [AgoraRtmPeerOnlineStatus]) {
self.agoraSettings.rtmDelegate?.rtmKit?(kit, peersOnlineStatusChanged: onlineStatus)
}
open func rtmKit(_ kit: AgoraRtmKit, fileMessageReceived message: AgoraRtmFileMessage, fromPeer peerId: String) {
self.agoraSettings.rtmDelegate?.rtmKit?(kit, fileMessageReceived: message, fromPeer: peerId)
}
open func rtmKit(_ kit: AgoraRtmKit, imageMessageReceived message: AgoraRtmImageMessage, fromPeer peerId: String) {
self.agoraSettings.rtmDelegate?.rtmKit?(kit, imageMessageReceived: message, fromPeer: peerId)
}
open func rtmKit(_ kit: AgoraRtmKit, media requestId: Int64, uploadingProgress progress: AgoraRtmMediaOperationProgress) {
self.agoraSettings.rtmDelegate?.rtmKit?(kit, media: requestId, uploadingProgress: progress)
}
open func rtmKit(_ kit: AgoraRtmKit, media requestId: Int64, downloadingProgress progress: AgoraRtmMediaOperationProgress) {
self.agoraSettings.rtmDelegate?.rtmKit?(kit, media: requestId, downloadingProgress: progress)
}
open func rtmKit(_ kit: AgoraRtmKit, connectionStateChanged state: AgoraRtmConnectionState, reason: AgoraRtmConnectionChangeReason) {
self.agoraSettings.rtmDelegate?.rtmKit?(kit, connectionStateChanged: state, reason: reason)
}
}

extension AgoraRtmController {
open func channel(_ channel: AgoraRtmChannel, memberCount count: Int32) {
self.agoraSettings.rtmChannelDelegate?.channel?(channel, memberCount: count)
}
open func channel(_ channel: AgoraRtmChannel, memberLeft member: AgoraRtmMember) {
self.agoraSettings.rtmChannelDelegate?.channel?(channel, memberLeft: member)
}
open func channel(_ channel: AgoraRtmChannel, attributeUpdate attributes: [AgoraRtmChannelAttribute]) {
self.agoraSettings.rtmChannelDelegate?.channel?(channel, attributeUpdate: attributes)
}
open func channel(_ channel: AgoraRtmChannel, fileMessageReceived message: AgoraRtmFileMessage, from member: AgoraRtmMember) {
self.agoraSettings.rtmChannelDelegate?.channel?(channel, fileMessageReceived: message, from: member)
}
open func channel(_ channel: AgoraRtmChannel, imageMessageReceived message: AgoraRtmImageMessage, from member: AgoraRtmMember) {
self.agoraSettings.rtmChannelDelegate?.channel?(channel, imageMessageReceived: message, from: member)
}
}

16 changes: 15 additions & 1 deletion Sources/Agora-UIKit/AgoraSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@
//

import AgoraRtcKit
import AgoraRtmKit

/// Settings used for the display and behaviour of AgoraVideoViewer
public struct AgoraSettings {

/// Delegate for Agora Rtc Engine callbacks
public weak var rtcDelegate: AgoraRtcEngineDelegate?

/// Delegate for Agora RTM callbacks
public weak var rtmDelegate: AgoraRtmDelegate?

/// Delegate for Agora RTM Channel callbacks
public weak var rtmChannelDelegate: AgoraRtmChannelDelegate?

/// URL to fetch tokens from. If supplied, this package will automatically fetch tokens
/// when the Agora Engine indicates it will be needed.
/// It will follow the URL pattern found in
Expand Down Expand Up @@ -102,6 +113,9 @@ public struct AgoraSettings {
set { self.externalVideoSettings = newValue }
}

/// Whether to show your own camera feed
public var showSelf: Bool = true

/// Settings for applying external videos
public struct ExternalAudioSettings {
/// Determines whether to enable the external audio source:
Expand Down Expand Up @@ -182,7 +196,7 @@ public struct AgoraSettings {
#if os(iOS)
/// Scale of the icons within the buttons in the builtin button tray
static var buttonIconScale: UIImage.SymbolScale = .large
#else
#elseif os(macOS)
/// Font size of the builtin buttons SF Symbol text
static var buttonIconSize: CGFloat = 20
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/Agora-UIKit/AgoraSingleVideoView+RtmDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if os(iOS)
import UIKit
#else
#elseif os(macOS)
import AppKit
#endif

Expand Down
4 changes: 2 additions & 2 deletions Sources/Agora-UIKit/AgoraSingleVideoView+RtmOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
#if os(iOS)
import UIKit
#else
#elseif os(macOS)
import AppKit
#endif

Expand Down Expand Up @@ -101,7 +101,7 @@ extension AgoraSingleVideoView {
AgoraVideoViewer.agoraPrint(.error, message: "invalid action title: \(actionTitle)")
}
}
#else
#elseif os(macOS)
/// Options button has been selected, now display available requests
/// - Parameter sender: Button that was selected
@objc public func optionsBtnSelected(sender: NSPopUpButton) {
Expand Down
14 changes: 7 additions & 7 deletions Sources/Agora-UIKit/AgoraSingleVideoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class AgoraSingleVideoView: MPView {
)
userOptionsBtn.layer.zPosition = 3
userOptionsBtn.tintColor = .systemGray
#else
#elseif os(macOS)
let userOptionsBtn = NSPopUpButton(frame: .zero, pullsDown: true)

// userOptionsBtn.wantsLayer = true
Expand All @@ -82,7 +82,7 @@ public class AgoraSingleVideoView: MPView {
)
userOptionsBtn.autoresizingMask = [.flexibleBottomMargin, .flexibleRightMargin]
userOptionsBtn.addTarget(self, action: #selector(optionsBtnSelected), for: .touchUpInside)
#else
#elseif os(macOS)
userOptionsBtn.isBordered = false
userOptionsBtn.wantsLayer = true
userOptionsBtn.layer?.backgroundColor = .clear
Expand All @@ -103,7 +103,7 @@ public class AgoraSingleVideoView: MPView {
#if os(iOS)
let muteFlag = UIImageView(image: UIImage(systemName: MPButton.micSlashSymbol))
muteFlag.tintColor = self.micFlagColor
#else
#elseif os(macOS)
let muteFlag = MPButton()
muteFlag.font = .systemFont(ofSize: NSFont.systemFontSize * 1.5)
muteFlag.attributedTitle = NSAttributedString(
Expand All @@ -118,7 +118,7 @@ public class AgoraSingleVideoView: MPView {
size: CGSize(width: 25, height: 25)
)
muteFlag.autoresizingMask = [.flexibleBottomMargin, .flexibleLeftMargin]
#else
#elseif os(macOS)
muteFlag.isBordered = false
muteFlag.wantsLayer = true
muteFlag.layer?.backgroundColor = .clear
Expand Down Expand Up @@ -149,7 +149,7 @@ public class AgoraSingleVideoView: MPView {
hostingView.frame = self.bounds
#if os(iOS)
hostingView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
#else
#elseif os(macOS)
hostingView.autoresizingMask = [.width, .height]
#endif
self.canvas.view = hostingView
Expand Down Expand Up @@ -177,7 +177,7 @@ public class AgoraSingleVideoView: MPView {
withConfiguration: UIImage.SymbolConfiguration(scale: .large)),
for: .normal
)
#else
#elseif os(macOS)
backgroundView.wantsLayer = true
backgroundView.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
let bgButton = MPButton()
Expand All @@ -193,7 +193,7 @@ public class AgoraSingleVideoView: MPView {
#if os(iOS)
bgButton.autoresizingMask = [.flexibleWidth, .flexibleHeight]
backgroundView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
#else
#elseif os(macOS)
bgButton.autoresizingMask = [.width, .height]
backgroundView.autoresizingMask = [.width, .height]
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/Agora-UIKit/AgoraUIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct AgoraUIKit: Codable {
/// Framework type of UIKit. "native", "flutter", "reactnative"
fileprivate(set) var framework: String
/// Version of UIKit being used
static let version = "4.0.0-preview.3"
static let version = "4.0.0-preview.4"
/// Framework type of UIKit. "native", "flutter", "reactnative"
static let framework = "native"
#if os(iOS)
Expand Down
Loading

0 comments on commit 877ad32

Please sign in to comment.