Skip to content

Commit

Permalink
Merge pull request #5 from AgoraIO-Community/swiftui-init
Browse files Browse the repository at this point in the history
SwiftUI
  • Loading branch information
maxxfrazer authored Jan 4, 2021
2 parents 7607bfa + 43659c6 commit 0a6f612
Show file tree
Hide file tree
Showing 44 changed files with 1,877 additions and 72 deletions.
403 changes: 403 additions & 0 deletions Agora-SwiftUI-Example/Agora-SwiftUI-Example.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Agora_SwiftUI_ExampleApp.swift
// Agora-SwiftUI-Example
//
// Created by Max Cobb on 29/12/2020.
//

import SwiftUI

@main
struct Agora_SwiftUI_ExampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
79 changes: 79 additions & 0 deletions Agora-SwiftUI-Example/Agora-SwiftUI-Example/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// ContentView.swift
// Agora-SwiftUI-Example
//
// Created by Max Cobb on 29/12/2020.
//

import SwiftUI
import AgoraUIKit_iOS

struct ContentView: View {
@State private var connectedToChannel = false

let agview = AgoraViewer(
connectionData: AgoraConnectionData(
appId: <#Agora App ID#>,
appToken: <#Agora Token or nil#>
),
style: .floating
)

@State private var agoraViewerStyle = 0
var body: some View {
ZStack {
agview
VStack {
Picker("Format", selection: $agoraViewerStyle) {
Text("Floating").tag(0)
Text("Grid").tag(1)
}.pickerStyle(SegmentedPickerStyle())
.frame(
minWidth: 0, idealWidth: 100, maxWidth: 200,
minHeight: 0, idealHeight: 40, maxHeight: .infinity, alignment: .topTrailing
).onChange(
of: agoraViewerStyle,
perform: {
self.agview.viewer.style = $0 == 0 ? .floating : .grid
}
)
Spacer()
HStack {
Spacer()
Button(
action: { connectToAgora() },
label: {
if connectedToChannel {
Text("Disconnect").padding(3.0).background(Color.red).cornerRadius(3.0).hidden()
} else {
Text("Connect").padding(3.0).background(Color.green).cornerRadius(3.0)
}
}
).disabled(connectedToChannel)
Spacer()
}
Spacer()
}
}

}

func connectToAgora() {
guard agview.viewer.checkForPermissions(alsoRequest: true) else {
connectToAgora()
return
}
connectedToChannel.toggle()
if connectedToChannel {
agview.join(channel: "test", with: nil, as: .broadcaster)
} else {
agview.viewer.leaveChannel()
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
56 changes: 56 additions & 0 deletions Agora-SwiftUI-Example/Agora-SwiftUI-Example/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>So the audience and other broadcasters can see you</string>
<key>NSLocalNetworkUsageDescription</key>
<string></string>
<key>NSMicrophoneUsageDescription</key>
<string>So the audience and other broadcasters can hear you</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchScreen</key>
<dict/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
11 changes: 11 additions & 0 deletions Agora-SwiftUI-Example/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Uncomment the next line to define a global platform for your project
platform :ios, '13.0'

target 'Agora-SwiftUI-Example' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for Agora-UIKit-Example
pod 'AgoraUIKit_iOS', :path => '../'

end
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 = '1.0.3'
s.version = '1.1.0'
s.summary = 'Agora video session UIKit template.'

s.description = <<-DESC
Expand Down
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.0.3'
s.version = '1.1.0'
s.summary = 'Agora video session AppKit template.'

s.description = <<-DESC
Expand Down
42 changes: 23 additions & 19 deletions Sources/Agora-UIKit/AgoraVideoViewer+Buttons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,30 @@ import AppKit
// leaveChannel, toggleCam, toggleMic, flipCamera, toggleBroadcast, toggleBeautify

extension AgoraVideoViewer {
fileprivate func positionButtonContainer(_ container: MPBlurView, _ contWidth: CGFloat, _ buttonMargin: CGFloat) {
#if os(iOS)
container.frame = CGRect(
origin: CGPoint(
x: (self.bounds.width - CGFloat(contWidth)) / 2,
y: (self.bounds.height - 60 - 20 - 10)
), size: CGSize(width: contWidth, height: 60 + buttonMargin * 2)
)
container.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin]
container.layer.cornerRadius = 20
container.clipsToBounds = true
#else
container.frame = CGRect(
origin: CGPoint(x: (self.bounds.width - CGFloat(contWidth)) / 2, y: 10),
size: CGSize(width: contWidth, height: 60 + 20))
container.autoresizingMask = [.minXMargin, .maxXMargin, .maxYMargin]
container.layer?.cornerRadius = 20
#endif
}

/// Add all the relevant buttons.
/// The buttons are set to add to their respective parent views
/// Whenever called, so I'm discarding the result for most of them here.
func addVideoButtons() {
internal func addVideoButtons() {
let container = self.getControlContainer()
let buttons = [
self.getCameraButton(), self.getMicButton(), self.getFlipButton(), self.getBeautifyButton(),
Expand Down Expand Up @@ -55,23 +75,7 @@ extension AgoraVideoViewer {
#endif
})
let contWidth = CGFloat(buttons.count) * (60 + buttonMargin) + buttonMargin
#if os(iOS)
container.frame = CGRect(
origin: CGPoint(
x: (self.bounds.width - CGFloat(contWidth)) / 2,
y: (self.bounds.height - 60 - 20 - 10)
), size: CGSize(width: contWidth, height: 60 + buttonMargin * 2)
)
container.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin]
container.layer.cornerRadius = 20
container.clipsToBounds = true
#else
container.frame = CGRect(
origin: CGPoint(x: (self.bounds.width - CGFloat(contWidth)) / 2, y: 10),
size: CGSize(width: contWidth, height: 60 + 20))
container.autoresizingMask = [.minXMargin, .maxXMargin, .maxYMargin]
container.layer?.cornerRadius = 20
#endif
positionButtonContainer(container, contWidth, buttonMargin)
}

internal func getControlContainer() -> MPBlurView {
Expand Down Expand Up @@ -152,7 +156,6 @@ extension AgoraVideoViewer {
return button
#endif
}


// func prepareSystemBroadcaster() {
// let frame = CGRect(x: 0, y:0, width: 60, height: 60)
Expand All @@ -165,6 +168,7 @@ extension AgoraVideoViewer {
// }
// self.addSubview(systemBroadcastPicker)
// }

/// Get the button for flipping the camera from front to rear facing
/// - Returns: The button for flipping the camera if enabled, otherwise nil
open func getFlipButton() -> MPButton? {
Expand Down
1 change: 0 additions & 1 deletion Sources/Agora-UIKit/AgoraVideoViewer+VideoControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ extension AgoraVideoViewer {
#endif
}


func startSharingScreen(displayId: UInt = 0) {
#if os(macOS)
let rectangle = CGRect.zero
Expand Down
Loading

0 comments on commit 0a6f612

Please sign in to comment.