-
Notifications
You must be signed in to change notification settings - Fork 2
/
agora.service.ts
40 lines (32 loc) · 1.11 KB
/
agora.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Injectable } from '@angular/core';
import AgoraRTC, { ILocalTrack, IAgoraRTCClient } from 'agora-rtc-sdk-ng';
import { environment } from '../environments/environments';
import { BehaviorSubject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class AgoraService {
private client: IAgoraRTCClient;
private appId = environment.AgoraAppId
private channelJoinedSource = new BehaviorSubject<boolean>(false);
channelJoined$ = this.channelJoinedSource.asObservable();
constructor() {
if(this.appId == '')
console.error('APPID REQUIRED -- Open AgoraService.ts and update appId ')
this.client = AgoraRTC.createClient({ mode: 'rtc', codec: 'vp9'})
}
async joinChannel(channelName: string, token: string | null, uid: string | null) {
await this.client.join(this.appId, channelName, token, uid)
this.channelJoinedSource.next(true)
}
async leaveChannel() {
await this.client.leave()
this.channelJoinedSource.next(false)
}
setupLocalTracks(): Promise<ILocalTrack[]> {
return AgoraRTC.createMicrophoneAndCameraTracks();
}
getClient() {
return this.client
}
}