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

feat(web): the classroom page device keep consistent with devices selected by the devices test page #1183

Merged
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion web/flat-web/src/api-middleware/rtc/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AGORA } from "../../constants/process";
import { globalStore } from "../../stores/GlobalStore";
import { generateRTCToken } from "../flatServer/agora";
import { setCameraTrack, setMicrophoneTrack, hotPlug } from "./hot-plug";
import { configStore } from "../../stores/config-store";

AgoraRTC.enableLogUpload();

Expand Down Expand Up @@ -132,7 +133,9 @@ export class RtcRoom {
public async getLocalAudioTrack(): Promise<ILocalAudioTrack> {
if (!this._localAudioTrack) {
await this.joined;
this._localAudioTrack = await AgoraRTC.createMicrophoneAudioTrack();
this._localAudioTrack = await AgoraRTC.createMicrophoneAudioTrack({
microphoneId: configStore.microphoneId,
});
setMicrophoneTrack(this._localAudioTrack as IMicrophoneAudioTrack);
this._localAudioTrack.once("track-ended", () => {
console.log("[rtc] track-ended local audio");
Expand All @@ -148,6 +151,7 @@ export class RtcRoom {
await this.joined;
this._localVideoTrack = await AgoraRTC.createCameraVideoTrack({
encoderConfig: { width: 288, height: 216 },
cameraId: configStore.cameraId,
});
setCameraTrack(this._localVideoTrack as ICameraVideoTrack);
this._localVideoTrack.once("track-ended", () => {
Expand Down
3 changes: 3 additions & 0 deletions web/flat-web/src/pages/DevicesTestPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useParams } from "react-router-dom";
import { RouteNameType, RouteParams, usePushHistory } from "../../utils/routes";
import { joinRoomHandler } from "../utils/join-room-handler";
import { GlobalStoreContext } from "../../components/StoreProvider";
import { configStore } from "../../stores/config-store";

export const DevicesTestPage = observer(function DeviceTestPage() {
const pushHistory = usePushHistory();
Expand Down Expand Up @@ -118,6 +119,8 @@ export const DevicesTestPage = observer(function DeviceTestPage() {
}, [microphoneDeviceId, deviceTest]);

const joinRoom = async (): Promise<void> => {
configStore.updateCameraId(cameraDeviceId);
configStore.updateMicrophoneId(microphoneDeviceId);
await joinRoomHandler(roomUUID, pushHistory);
};

Expand Down
12 changes: 12 additions & 0 deletions web/flat-web/src/stores/config-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class ConfigStore {
public autoMicOn = true;
/** Region, default by language */
public region: Region | null = null;
/** selected camera device id on devices test page */
public cameraId?: string;
/** selected microphone device id on devices test page */
public microphoneId?: string;

public constructor() {
autoPersistStore({ storeLSName: "ConfigStore", store: this, version: LS_VERSION });
Expand All @@ -28,6 +32,14 @@ export class ConfigStore {
this.autoMicOn = isOn;
};

public updateCameraId = (cameraId: string): void => {
this.cameraId = cameraId;
};

public updateMicrophoneId = (microphoneId: string): void => {
this.microphoneId = microphoneId;
};

public setRegion = (region: Region): void => {
this.region = region;
};
Expand Down