Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): force wait rtc join #1036

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion web/flat-web/src/api-middleware/rtc/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export enum RtcChannelType {
export class RtcRoom {
public client?: IAgoraRTCClient;

private resolveJoined!: () => void;
private joined = new Promise<void>(resolve => {
this.resolveJoined = resolve;
});
private roomUUID?: string;

public async join({
Expand All @@ -49,7 +53,7 @@ export class RtcRoom {
channelType: RtcChannelType;
}): Promise<IAgoraRTCClient> {
if (this.client) {
await this.destroy();
return this.client;
}

const mode = channelType === RtcChannelType.Communication ? "rtc" : "live";
Expand All @@ -67,6 +71,7 @@ export class RtcRoom {
this.client.on("user-published", this.onUserPublished);
this.client.on("user-unpublished", this.onUserUnpublished);
await this.client.join(AGORA.APP_ID, roomUUID, token, rtcUID);
this.resolveJoined();

this.roomUUID = roomUUID;

Expand All @@ -79,6 +84,7 @@ export class RtcRoom {

public async destroy(): Promise<void> {
if (this.client) {
await this.joined;
setMicrophoneTrack();
setCameraTrack();
if (this.client.localTracks.length > 0) {
Expand Down Expand Up @@ -111,6 +117,7 @@ export class RtcRoom {

public async getLocalAudioTrack(): Promise<ILocalAudioTrack> {
if (!this._localAudioTrack) {
await this.joined;
this._localAudioTrack = await AgoraRTC.createMicrophoneAudioTrack();
setMicrophoneTrack(this._localAudioTrack as IMicrophoneAudioTrack);
this._localAudioTrack.once("track-ended", () => {
Expand All @@ -124,6 +131,7 @@ export class RtcRoom {

public async getLocalVideoTrack(): Promise<ILocalVideoTrack> {
if (!this._localVideoTrack) {
await this.joined;
this._localVideoTrack = await AgoraRTC.createCameraVideoTrack({
encoderConfig: { width: 288, height: 216 },
});
Expand Down