Skip to content

Commit

Permalink
fix video observer send wrong video size
Browse files Browse the repository at this point in the history
  • Loading branch information
tyohan committed Aug 10, 2024
1 parent 309a21a commit 402baf4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { InliveApp } from './app/index.js'
export { InliveStream, Stream, Stat } from './stream/index.js'
export { Room, RoomEvent, createAuth } from './room/index.js'
export { Room, createAuth, ChannelClosureReasons } from './room/index.js'
export { RoomEvent } from './room/peer/event.js'
10 changes: 0 additions & 10 deletions packages/room/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ import * as config from './config/config.js'
export { createAuth } from './api/auth.js'
export { REASONS as ChannelClosureReasons } from './channel/channel.js'

export const RoomEvent = Object.freeze({
CHANNEL_OPENED: 'channelOpened',
CHANNEL_CLOSED: 'channelClosed',
PEER_OPENED: 'peerOpened',
PEER_CLOSED: 'peerClosed',
STREAM_AVAILABLE: 'streamAvailable',
STREAM_REMOVED: 'streamRemoved',
META_CHANGED: 'metaChanged',
})

/**
* @param {import('./room-types.js').RoomType.UserConfig} [userConfig]
*/
Expand Down
7 changes: 5 additions & 2 deletions packages/room/observer/video-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export class VideoObserver {
const videoTracks = entry.target.srcObject.getVideoTracks()
if (videoTracks.length > 0) {
const trackid = videoTracks[0].id
const width = entry.isIntersecting ? entry.target.width : 0
const height = entry.isIntersecting ? entry.target.height : 0
const width = entry.isIntersecting ? entry.target.offsetWidth : 0
const height = entry.isIntersecting ? entry.target.offsetHeight : 0
this.#onVideoSizeChanged(trackid, width, height)
}
}
Expand Down Expand Up @@ -100,6 +100,7 @@ export class VideoObserver {
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)
Expand All @@ -123,6 +124,8 @@ export class VideoObserver {
},
}

console.debug('video size changed', data)

this.#dataChannel.send(JSON.stringify(data))
} else {
const listener = () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/room/peer/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,16 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
this._videoObserver.observe(videoElement)
}

/**
* @param {string} trackId
* @param {number} width
* @param {number} height
* @returns {void}
*/
updateVideoSize = (trackId, width, height) => {
this._videoObserver?.sendVideoSize(trackId, width, height)
}

/**
* @param {HTMLVideoElement} videoElement
*/
Expand Down Expand Up @@ -1057,6 +1067,7 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
turnOffMic: peer.turnOffMic,
replaceTrack: peer.replaceTrack,
observeVideo: peer.observeVideo,
updateVideoSize: peer.updateVideoSize,
unobserveVideo: peer.unobserveVideo,
negotiate: peer.negotiate,
pendingNegotiation: peer.pendingNegotiation,
Expand Down

0 comments on commit 402baf4

Please sign in to comment.