Skip to content

Commit

Permalink
camera disabled にした時に配信側に映像が残る問題へのハックを入れる
Browse files Browse the repository at this point in the history
  • Loading branch information
tnamao committed Oct 24, 2023
1 parent 7eed896 commit 335b301
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ function setSoraCallbacks(
dispatch(slice.actions.removeRemoteMediaStream((event.target as MediaStream).id));
}
});
sora.on('disconnect', (event) => {
sora.on('disconnect', async (event) => {
const message: Record<string, unknown> = {
type: event.type,
title: event.title,
Expand All @@ -873,7 +873,7 @@ function setSoraCallbacks(
),
);
// ローカルの MediaStream の Track と MediaProcessor を止める
stopLocalVideoTrack(dispatch, getState());
await stopLocalVideoTrack(dispatch, getState());
stopLocalAudioTrack(dispatch, getState());
const { fakeContents, soraContents, reconnect } = getState();
const { remoteMediaStreams } = soraContents;
Expand Down Expand Up @@ -1723,12 +1723,12 @@ export const setCameraDevice = (cameraDevice: boolean) => {
}
} else if (state.soraContents.sora && state.soraContents.localMediaStream) {
// Sora 接続中の場合
stopLocalVideoTrack(dispatch, state);
await stopLocalVideoTrack(dispatch, state);
state.soraContents.sora.stopVideoTrack(state.soraContents.localMediaStream);
} else if (state.soraContents.localMediaStream) {
// Sora は未接続で media access での表示を行っている場合
// localMediaStream の VideoTrack を停止して MediaStream から Track を削除する
stopLocalVideoTrack(dispatch, state);
await stopLocalVideoTrack(dispatch, state);
}
dispatch(slice.actions.setCameraDevice(cameraDevice));
};
Expand All @@ -1739,10 +1739,10 @@ export const setCameraDevice = (cameraDevice: boolean) => {
* 映像処理を行っている MediaProcessor の停止を行う関数
* MediaStream から Track の削除も行う
*/
const stopLocalVideoTrack = (
const stopLocalVideoTrack = async (
dispatch: Dispatch,
{ soraContents, lightAdjustmentProcessor, virtualBackgroundProcessor }: SoraDevtoolsState,
): void => {
): Promise<void> => {
const { localMediaStream } = soraContents;
let originalTrack: MediaStreamTrack | undefined;
if (lightAdjustmentProcessor && lightAdjustmentProcessor.isProcessing()) {
Expand All @@ -1756,6 +1756,10 @@ const stopLocalVideoTrack = (
virtualBackgroundProcessor.stopProcessing();
}
if (originalTrack !== undefined) {
originalTrack.enabled = false;
// track enabled = false から sleep を sleep を入れないと配信側にカメラの最後のコマが残る問題へのハック
// safari はこれで対応できるが firefox は残ってしまう
await new Promise((resolve) => setTimeout(resolve, 100));
originalTrack.stop();
localMediaStream?.removeTrack(originalTrack);
dispatch(
Expand All @@ -1767,6 +1771,12 @@ const stopLocalVideoTrack = (
if (!localMediaStream) {
return;
}
localMediaStream.getVideoTracks().forEach((track) => {
track.enabled = false;
});
// track enabled = false から sleep を sleep を入れないと配信側にカメラの最後のコマが残る問題へのハック
// safari はこれで対応できるが firefox は残ってしまう
await new Promise((resolve) => setTimeout(resolve, 100));
localMediaStream.getVideoTracks().forEach((track) => {
track.stop();
localMediaStream.removeTrack(track);
Expand Down

0 comments on commit 335b301

Please sign in to comment.