fixes in useMediaHandler
This commit is contained in:
parent
9b2e99c559
commit
885e933948
1 changed files with 9 additions and 5 deletions
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MatrixClient } from "matrix-js-sdk";
|
import { MatrixClient } from "matrix-js-sdk";
|
||||||
|
import { MediaHandlerEvent } from "matrix-js-sdk/src/webrtc/mediaHandler";
|
||||||
import React, {
|
import React, {
|
||||||
useState,
|
useState,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
@ -95,9 +96,9 @@ export function MediaHandlerProvider({ client, children }: Props): JSX.Element {
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// @ts-ignore
|
// @ts-ignore, ignore that audioInput is a private members of mediaHandler
|
||||||
audioInput: mediaHandler.audioInput,
|
audioInput: mediaHandler.audioInput,
|
||||||
// @ts-ignore
|
// @ts-ignore, ignore that videoInput is a private members of mediaHandler
|
||||||
videoInput: mediaHandler.videoInput,
|
videoInput: mediaHandler.videoInput,
|
||||||
audioOutput: undefined,
|
audioOutput: undefined,
|
||||||
audioInputs: [],
|
audioInputs: [],
|
||||||
|
@ -179,11 +180,14 @@ export function MediaHandlerProvider({ client, children }: Props): JSX.Element {
|
||||||
}
|
}
|
||||||
updateDevices();
|
updateDevices();
|
||||||
|
|
||||||
mediaHandler.on("local_streams_changed", updateDevices);
|
mediaHandler.on(MediaHandlerEvent.LocalStreamsChanged, updateDevices);
|
||||||
navigator.mediaDevices.addEventListener("devicechange", updateDevices);
|
navigator.mediaDevices.addEventListener("devicechange", updateDevices);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
mediaHandler.removeListener("local_streams_changed", updateDevices);
|
mediaHandler.removeListener(
|
||||||
|
MediaHandlerEvent.LocalStreamsChanged,
|
||||||
|
updateDevices
|
||||||
|
);
|
||||||
navigator.mediaDevices.removeEventListener("devicechange", updateDevices);
|
navigator.mediaDevices.removeEventListener("devicechange", updateDevices);
|
||||||
mediaHandler.stopAllStreams();
|
mediaHandler.stopAllStreams();
|
||||||
};
|
};
|
||||||
|
@ -207,7 +211,7 @@ export function MediaHandlerProvider({ client, children }: Props): JSX.Element {
|
||||||
[client]
|
[client]
|
||||||
);
|
);
|
||||||
|
|
||||||
const setAudioOutput: (deviceId: any) => void = useCallback((deviceId) => {
|
const setAudioOutput: (deviceId: string) => void = useCallback((deviceId) => {
|
||||||
updateMediaPreferences({ audioOutput: deviceId });
|
updateMediaPreferences({ audioOutput: deviceId });
|
||||||
setState((prevState) => ({ ...prevState, audioOutput: deviceId }));
|
setState((prevState) => ({ ...prevState, audioOutput: deviceId }));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
Loading…
Reference in a new issue