Skip to content

Commit 3d69464

Browse files
author
zhaoyongqiang
committed
fix preload channel
1 parent ec20a70 commit 3d69464

4 files changed

Lines changed: 47 additions & 45 deletions

File tree

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

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,69 +22,63 @@
2222
<rect key="frame" x="20" y="128" width="374" height="288"/>
2323
<subviews>
2424
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Enter channel name" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="GWc-L5-fZV" userLabel="channelName">
25-
<rect key="frame" x="37.5" y="80" width="299" height="44"/>
25+
<rect key="frame" x="37.5" y="20" width="299" height="44"/>
2626
<constraints>
2727
<constraint firstAttribute="height" constant="44" id="35y-W8-dsg"/>
2828
</constraints>
2929
<fontDescription key="fontDescription" type="system" pointSize="14"/>
3030
<textInputTraits key="textInputTraits"/>
3131
</textField>
3232
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="First Frame Optimization" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ohV-am-Acd">
33-
<rect key="frame" x="37" y="197" width="158.5" height="17"/>
33+
<rect key="frame" x="37" y="137" width="158.5" height="17"/>
3434
<fontDescription key="fontDescription" type="system" pointSize="14"/>
3535
<nil key="textColor"/>
3636
<nil key="highlightedColor"/>
3737
</label>
3838
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="1k3-bd-l8R">
39-
<rect key="frame" x="203" y="190" width="51" height="31"/>
39+
<rect key="frame" x="203" y="130" width="51" height="31"/>
4040
<connections>
4141
<action selector="doOptimizeFirstFrameSwitch:" destination="O0d-ef-mTa" eventType="valueChanged" id="ULE-eo-ces"/>
4242
</connections>
4343
</switch>
44-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kbN-ZR-nNn" userLabel="joinBtn">
45-
<rect key="frame" x="279" y="190" width="30" height="30"/>
46-
<state key="normal" title="Join"/>
47-
<connections>
48-
<action selector="doJoinPressedWithSender:" destination="O0d-ef-mTa" eventType="touchUpInside" id="pdy-Tj-ycl"/>
49-
</connections>
50-
</button>
51-
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="preload remote uid" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="KaL-W1-pfm">
52-
<rect key="frame" x="37" y="30" width="203" height="34"/>
53-
<fontDescription key="fontDescription" type="system" pointSize="14"/>
54-
<textInputTraits key="textInputTraits"/>
55-
</textField>
5644
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Q0N-nV-bez">
57-
<rect key="frame" x="28" y="142" width="119.5" height="35"/>
45+
<rect key="frame" x="28" y="82" width="119.5" height="35"/>
5846
<state key="normal" title="Button"/>
5947
<buttonConfiguration key="configuration" style="plain" title="default color"/>
6048
<connections>
6149
<action selector="doChoseBackgroundColor:" destination="O0d-ef-mTa" eventType="touchUpInside" id="kas-nl-lc9"/>
6250
</connections>
6351
</button>
64-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Audience role added, preloaded channel stream" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AAU-sM-2GN">
65-
<rect key="frame" x="37" y="8" width="308.5" height="17"/>
66-
<fontDescription key="fontDescription" type="system" pointSize="14"/>
67-
<color key="textColor" name="btnPanelBackground"/>
68-
<nil key="highlightedColor"/>
69-
</label>
52+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="S19-UR-C2c">
53+
<rect key="frame" x="28" y="184" width="146" height="35"/>
54+
<state key="normal" title="Button"/>
55+
<buttonConfiguration key="configuration" style="plain" title="preload channel"/>
56+
<connections>
57+
<action selector="onClickPreloadButton:" destination="O0d-ef-mTa" eventType="touchUpInside" id="uRz-q4-Bjn"/>
58+
</connections>
59+
</button>
60+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kbN-ZR-nNn" userLabel="joinBtn">
61+
<rect key="frame" x="213" y="186" width="30" height="30"/>
62+
<state key="normal" title="Join"/>
63+
<connections>
64+
<action selector="doJoinPressedWithSender:" destination="O0d-ef-mTa" eventType="touchUpInside" id="pdy-Tj-ycl"/>
65+
</connections>
66+
</button>
7067
</subviews>
7168
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
7269
<constraints>
7370
<constraint firstItem="1k3-bd-l8R" firstAttribute="top" secondItem="GWc-L5-fZV" secondAttribute="bottom" constant="66" id="13Z-tP-Rgb"/>
74-
<constraint firstItem="KaL-W1-pfm" firstAttribute="leading" secondItem="UzG-zY-iSA" secondAttribute="leading" constant="37" id="5eO-54-GY0"/>
7571
<constraint firstItem="ohV-am-Acd" firstAttribute="top" secondItem="GWc-L5-fZV" secondAttribute="bottom" constant="73" id="6R3-Em-K11"/>
76-
<constraint firstItem="kbN-ZR-nNn" firstAttribute="leading" secondItem="1k3-bd-l8R" secondAttribute="trailing" constant="27" id="7OA-ok-wZu"/>
72+
<constraint firstItem="kbN-ZR-nNn" firstAttribute="leading" secondItem="S19-UR-C2c" secondAttribute="trailing" constant="39" id="6WA-Qt-zCy"/>
7773
<constraint firstItem="1k3-bd-l8R" firstAttribute="leading" secondItem="ohV-am-Acd" secondAttribute="trailing" constant="7.5" id="AD9-TB-zbF"/>
78-
<constraint firstItem="AAU-sM-2GN" firstAttribute="top" secondItem="UzG-zY-iSA" secondAttribute="top" constant="8" id="C7z-Rg-EWA"/>
74+
<constraint firstItem="GWc-L5-fZV" firstAttribute="top" secondItem="UzG-zY-iSA" secondAttribute="top" constant="20" id="Aw7-EV-2aa"/>
75+
<constraint firstItem="kbN-ZR-nNn" firstAttribute="top" secondItem="1k3-bd-l8R" secondAttribute="bottom" constant="25" id="DUD-59-ryB"/>
7976
<constraint firstItem="GWc-L5-fZV" firstAttribute="leading" secondItem="UzG-zY-iSA" secondAttribute="leading" constant="37.5" id="Fzh-Ry-Cyf"/>
8077
<constraint firstItem="Q0N-nV-bez" firstAttribute="top" secondItem="GWc-L5-fZV" secondAttribute="bottom" constant="18" id="LHA-IH-a4H"/>
78+
<constraint firstItem="S19-UR-C2c" firstAttribute="leading" secondItem="UzG-zY-iSA" secondAttribute="leading" constant="28" id="M4y-zq-16B"/>
8179
<constraint firstItem="ohV-am-Acd" firstAttribute="leading" secondItem="UzG-zY-iSA" secondAttribute="leading" constant="37" id="U0S-YA-fEo"/>
82-
<constraint firstItem="KaL-W1-pfm" firstAttribute="top" secondItem="UzG-zY-iSA" secondAttribute="top" constant="30" id="Vmf-b6-ur3"/>
83-
<constraint firstItem="GWc-L5-fZV" firstAttribute="top" secondItem="KaL-W1-pfm" secondAttribute="bottom" constant="16" id="ZfA-04-6xo"/>
84-
<constraint firstAttribute="trailing" secondItem="KaL-W1-pfm" secondAttribute="trailing" constant="134" id="Zzb-8O-e9W"/>
80+
<constraint firstItem="S19-UR-C2c" firstAttribute="top" secondItem="ohV-am-Acd" secondAttribute="bottom" constant="30" id="ahx-nB-ru9"/>
8581
<constraint firstAttribute="height" constant="288" id="c9y-rL-vhW"/>
86-
<constraint firstItem="kbN-ZR-nNn" firstAttribute="top" secondItem="GWc-L5-fZV" secondAttribute="bottom" constant="66" id="m85-6c-puk"/>
87-
<constraint firstItem="AAU-sM-2GN" firstAttribute="leading" secondItem="UzG-zY-iSA" secondAttribute="leading" constant="37" id="txY-vA-g0e"/>
8882
<constraint firstItem="Q0N-nV-bez" firstAttribute="leading" secondItem="UzG-zY-iSA" secondAttribute="leading" constant="28" id="ysb-57-hko"/>
8983
<constraint firstAttribute="trailing" secondItem="GWc-L5-fZV" secondAttribute="trailing" constant="37.5" id="ze4-ah-O7j"/>
9084
</constraints>
@@ -101,7 +95,7 @@
10195
<connections>
10296
<outlet property="channelTextField" destination="GWc-L5-fZV" id="xDy-ai-JdS"/>
10397
<outlet property="joinButton" destination="kbN-ZR-nNn" id="kkw-5w-Nnv"/>
104-
<outlet property="preloadTextField" destination="KaL-W1-pfm" id="ycv-bE-yFx"/>
98+
<outlet property="preloadButton" destination="S19-UR-C2c" id="QYb-aJ-DMZ"/>
10599
</connections>
106100
</viewController>
107101
<placeholder placeholderIdentifier="IBFirstResponder" id="DXe-2A-qSu" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import AgoraRtcKit
1212
class LiveStreamingEntry : UIViewController
1313
{
1414
@IBOutlet weak var joinButton: UIButton!
15-
@IBOutlet weak var preloadTextField: UITextField!
15+
@IBOutlet weak var preloadButton: UIButton!
1616
@IBOutlet weak var channelTextField: UITextField!
1717
let identifier = "LiveStreaming"
1818
var role:AgoraClientRole = .broadcaster
@@ -21,6 +21,8 @@ class LiveStreamingEntry : UIViewController
2121

2222
override func viewDidLoad() {
2323
super.viewDidLoad()
24+
preloadButton.setTitle("preload Channel".localized, for: .normal)
25+
preloadButton.setTitle("cancel preload".localized, for: .selected)
2426
}
2527

2628
func getRoleAction(_ role: AgoraClientRole) -> UIAlertAction{
@@ -30,6 +32,14 @@ class LiveStreamingEntry : UIViewController
3032
})
3133
}
3234

35+
@IBAction func onClickPreloadButton(_ sender: UIButton) {
36+
if channelTextField.text?.isEmpty == true {
37+
ToastView.show(text: "please input channel name!".localized)
38+
return
39+
}
40+
sender.isSelected = !sender.isSelected
41+
}
42+
3343
@IBAction func doOptimizeFirstFrameSwitch(_ sender: UISwitch) {
3444
if sender.isOn {
3545
let alertVC = UIAlertController(title: "After this function is enabled, it cannot be disabled and takes effect only when both the primary and secondary ends are enabled".localized,
@@ -88,7 +98,7 @@ class LiveStreamingEntry : UIViewController
8898
newViewController.configs = ["channelName":channelName,
8999
"role":self.role,
90100
"isFirstFrame": isFirstFrame,
91-
"preloadUid": preloadTextField.text ?? "",
101+
"isPreloadChannel": preloadButton.isSelected,
92102
"backgroundColor": backgroundColor]
93103
navigationController?.pushViewController(newViewController, animated: true)
94104
}
@@ -166,15 +176,6 @@ class LiveStreamingMain: BaseViewController {
166176
// get channel name from configs
167177
guard let channelName = configs["channelName"] as? String, let clientRole = configs["role"] as? AgoraClientRole else {return}
168178

169-
if let preloadUid = UInt(configs["preloadUid"] as? String ?? ""),
170-
role == .audience {
171-
NetworkManager.shared.generateToken(channelName: channelName, uid: preloadUid, success: { token in
172-
self.agoraKit.preloadChannel(byToken: token,
173-
channelId: channelName,
174-
uid: preloadUid)
175-
})
176-
}
177-
178179
role = clientRole
179180
// for audience put local video in foreground
180181
isLocalVideoForeground = role == .audience
@@ -202,6 +203,12 @@ class LiveStreamingMain: BaseViewController {
202203
option.publishMicrophoneTrack = role == .broadcaster
203204
option.clientRoleType = role
204205
NetworkManager.shared.generateToken(channelName: channelName, success: { token in
206+
let preloadChannel = self.configs["isPreloadChannel"] as? Bool
207+
if preloadChannel == true {
208+
self.agoraKit.preloadChannel(byToken: token,
209+
channelId: channelName,
210+
uid: 0)
211+
}
205212
let result = self.agoraKit.joinChannel(byToken: token, channelId: channelName, uid: 0, mediaOptions: option)
206213
if result != 0 {
207214
// Usually happens with invalid parameters

iOS/APIExample/APIExample/Examples/Advanced/LiveStreaming/zh-Hans.lproj/LiveStreaming.strings

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
"ohV-am-Acd.text" = "首帧出图";
1515

16-
"KaL-W1-pfm.placeholder" = "输入秒开远端uid";
17-
1816
"Q0N-nV-bez.normalTitle" = "默认背景色";
1917

20-
"AAU-sM-2GN.text" = "观众角色加入, 预加载频道流";
18+
"S19-UR-C2c.normalTitle" = "预加载";
19+
"S19-UR-C2c.selectTitle" = "取消预加载";

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,5 @@
162162
"Pink" = "粉色";
163163
"Purple" = "紫色";
164164
"Yellow" = "黄色";
165+
"preload Channel" = "预加载";
166+
"cancel preload" = "取消预加载";

0 commit comments

Comments
 (0)