11import {
2- ChannelMediaOptions, Constants, RtcEngine, RtcEngineConfig, VideoCanvas,
3- VideoEncoderConfiguration
2+ ChannelMediaOptions,
3+ Constants,
4+ RtcEngine,
5+ RtcEngineConfig,
6+ VideoCanvas,
7+ VideoEncoderConfiguration
48} from 'AgoraRtcSdk';
59import { TitleBar } from '../../common/TitleBar';
610import Logger from '../../util/Logger';
@@ -32,12 +36,25 @@ struct JoinVideoChannelToken {
3236 let context = getContext(this) as common.UIAbilityContext;
3337 config.mAppId = appId;
3438 config.mEventHandler = {};
39+ config.mEventHandler.onRequestToken = () => {
40+ Logger.info(TAG, "onRequestToken ...");
41+ }
42+ config.mEventHandler.onTokenPrivilegeWillExpire = async (oldToken: string) => {
43+ Logger.info(TAG, `onTokenPrivilegeWillExpire oldToken = ${oldToken}`);
44+ //请求服务端重新生产token
45+ // this.token = getTokenFromServer()
46+ // this.rtcEngine?.renewToken(this.token)
47+ }
3548 config.mEventHandler.onUserJoined = (uid: number, collapse: number) => {
3649 Logger.info(TAG, "mEventHandler.onUserJoined: " + uid + " , " + collapse);
3750 if (this.remoteUid == 0) {
3851 this.remoteUid = uid;
3952 }
4053 };
54+ config.mEventHandler.onConnectionStateChanged =
55+ (state: Constants.ConnectionState, reason: Constants.ConnectionChangedReason) => {
56+ Logger.info(TAG, `onConnectionStateChanged state=${state} reason=${reason}`);
57+ }
4158 config.mEventHandler.onUserOffline = (uid: number, reason: number) => {
4259 Logger.info(TAG, "mEventHandler.onUserOffline: " + uid + " , " + reason);
4360 if (this.remoteUid == uid) {
@@ -143,7 +160,12 @@ struct JoinVideoChannelToken {
143160 this.appId = value
144161 })
145162 .flexGrow(0)
146- .margin({ left: 12, right: 12, top: 6, bottom: 6 })
163+ .margin({
164+ left: 12,
165+ right: 12,
166+ top: 6,
167+ bottom: 6
168+ })
147169
148170 TextInput({ placeholder: $r('app.string.token'), text: this.token })
149171 .id("input_token")
@@ -154,7 +176,12 @@ struct JoinVideoChannelToken {
154176 this.token = value
155177 })
156178 .flexGrow(0)
157- .margin({ left: 12, right: 12, top: 6, bottom: 6 })
179+ .margin({
180+ left: 12,
181+ right: 12,
182+ top: 6,
183+ bottom: 6
184+ })
158185
159186 Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) {
160187 TextInput({ placeholder: $r('app.string.text_input_channel_name'), text: this.channelName })
@@ -210,13 +237,17 @@ struct JoinVideoChannelToken {
210237 ShowToast.longToast("joinChannelWithOptions error " + ret + " : " + RtcEngine.getErrorDescription(ret))
211238 return
212239 }
213-
214240 this.rtcEngine?.startPreview()
215241 })
216242 .flexGrow(0)
217243 }
218244 }
219- .padding({ left: 12, right: 12, top: 6, bottom: 6 })
245+ .padding({
246+ left: 12,
247+ right: 12,
248+ top: 6,
249+ bottom: 6
250+ })
220251 }
221252 .backgroundColor($r('app.color.background_shallow_grey'))
222253 }
0 commit comments