Skip to content

Commit

Permalink
fix: video resize sometimes make video freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
tyohan committed Sep 19, 2024
1 parent b79c6e1 commit b48d7d4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/room/observer/video-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export class VideoObserver {
#dataChannel
#resizeObserver
#intersectionObserver
/** @type { import('./video-observer-types.js').VideoObserver.StringMapTimeout} delayedReports - Last report time */
#delayedReports

/**
* Constructor.
* @param {RTCDataChannel} dataChannel - Data channel to use for reporting video size
Expand All @@ -15,6 +18,8 @@ export class VideoObserver {
this.#intersectionObserver = new IntersectionObserver(
this.#onIntersection.bind(this)
)

this.#delayedReports = {}
}

/**
Expand Down Expand Up @@ -88,6 +93,17 @@ export class VideoObserver {
* @returns {void}
*/
#onVideoSizeChanged(id, width, height) {
if (id in this.#delayedReports) {
clearTimeout(this.#delayedReports[id])

delete this.#delayedReports[id]
}

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

this.sendVideoSize(id, width, height)
}

Expand Down

0 comments on commit b48d7d4

Please sign in to comment.