Skip to content

Commit

Permalink
media access 実行中に mediaType を変更できないようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
tnamao committed Oct 18, 2023
1 parent d7fed26 commit d03679f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/components/DevtoolsPane/MediaAccessButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';

import { disposeTestMediaAccess, testMediaAccess } from '@/app/actions';
import { useAppDispatch, useAppSelector } from '@/app/hooks';
import { isFormDisabled } from '@/utils';

export const MediaAccessButton: React.FC = () => {
const dispatch = useAppDispatch();
Expand All @@ -11,7 +12,9 @@ export const MediaAccessButton: React.FC = () => {
const disposeMediaAccess = (): void => {
dispatch(disposeTestMediaAccess());
};
const connectionStatus = useAppSelector((state) => state.soraContents.connectionStatus);
const localTestMediaStream = useAppSelector((state) => state.localTestMediaStream);
const disabled = localTestMediaStream === null && isFormDisabled(connectionStatus);
return (
<div className="col-auto mb-1">
<input
Expand All @@ -20,6 +23,7 @@ export const MediaAccessButton: React.FC = () => {
name="media_access"
defaultValue={localTestMediaStream === null ? 'media access' : 'dispose'}
onClick={localTestMediaStream === null ? mediaAccess : disposeMediaAccess}
disabled={disabled}
/>
</div>
);
Expand Down
5 changes: 3 additions & 2 deletions src/components/DevtoolsPane/MediaTypeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FormCheck, FormGroup } from 'react-bootstrap';
import { setMediaType } from '@/app/actions';
import { useAppDispatch, useAppSelector } from '@/app/hooks';
import { MEDIA_TYPES } from '@/constants';
import { checkFormValue, isFormDisabled } from '@/utils';
import { checkFormValue, isMediaTypeFormDisabled } from '@/utils';

import { TooltipFormLabel } from './TooltipFormLabel';

Expand Down Expand Up @@ -38,8 +38,9 @@ export const MediaTypeForm: React.FC = () => {
const enabledMediacaptureRegion =
typeof window !== 'undefined' && window.CropTarget !== undefined;
const connectionStatus = useAppSelector((state) => state.soraContents.connectionStatus);
const localTestMediaStream = useAppSelector((state) => state.localTestMediaStream);
const mediaType = useAppSelector((state) => state.mediaType);
const disabled = isFormDisabled(connectionStatus);
const disabled = isMediaTypeFormDisabled(localTestMediaStream, connectionStatus);
const dispatch = useAppDispatch();
const onChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
if (checkFormValue(event.target.value, MEDIA_TYPES)) {
Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,13 @@ export function isFormDisabled(
return connectionStatus === 'connected' || connectionStatus === 'connecting';
}

export function isMediaTypeFormDisabled(
localTestMediaStream: SoraDevtoolsState['localTestMediaStream'],
connectionStatus: SoraDevtoolsState['soraContents']['connectionStatus'],
): boolean {
return localTestMediaStream !== null || isFormDisabled(connectionStatus);
}

// track の設定情報を返す
type GetMediaStreamTrackProperties = {
id: MediaStreamTrack['id'];
Expand Down

0 comments on commit d03679f

Please sign in to comment.