Skip to content

Commit

Permalink
fix: revert video observer to report video size in realtime
Browse files Browse the repository at this point in the history
  • Loading branch information
tyohan committed Aug 28, 2024
1 parent 611eb3e commit 320af70
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
19 changes: 2 additions & 17 deletions packages/room/observer/video-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@
* Video observer class.
*/
export class VideoObserver {
#intervalGap
/** @type { import('./video-observer-types.js').VideoObserver.StringMapTimeout} delayedReports - Last report time */
#delayedReports
#dataChannel
#resizeObserver
#intersectionObserver
/**
* Constructor.
* @param {RTCDataChannel} dataChannel - Data channel to use for reporting video size
* @param {number} intervalGap - interval time gap between report
*/
constructor(dataChannel, intervalGap) {
this.#intervalGap = typeof intervalGap !== 'number' ? 1000 : intervalGap
this.#delayedReports = {}
constructor(dataChannel) {
this.#dataChannel = dataChannel
this.#resizeObserver = new ResizeObserver(this.#onResize.bind(this))
this.#intersectionObserver = new IntersectionObserver(
Expand Down Expand Up @@ -94,16 +88,7 @@ export class VideoObserver {
* @returns {void}
*/
#onVideoSizeChanged(id, width, height) {
if (id in this.#delayedReports) {
clearTimeout(this.#delayedReports[id])

delete this.#delayedReports[id]
}

console.log('video size changed start timeout', id, width, height)
this.#delayedReports[id] = setTimeout(() => {
this.sendVideoSize(id, width, height)
}, this.#intervalGap)
this.sendVideoSize(id, width, height)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/room/peer/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
internalChannel
)

this._videoObserver = new VideoObserver(internalChannel, 1000)
this._videoObserver = new VideoObserver(internalChannel)

for (const videoElement of this._pendingObservedVideo) {
this._videoObserver.observe(videoElement)
Expand Down

0 comments on commit 320af70

Please sign in to comment.