Skip to content

Commit

Permalink
mic / camera デバイスの無効化時に track の停止処理を追加する
Browse files Browse the repository at this point in the history
  • Loading branch information
tnamao committed Oct 23, 2023
1 parent 5afb531 commit 6ce2919
Showing 1 changed file with 67 additions and 10 deletions.
77 changes: 67 additions & 10 deletions src/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1697,15 +1697,12 @@ export const setMicDevice = (micDevice: boolean) => {
}
} else if (state.soraContents.sora && state.soraContents.localMediaStream) {
// Sora 接続中の場合
stopLocalAudioTrack(dispatch, state);
state.soraContents.sora.stopAudioTrack(state.soraContents.localMediaStream);
} else if (state.soraContents.localMediaStream) {
// Sora は未接続で media access での表示を行っている場合
// localMediaStream の AudioTrack を停止して MediaStream から Track を削除する
state.soraContents.localMediaStream.getAudioTracks().forEach((track) => {
track.enabled = false;
track.stop();
state.soraContents.localMediaStream?.removeTrack(track);
});
stopLocalAudioTrack(dispatch, state);
}
dispatch(slice.actions.setMicDevice(micDevice));
};
Expand Down Expand Up @@ -1776,20 +1773,80 @@ export const setCameraDevice = (cameraDevice: boolean) => {
}
} else if (state.soraContents.sora && state.soraContents.localMediaStream) {
// Sora 接続中の場合
stopLocalVideoTrack(dispatch, state);
state.soraContents.sora.stopVideoTrack(state.soraContents.localMediaStream);
} else if (state.soraContents.localMediaStream) {
// Sora は未接続で media access での表示を行っている場合
// localMediaStream の VideoTrack を停止して MediaStream から Track を削除する
state.soraContents.localMediaStream.getVideoTracks().forEach((track) => {
track.enabled = false;
track.stop();
state.soraContents.localMediaStream?.removeTrack(track);
});
stopLocalVideoTrack(dispatch, state);
}
dispatch(slice.actions.setCameraDevice(cameraDevice));
};
};

const stopLocalVideoTrack = (
dispatch: Dispatch,
{ soraContents, lightAdjustmentProcessor, virtualBackgroundProcessor }: SoraDevtoolsState,
): void => {
const { localMediaStream } = soraContents;
let originalTrack;
if (lightAdjustmentProcessor && lightAdjustmentProcessor.isProcessing()) {
originalTrack = lightAdjustmentProcessor.getOriginalTrack();
lightAdjustmentProcessor.stopProcessing();
}
if (virtualBackgroundProcessor && virtualBackgroundProcessor.isProcessing()) {
if (originalTrack === undefined) {
originalTrack = virtualBackgroundProcessor.getOriginalTrack();
}
virtualBackgroundProcessor.stopProcessing();
}
if (originalTrack !== undefined) {
originalTrack.stop();
dispatch(
slice.actions.setTimelineMessage(
createSoraDevtoolsMediaStreamTrackLog('stop', originalTrack),
),
);
} else {
if (localMediaStream) {
localMediaStream.getVideoTracks().forEach((track) => {
track.stop();
dispatch(
slice.actions.setTimelineMessage(createSoraDevtoolsMediaStreamTrackLog('stop', track)),
);
});
}
}
};

const stopLocalAudioTrack = (
dispatch: Dispatch,
{ soraContents, noiseSuppressionProcessor }: SoraDevtoolsState,
): void => {
const { localMediaStream } = soraContents;
if (noiseSuppressionProcessor && noiseSuppressionProcessor.isProcessing()) {
const originalTrack = noiseSuppressionProcessor.getOriginalTrack();
if (originalTrack) {
originalTrack.stop();
dispatch(
slice.actions.setTimelineMessage(
createSoraDevtoolsMediaStreamTrackLog('stop', originalTrack),
),
);
}
noiseSuppressionProcessor.stopProcessing();
} else {
if (localMediaStream) {
localMediaStream.getAudioTracks().forEach((track) => {
track.stop();
dispatch(
slice.actions.setTimelineMessage(createSoraDevtoolsMediaStreamTrackLog('stop', track)),
);
});
}
}
};

// Lyra の初期化
export const initLyra = () => {
return async (_dispatch: Dispatch, _getState: () => SoraDevtoolsState): Promise<void> => {
Expand Down

0 comments on commit 6ce2919

Please sign in to comment.