| 1 |
import { Component, onMounted, onPatched, status, useExternalListener, useRef } from "@odoo/owl"; |
| 2 |
import { useService } from "@web/core/utils/hooks"; |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
export class CallParticipantVideo extends Component { |
| 10 |
static props = ["session", "type", "inset?"]; |
| 11 |
static template = "discuss.CallParticipantVideo"; |
| 12 |
|
| 13 |
setup() { |
| 14 |
super.setup(); |
| 15 |
this.rtc = useService("discuss.rtc"); |
| 16 |
this.store = useService("mail.store"); |
| 17 |
this.root = useRef("root"); |
| 18 |
onMounted(() => this._update()); |
| 19 |
onPatched(() => this._update()); |
| 20 |
useExternalListener(this.env.bus, "RTC-SERVICE:PLAY_MEDIA", async () => { |
| 21 |
await this.play(); |
| 22 |
}); |
| 23 |
} |
| 24 |
|
| 25 |
_update() { |
| 26 |
if (!this.root.el) { |
| 27 |
return; |
| 28 |
} |
| 29 |
if (!this.props.session || !this.props.session.getStream(this.props.type)) { |
| 30 |
this.root.el.srcObject = undefined; |
| 31 |
} else { |
| 32 |
this.root.el.srcObject = this.props.session.getStream(this.props.type); |
| 33 |
} |
| 34 |
this.root.el.load(); |
| 35 |
} |
| 36 |
|
| 37 |
async play() { |
| 38 |
try { |
| 39 |
await this.root.el?.play?.(); |
| 40 |
this.props.session.videoError = undefined; |
| 41 |
} catch (error) { |
| 42 |
if (status(this) === "destroyed") { |
| 43 |
return; |
| 44 |
} |
| 45 |
this.props.session.videoError = error.name; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
async onVideoLoadedMetaData() { |
| 50 |
await this.play(); |
| 51 |
} |
| 52 |
} |