Skip to content

Commit

Permalink
デバイスを無効化する処理の場合に state の MediaStream からも Track を削除する
Browse files Browse the repository at this point in the history
  • Loading branch information
tnamao committed Oct 24, 2023
1 parent 203df7f commit 7eed896
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ export const disposeMedia = () => {
}
if (originalTrack !== undefined) {
originalTrack.stop();
localMediaStream?.removeTrack(originalTrack);
dispatch(
slice.actions.setTimelineMessage(
createSoraDevtoolsMediaStreamTrackLog('stop', originalTrack),
Expand All @@ -1129,6 +1130,7 @@ export const disposeMedia = () => {
if (localMediaStream) {
localMediaStream.getVideoTracks().forEach((track) => {
track.stop();
localMediaStream.removeTrack(track);
dispatch(
slice.actions.setTimelineMessage(createSoraDevtoolsMediaStreamTrackLog('stop', track)),
);
Expand All @@ -1140,6 +1142,7 @@ export const disposeMedia = () => {
const originalTrack = noiseSuppressionProcessor.getOriginalTrack();
if (originalTrack) {
originalTrack.stop();
localMediaStream?.removeTrack(originalTrack);
dispatch(
slice.actions.setTimelineMessage(
createSoraDevtoolsMediaStreamTrackLog('stop', originalTrack),
Expand All @@ -1151,6 +1154,7 @@ export const disposeMedia = () => {
if (localMediaStream) {
localMediaStream.getAudioTracks().forEach((track) => {
track.stop();
localMediaStream.removeTrack(track);
dispatch(
slice.actions.setTimelineMessage(createSoraDevtoolsMediaStreamTrackLog('stop', track)),
);
Expand Down Expand Up @@ -1733,13 +1737,14 @@ export const setCameraDevice = (cameraDevice: boolean) => {
/**
* devtools のローカルにもっている MediaStream のうち Video Track と
* 映像処理を行っている MediaProcessor の停止を行う関数
* MediaStream から Track の削除も行う
*/
const stopLocalVideoTrack = (
dispatch: Dispatch,
{ soraContents, lightAdjustmentProcessor, virtualBackgroundProcessor }: SoraDevtoolsState,
): void => {
const { localMediaStream } = soraContents;
let originalTrack;
let originalTrack: MediaStreamTrack | undefined;
if (lightAdjustmentProcessor && lightAdjustmentProcessor.isProcessing()) {
originalTrack = lightAdjustmentProcessor.getOriginalTrack();
lightAdjustmentProcessor.stopProcessing();
Expand All @@ -1752,26 +1757,30 @@ const stopLocalVideoTrack = (
}
if (originalTrack !== undefined) {
originalTrack.stop();
localMediaStream?.removeTrack(originalTrack);
dispatch(
slice.actions.setTimelineMessage(
createSoraDevtoolsMediaStreamTrackLog('stop', originalTrack),
),
);
} else {
if (localMediaStream) {
localMediaStream.getVideoTracks().forEach((track) => {
track.stop();
dispatch(
slice.actions.setTimelineMessage(createSoraDevtoolsMediaStreamTrackLog('stop', track)),
);
});
if (!localMediaStream) {
return;
}
localMediaStream.getVideoTracks().forEach((track) => {
track.stop();
localMediaStream.removeTrack(track);
dispatch(
slice.actions.setTimelineMessage(createSoraDevtoolsMediaStreamTrackLog('stop', track)),
);
});
}
};

/**
* devtools のローカルにもっている MediaStream のうち Video Track と
* devtools のローカルにもっている MediaStream のうち Audio Track と
* 映像処理を行っている MediaProcessor の停止を行う関数
* MediaStream から Track の削除も行う
*/
const stopLocalAudioTrack = (
dispatch: Dispatch,
Expand All @@ -1782,6 +1791,7 @@ const stopLocalAudioTrack = (
const originalTrack = noiseSuppressionProcessor.getOriginalTrack();
if (originalTrack) {
originalTrack.stop();
localMediaStream?.removeTrack(originalTrack);
dispatch(
slice.actions.setTimelineMessage(
createSoraDevtoolsMediaStreamTrackLog('stop', originalTrack),
Expand All @@ -1793,6 +1803,7 @@ const stopLocalAudioTrack = (
if (localMediaStream) {
localMediaStream.getAudioTracks().forEach((track) => {
track.stop();
localMediaStream.removeTrack(track);
dispatch(
slice.actions.setTimelineMessage(createSoraDevtoolsMediaStreamTrackLog('stop', track)),
);
Expand Down

0 comments on commit 7eed896

Please sign in to comment.