|
@@ -38,6 +38,7 @@ export class LiveComponent implements OnInit {
|
|
|
audioTrack: null,
|
|
|
videoTrack: null,
|
|
|
};
|
|
|
+ changeScreen: boolean = false; //大小屏切换
|
|
|
constructor(
|
|
|
public toastController: ToastController,
|
|
|
private loadingCtrl: LoadingController,
|
|
@@ -47,7 +48,7 @@ export class LiveComponent implements OnInit {
|
|
|
) {}
|
|
|
|
|
|
ngOnInit() {
|
|
|
- this.client = AgoraRTC.createClient({ mode: 'live', codec: 'h264' });
|
|
|
+ this.client = AgoraRTC.createClient({ mode: 'rtc', codec: 'h264' });
|
|
|
AgoraRTC.enableLogUpload();
|
|
|
this.getDevices();
|
|
|
this.activateRoute.paramMap.subscribe(async (params) => {
|
|
@@ -69,9 +70,8 @@ export class LiveComponent implements OnInit {
|
|
|
const videoDevices = devices.filter(function (device: any) {
|
|
|
return device.kind === 'videoinput';
|
|
|
});
|
|
|
-
|
|
|
- var selectedMicrophoneId = audioDevices[0].deviceId;
|
|
|
- var selectedCameraId = videoDevices[0].deviceId;
|
|
|
+ let selectedMicrophoneId = audioDevices[0].deviceId;
|
|
|
+ let selectedCameraId = videoDevices[0].deviceId;
|
|
|
return Promise.all([
|
|
|
AgoraRTC.createCameraVideoTrack({ cameraId: selectedCameraId }),
|
|
|
AgoraRTC.createMicrophoneAudioTrack({
|
|
@@ -96,18 +96,18 @@ export class LiveComponent implements OnInit {
|
|
|
queryProfile.equalTo('user', this.room?.get('user').id);
|
|
|
queryProfile.notEqualTo('isDeleted', true);
|
|
|
this.profile = await queryProfile.first();
|
|
|
- this.getToken()
|
|
|
+ this.getToken();
|
|
|
}
|
|
|
async getToken() {
|
|
|
let baseurl = 'https://server.fmode.cn/api/webrtc/build_token';
|
|
|
let reqBody = {
|
|
|
- company:'9aMy8gAuey',// this.aiSer.company,
|
|
|
+ company: '9aMy8gAuey', // this.aiSer.company,
|
|
|
profile: this.profile?.id,
|
|
|
channelName: this.profile?.id,
|
|
|
// department: localStorage.getItem('department'),
|
|
|
// exam: localStorage.getItem('exam'),
|
|
|
};
|
|
|
- let data: any = await this.http.httpRequst(baseurl, reqBody,'POST');
|
|
|
+ let data: any = await this.http.httpRequst(baseurl, reqBody, 'POST');
|
|
|
console.log(data);
|
|
|
if (data.code == 200) {
|
|
|
(this.options.token = data.data.token),
|
|
@@ -120,41 +120,28 @@ export class LiveComponent implements OnInit {
|
|
|
// 进入频道
|
|
|
async join() {
|
|
|
let data = await Promise.all([
|
|
|
- // join the channel
|
|
|
this.client.join(
|
|
|
this.options.appid,
|
|
|
this.options.channel,
|
|
|
this.options.token,
|
|
|
111111
|
|
|
),
|
|
|
-
|
|
|
- // create local tracks, using microphone and camera
|
|
|
+ /* 创建音频和视频轨道 */
|
|
|
AgoraRTC.createMicrophoneAudioTrack(),
|
|
|
AgoraRTC.createCameraVideoTrack(),
|
|
|
]);
|
|
|
- await this.client.setClientRole('host');
|
|
|
+ // await this.client.setClientRole('host');
|
|
|
this.localTracks.audioTrack = data[1];
|
|
|
this.localTracks.videoTrack = data[2];
|
|
|
- this.localTracks.videoTrack.play('video');
|
|
|
+ let remoteEle = document.getElementById('vice-video');
|
|
|
+ if (remoteEle) {
|
|
|
+ remoteEle.textContent = '';
|
|
|
+ }
|
|
|
+ this.localTracks.videoTrack.play('vice-video'); //播放自己视频渲染
|
|
|
let publish = await this.client.publish(Object.values(this.localTracks));
|
|
|
-
|
|
|
- // getCurrentFrameData 获取当前渲染的视频帧数据。
|
|
|
- // 订阅监考端音视频
|
|
|
- this.client.on('user-published', async (user: any, mediaType: any) => {
|
|
|
- console.log('user-published');
|
|
|
- await this.client.subscribe(user, mediaType);
|
|
|
- if (mediaType == 'audio' && user.uid != 333333) {
|
|
|
- console.log(mediaType, user);
|
|
|
- //远端老师发出语音对话提示
|
|
|
- // this.createBasicNotification('请注意,监考老师已向你发出语音通话!', 'info', '语音通话提示')
|
|
|
- const remoteAudioTrack = user.audioTrack;
|
|
|
- remoteAudioTrack.setVolume(100);
|
|
|
- remoteAudioTrack.play();
|
|
|
- }
|
|
|
- });
|
|
|
- // 查询远端用户是否存在小程序端用户
|
|
|
this.joinReady();
|
|
|
}
|
|
|
+ /* 订阅远程视频 */
|
|
|
async joinReady() {
|
|
|
console.log(this.client.remoteUsers);
|
|
|
let wxRemoteUsers = this.client.remoteUsers.find((item: any) => {
|
|
@@ -163,16 +150,46 @@ export class LiveComponent implements OnInit {
|
|
|
}
|
|
|
});
|
|
|
console.log(wxRemoteUsers);
|
|
|
+ this.client.on('user-joined', (user: any) => {
|
|
|
+ console.log(user, `${user.uid} 加入频道`);
|
|
|
+ });
|
|
|
this.client.on('user-published', async (user: any, mediaType: any) => {
|
|
|
- if (user.uid == 333333) {
|
|
|
- await this.client.subscribe(user, mediaType);
|
|
|
- console.log('用户推流成功');
|
|
|
+ console.log('用户推流成功');
|
|
|
+ // if (user.uid == 333333) {
|
|
|
+ await this.client.subscribe(user, mediaType);
|
|
|
+ // }
|
|
|
+ let remoteEle = document.getElementById('video');
|
|
|
+ if (remoteEle) {
|
|
|
+ remoteEle.textContent = '';
|
|
|
+ }
|
|
|
+ if (mediaType === 'video') {
|
|
|
+ user.videoTrack.play(`video`);
|
|
|
+ }
|
|
|
+ if (mediaType === 'audio') {
|
|
|
+ user.audioTrack.play();
|
|
|
}
|
|
|
});
|
|
|
this.client.on('user-unpublished', (user: any) => {
|
|
|
- if (user.uid == 333333) {
|
|
|
- console.log('用户取消推流');
|
|
|
+ let remoteEle = document.getElementById('video');
|
|
|
+ if (remoteEle) {
|
|
|
+ remoteEle.textContent = '对方离开直播间';
|
|
|
}
|
|
|
+ // if (user.uid == 333333) {
|
|
|
+ console.log('用户取消推流');
|
|
|
+ // }
|
|
|
});
|
|
|
}
|
|
|
+ /* 监听屏幕切换 */
|
|
|
+ onChangeScreen(type: string) {
|
|
|
+ if (type == 'big' && this.changeScreen) {
|
|
|
+ this.changeScreen = !this.changeScreen;
|
|
|
+ } else if (type == 'small' && !this.changeScreen) {
|
|
|
+ this.changeScreen = !this.changeScreen;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ngOnDestroy(): void {
|
|
|
+ /* 离开房间 */
|
|
|
+ this.client.leave();
|
|
|
+ console.log(111);
|
|
|
+ }
|
|
|
}
|