Last active
December 7, 2021 11:17
-
-
Save maxxfrazer/0fbd817d6153a1daae931fb99a972e2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AgoraViewerHelper: AgoraVideoViewerDelegate { | |
static var agview: AgoraViewer = { | |
var agSettings = AgoraSettings() | |
agSettings.videoConfiguration = .init( | |
size: CGSize(width: 480, height: 360), frameRate: .fps24, | |
bitrate: AgoraVideoBitrateStandard, orientationMode: .fixedPortrait, | |
mirrorMode: .auto | |
) | |
agSettings.enabledButtons = [.cameraButton, .micButton, .flipButton] | |
return AgoraViewer( | |
connectionData: AgoraConnectionData( | |
appId: AppKeys.agoraAppId, rtcToken: AppKeys.agoraToken | |
), | |
style: .floating, | |
agoraSettings: agSettings, | |
delegate: AgoraViewerHelper.delegate | |
) | |
}() | |
var virtualBackgroundEnabled: Bool = false | |
static var delegate = AgoraViewerHelper() | |
func extraButtons() -> [UIButton] { | |
let button = UIButton() | |
button.setImage(UIImage( | |
systemName: "wand.and.stars", | |
withConfiguration: UIImage.SymbolConfiguration(scale: .large) | |
), for: .normal) | |
button.isSelected = self.virtualBackgroundEnabled | |
button.backgroundColor = self.virtualBackgroundEnabled ? .systemGreen : .systemGray | |
button.addTarget(self, action: #selector(self.toggleBackground), for: .touchUpInside) | |
return [button] | |
} | |
@objc func toggleBackground(_ sender: UIButton) { | |
virtualBackgroundEnabled.toggle() | |
sender.backgroundColor = self.virtualBackgroundEnabled ? .systemGreen : .systemGray | |
// more doresegment code will go here | |
} | |
func registerDoreSegment() { | |
// nothing yet | |
} | |
func joinedChannel(channel: String) { | |
registerDoreSegment() | |
// more doresegment code will go here | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State var joinedChannel: Bool = false | |
var body: some View { | |
ZStack { | |
AgoraViewerHelper.agview | |
if !joinedChannel { | |
Button("Join Channel") { | |
self.joinChannel() | |
} | |
} | |
} | |
} | |
func joinChannel() { | |
self.joinedChannel = true | |
AgoraViewerHelper.agview.join( | |
channel: "test", with: AppKeys.agoraToken, | |
as: .broadcaster | |
) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment