Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26a6180

Browse files
author
xia ning
authored
Merge pull request AgoraIO#106 from AgoraIO/dev/GlobalSettings
Dev/global settings
2 parents 4d05060 + c2a0d1a commit 26a6180

File tree

4 files changed

+100
-29
lines changed

4 files changed

+100
-29
lines changed

iOS/APIExample/Common/UITypeAlias.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ extension UIColor {
8383
}
8484

8585
extension UIView {
86-
8786
/// Adds constraints to this `UIView` instances `superview` object to make sure this always has the same size as the superview.
8887
/// Please note that this has no effect if its `superview` is `nil` – add this `UIView` instance as a subview before calling this.
8988
func bindFrameToSuperviewBounds() {

iOS/APIExample/Examples/Advanced/LiveStreaming/Base.lproj/LiveStreaming.storyboard

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3-
<device id="retina6_1" orientation="portrait" appearance="dark"/>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
77
<capability name="Named colors" minToolsVersion="9.0"/>
88
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
9+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
910
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1011
</dependencies>
1112
<scenes>
@@ -25,15 +26,15 @@
2526
<fontDescription key="fontDescription" type="system" pointSize="14"/>
2627
<textInputTraits key="textInputTraits"/>
2728
</textField>
28-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kbN-ZR-nNn" userLabel="joinBtn">
29+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kbN-ZR-nNn" userLabel="joinBtn">
2930
<rect key="frame" x="172" y="74" width="30" height="30"/>
3031
<state key="normal" title="Join"/>
3132
<connections>
3233
<action selector="doJoinPressedWithSender:" destination="O0d-ef-mTa" eventType="touchUpInside" id="pdy-Tj-ycl"/>
3334
</connections>
3435
</button>
3536
</subviews>
36-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
37+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
3738
<constraints>
3839
<constraint firstItem="kbN-ZR-nNn" firstAttribute="top" secondItem="GWc-L5-fZV" secondAttribute="bottom" constant="20" id="LVQ-Cs-yOU"/>
3940
<constraint firstItem="kbN-ZR-nNn" firstAttribute="centerX" secondItem="GWc-L5-fZV" secondAttribute="centerX" id="RUT-ez-nDw"/>
@@ -44,13 +45,13 @@
4445
</constraints>
4546
</view>
4647
</subviews>
47-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
48+
<viewLayoutGuide key="safeArea" id="wDs-Gr-g1S"/>
49+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
4850
<constraints>
4951
<constraint firstItem="UzG-zY-iSA" firstAttribute="centerY" secondItem="wDs-Gr-g1S" secondAttribute="centerY" multiplier="0.8" id="8bT-wH-NDK"/>
5052
<constraint firstItem="UzG-zY-iSA" firstAttribute="leading" secondItem="wDs-Gr-g1S" secondAttribute="leading" constant="20" id="BQh-SU-OA6"/>
5153
<constraint firstItem="wDs-Gr-g1S" firstAttribute="trailing" secondItem="UzG-zY-iSA" secondAttribute="trailing" constant="20" id="gHu-5I-6Gb"/>
5254
</constraints>
53-
<viewLayoutGuide key="safeArea" id="wDs-Gr-g1S"/>
5455
</view>
5556
<connections>
5657
<outlet property="channelTextField" destination="GWc-L5-fZV" id="xDy-ai-JdS"/>
@@ -71,14 +72,18 @@
7172
<subviews>
7273
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="q9v-1n-ZYf">
7374
<rect key="frame" x="0.0" y="44" width="414" height="818"/>
74-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
75+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
7576
</view>
7677
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="XSO-cE-x5n">
7778
<rect key="frame" x="257.5" y="54" width="136.5" height="182"/>
78-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
79+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
80+
<gestureRecognizers/>
7981
<constraints>
8082
<constraint firstAttribute="width" secondItem="XSO-cE-x5n" secondAttribute="height" multiplier="3:4" id="Bux-mO-Qgq"/>
8183
</constraints>
84+
<connections>
85+
<outletCollection property="gestureRecognizers" destination="yDz-VT-Yop" appends="YES" id="grI-uM-Mpw"/>
86+
</connections>
8287
</view>
8388
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Uwe-Fi-04a" userLabel="CoHost">
8489
<rect key="frame" x="20" y="783" width="132" height="44"/>
@@ -172,7 +177,8 @@
172177
</constraints>
173178
</view>
174179
</subviews>
175-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
180+
<viewLayoutGuide key="safeArea" id="CeS-QQ-Djo"/>
181+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
176182
<constraints>
177183
<constraint firstItem="Uwe-Fi-04a" firstAttribute="leading" secondItem="CeS-QQ-Djo" secondAttribute="leading" constant="20" id="0oI-Iz-1eG"/>
178184
<constraint firstItem="XSO-cE-x5n" firstAttribute="top" secondItem="CeS-QQ-Djo" secondAttribute="top" constant="10" id="1HU-w7-YYi"/>
@@ -186,16 +192,22 @@
186192
<constraint firstItem="CeS-QQ-Djo" firstAttribute="trailing" secondItem="q9v-1n-ZYf" secondAttribute="trailing" id="isT-Rq-5PH"/>
187193
<constraint firstItem="Uwe-Fi-04a" firstAttribute="top" secondItem="Wts-5Z-p7a" secondAttribute="bottom" constant="10" id="wl5-PM-CyG"/>
188194
</constraints>
189-
<viewLayoutGuide key="safeArea" id="CeS-QQ-Djo"/>
190195
</view>
191196
<connections>
197+
<outlet property="backgroundVideoContainer" destination="q9v-1n-ZYf" id="ADa-RX-kZg"/>
192198
<outlet property="clientRoleToggle" destination="7iE-Y0-bQi" id="xF0-48-qAP"/>
193-
<outlet property="localVideoContainer" destination="XSO-cE-x5n" id="1XV-B8-ry9"/>
194-
<outlet property="remoteVideoContainer" destination="q9v-1n-ZYf" id="WST-Vv-Jjj"/>
199+
<outlet property="clientRoleToggleView" destination="Uwe-Fi-04a" id="oys-Z9-DtO"/>
200+
<outlet property="foregroundVideoContainer" destination="XSO-cE-x5n" id="7GG-yW-hDg"/>
195201
<outlet property="ultraLowLatencyToggle" destination="cbb-WI-53A" id="n3x-pK-MuE"/>
202+
<outlet property="ultraLowLatencyToggleView" destination="Wts-5Z-p7a" id="HI8-ov-5iY"/>
196203
</connections>
197204
</viewController>
198205
<placeholder placeholderIdentifier="IBFirstResponder" id="8dQ-Wz-bG7" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
206+
<tapGestureRecognizer id="yDz-VT-Yop">
207+
<connections>
208+
<action selector="onTapForegroundVideo:" destination="jxp-ZN-2yG" id="GIx-yy-Bev"/>
209+
</connections>
210+
</tapGestureRecognizer>
199211
</objects>
200212
<point key="canvasLocation" x="3130" y="931"/>
201213
</scene>
@@ -207,5 +219,8 @@
207219
<namedColor name="btnPanelForeground">
208220
<color red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
209221
</namedColor>
222+
<systemColor name="systemBackgroundColor">
223+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
224+
</systemColor>
210225
</resources>
211226
</document>

iOS/APIExample/Examples/Advanced/LiveStreaming/LiveStreaming.swift

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,37 @@ class LiveStreamingEntry : UIViewController
5353
}
5454

5555
class LiveStreamingMain: BaseViewController {
56-
var localVideo = Bundle.loadView(fromNib: "VideoView", withType: VideoView.self)
57-
var remoteVideo = Bundle.loadView(fromNib: "VideoView", withType: VideoView.self)
58-
@IBOutlet weak var localVideoContainer:UIView!
59-
@IBOutlet weak var remoteVideoContainer:UIView!
56+
var foregroundVideo = Bundle.loadView(fromNib: "VideoView", withType: VideoView.self)
57+
var backgroundVideo = Bundle.loadView(fromNib: "VideoView", withType: VideoView.self)
58+
@IBOutlet weak var foregroundVideoContainer:UIView!
59+
@IBOutlet weak var backgroundVideoContainer:UIView!
60+
@IBOutlet weak var clientRoleToggleView:UIView!
61+
@IBOutlet weak var ultraLowLatencyToggleView:UIView!
6062
@IBOutlet weak var clientRoleToggle:UISwitch!
6163
@IBOutlet weak var ultraLowLatencyToggle:UISwitch!
64+
var remoteUid: UInt? {
65+
didSet {
66+
foregroundVideoContainer.isHidden = !(role == .broadcaster && remoteUid != nil)
67+
}
68+
}
6269
var agoraKit: AgoraRtcEngineKit!
6370
var role: AgoraClientRole = .broadcaster {
6471
didSet {
65-
localVideoContainer.isHidden = role != .broadcaster
72+
foregroundVideoContainer.isHidden = !(role == .broadcaster && remoteUid != nil)
6673
ultraLowLatencyToggle.isEnabled = role == .audience
6774
}
6875
}
76+
var isLocalVideoForeground = false {
77+
didSet {
78+
if isLocalVideoForeground {
79+
foregroundVideo.setPlaceholder(text: "Local Host".localized)
80+
backgroundVideo.setPlaceholder(text: "Remote Host".localized)
81+
} else {
82+
foregroundVideo.setPlaceholder(text: "Remote Host".localized)
83+
backgroundVideo.setPlaceholder(text: "Local Host".localized)
84+
}
85+
}
86+
}
6987
var isUltraLowLatencyOn: Bool = false
7088

7189
// indicate if current instance has joined channel
@@ -75,12 +93,10 @@ class LiveStreamingMain: BaseViewController {
7593
super.viewDidLoad()
7694

7795
// layout render view
78-
localVideoContainer.addSubview(localVideo)
79-
remoteVideoContainer.addSubview(remoteVideo)
80-
localVideo.setPlaceholder(text: "Local Host".localized)
81-
localVideo.bindFrameToSuperviewBounds()
82-
remoteVideo.setPlaceholder(text: "Remote Host".localized)
83-
remoteVideo.bindFrameToSuperviewBounds()
96+
foregroundVideoContainer.addSubview(foregroundVideo)
97+
backgroundVideoContainer.addSubview(backgroundVideo)
98+
foregroundVideo.bindFrameToSuperviewBounds()
99+
backgroundVideo.bindFrameToSuperviewBounds()
84100

85101
// set up agora instance when view loadedlet config = AgoraRtcEngineConfig()
86102
let config = AgoraRtcEngineConfig()
@@ -92,6 +108,12 @@ class LiveStreamingMain: BaseViewController {
92108
guard let channelName = configs["channelName"] as? String,
93109
let role = configs["role"] as? AgoraClientRole else {return}
94110

111+
// for audience put local video in foreground
112+
isLocalVideoForeground = role == .audience
113+
// if inital role is broadcaster, do not show audience options
114+
clientRoleToggleView.isHidden = role == .broadcaster
115+
ultraLowLatencyToggleView.isHidden = role == .broadcaster
116+
95117
// make this room live broadcasting room
96118
agoraKit.setChannelProfile(.liveBroadcasting)
97119
updateClientRole(role)
@@ -108,7 +130,7 @@ class LiveStreamingMain: BaseViewController {
108130
// 2. If app certificate is turned on at dashboard, token is needed
109131
// when joining channel. The channel name and uid used to calculate
110132
// the token has to match the ones used for channel join
111-
let result = agoraKit.joinChannel(byToken: nil, channelId: channelName, info: nil, uid: SCREEN_SHARE_BROADCASTER_UID) {[unowned self] (channel, uid, elapsed) -> Void in
133+
let result = agoraKit.joinChannel(byToken: nil, channelId: channelName, info: nil, uid: 0) {[unowned self] (channel, uid, elapsed) -> Void in
112134
self.isJoined = true
113135
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
114136
}
@@ -138,7 +160,7 @@ class LiveStreamingMain: BaseViewController {
138160
let videoCanvas = AgoraRtcVideoCanvas()
139161
videoCanvas.uid = 0
140162
// the view to be binded
141-
videoCanvas.view = localVideo.videoView
163+
videoCanvas.view = localVideoCanvas()
142164
videoCanvas.renderMode = .hidden
143165
agoraKit.setupLocalVideo(videoCanvas)
144166

@@ -159,6 +181,33 @@ class LiveStreamingMain: BaseViewController {
159181
agoraKit.setClientRole(.audience, options: options)
160182
}
161183

184+
func localVideoCanvas() -> UIView {
185+
return isLocalVideoForeground ? foregroundVideo.videoView : backgroundVideo.videoView
186+
}
187+
188+
func remoteVideoCanvas() -> UIView {
189+
return isLocalVideoForeground ? backgroundVideo.videoView : foregroundVideo.videoView
190+
}
191+
192+
@IBAction func onTapForegroundVideo(_ sender:UIGestureRecognizer) {
193+
isLocalVideoForeground = !isLocalVideoForeground
194+
195+
let localVideoCanvas = AgoraRtcVideoCanvas()
196+
localVideoCanvas.uid = 0
197+
localVideoCanvas.renderMode = .hidden
198+
localVideoCanvas.view = self.localVideoCanvas()
199+
200+
let remoteVideoCanvas = AgoraRtcVideoCanvas()
201+
remoteVideoCanvas.renderMode = .hidden
202+
remoteVideoCanvas.view = self.remoteVideoCanvas()
203+
204+
agoraKit.setupLocalVideo(localVideoCanvas)
205+
if let uid = remoteUid {
206+
remoteVideoCanvas.uid = uid
207+
agoraKit.setupRemoteVideo(remoteVideoCanvas)
208+
}
209+
}
210+
162211
@IBAction func onToggleClientRole(_ sender:UISwitch) {
163212
let role:AgoraClientRole = sender.isOn ? .broadcaster : .audience
164213
updateClientRole(role)
@@ -227,13 +276,16 @@ extension LiveStreamingMain: AgoraRtcEngineDelegate {
227276
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinedOfUid uid: UInt, elapsed: Int) {
228277
LogUtils.log(message: "remote user join: \(uid) \(elapsed)ms", level: .info)
229278

279+
//record remote uid
280+
remoteUid = uid
281+
230282
// Only one remote video view is available for this
231283
// tutorial. Here we check if there exists a surface
232284
// view tagged as this uid.
233285
let videoCanvas = AgoraRtcVideoCanvas()
234286
videoCanvas.uid = uid
235287
// the view to be binded
236-
videoCanvas.view = remoteVideo.videoView
288+
videoCanvas.view = remoteVideoCanvas()
237289
videoCanvas.renderMode = .hidden
238290
agoraKit.setupRemoteVideo(videoCanvas)
239291
}
@@ -245,6 +297,11 @@ extension LiveStreamingMain: AgoraRtcEngineDelegate {
245297
func rtcEngine(_ engine: AgoraRtcEngineKit, didOfflineOfUid uid: UInt, reason: AgoraUserOfflineReason) {
246298
LogUtils.log(message: "remote user left: \(uid) reason \(reason)", level: .info)
247299

300+
//clear remote uid
301+
if(remoteUid == uid){
302+
remoteUid = nil
303+
}
304+
248305
// to unlink your view from sdk, so that your view reference will be released
249306
// note the video will stay at its last frame, to completely remove it
250307
// you will need to remove the EAGL sublayer from your binded view

iOS/APIExample/zh-Hans.lproj/Localizable.strings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
"Join a channel (Video)" = "实时视频通话/直播";
1010
"Join a channel (Audio)" = "实时语音通话/直播";
11-
"Live Streaming" = "RTC实时直播";
11+
"Live Streaming" = "RTC实时直播/主播/观众";
1212
"RTMP Streaming" = "RTMP旁路推流";
1313
"Media Injection" = "流媒体注入";
1414
"Video Metadata" = "SEI消息";

0 commit comments

Comments
 (0)