change(tracker/player): change feeds updating

This commit is contained in:
sylenien 2022-10-10 14:57:29 +02:00 committed by Delirium
parent 9d7409b871
commit f3b4494097
3 changed files with 6 additions and 72 deletions

View file

@ -72,43 +72,8 @@ export const INITIAL_STATE: State = {
const MAX_RECONNECTION_COUNT = 4;
let handlers = Symbol('handlers');
interface VideoFeeds {
[key: string]: boolean
}
type ProxyResult<T extends {}> = T & {
observe: (handler: (args: any) => any) => void
[key: typeof handlers]: Function[]
}
function makeObservable<T extends {}>(target: T): ProxyResult<T> {
// @ts-ignore
target[handlers] = [];
// @ts-ignore
target.observe = function(handler) {
this[handlers].push(handler);
};
// @ts-ignore
return new Proxy(target, {
set(target, property, value) {
// @ts-ignore
let success = Reflect.set(...arguments);
if (success) {
// @ts-ignore
target[handlers].forEach(handler => handler(property, value));
}
return success;
}
});
}
export const videoFeeds = makeObservable<VideoFeeds>({})
export default class AssistManager {
private videoStreams: Record<string, MediaStreamTrack> = {}
// TODO: Session type
constructor(private session: any, private md: MessageDistributor, private config: any) {}
@ -240,7 +205,7 @@ export default class AssistManager {
}
})
socket.on('videofeed', ({ streamId, enabled }) => {
videoFeeds[streamId] = enabled
this.videoStreams[streamId].enabled = enabled
})
socket.on('SESSION_DISCONNECTED', e => {
waitingForMessages = true
@ -405,7 +370,7 @@ export default class AssistManager {
call.on('stream', stream => {
this.callArgs && this.callArgs.onStream(stream)
stream.getVideoTracks().forEach(track => {
videoFeeds[track.id] = track.enabled
this.videoStreams[track.id] = track
})
});
// call.peerConnection.addEventListener("track", e => console.log('newtrack',e.track))
@ -537,8 +502,9 @@ export default class AssistManager {
call.on('stream', stream => {
getState().calling !== CallingState.OnCall && update({ calling: CallingState.OnCall })
stream.getVideoTracks().forEach(track => {
videoFeeds[track.id] = track.enabled
this.videoStreams[track.id] = track
})
this.callArgs && this.callArgs.onStream(stream)
});

View file

@ -147,7 +147,7 @@ export default class CallWindow {
this.checkRemoteVideoInterval = setInterval(() => {
const settings = this.remoteVideo?.getSettings()
const isDummyVideoTrack =
!!settings && (settings.width === 2 || settings.frameRate === 0)
!!settings && !this.remoteVideo.enabled && (settings.width === 2 || settings.frameRate === 0)
const shouldBeEnabled = !isDummyVideoTrack
if (enabled !== shouldBeEnabled) {
this.toggleRemoteVideoUI((enabled = shouldBeEnabled))

View file

@ -1,32 +0,0 @@
/* eslint-disable prefer-rest-params */
const handlers = Symbol('handlers')
export type ProxyResult<T extends Record<any, any>> = T & {
observe: (handler: (key: string, value: any) => any) => void
// @ts-ignore
[key: typeof handlers]: (() => void)[]
}
export function makeObservable<T extends Record<any, any>>(target: T): ProxyResult<T> {
// @ts-ignore
target[handlers] = []
// @ts-ignore
target.observe = function (handler) {
// @ts-ignore
this[handlers].push(handler)
}
// @ts-ignore
return new Proxy(target, {
set(target, property, value) {
// @ts-ignore
const success = Reflect.set(...arguments)
if (success) {
// @ts-ignore
target[handlers].forEach((handler: (property: string, value: any) => void) => handler(property, value))
}
return success
},
})
}