Debian Codegraph @

addons/mail/static/src/discuss/call/common/call_participant_card.js

raw symbols SCIP
1 import { CallContextMenu } from "@mail/discuss/call/common/call_context_menu";
2 import { CallParticipantVideo } from "@mail/discuss/call/common/call_participant_video";
3 import { CallDropdown } from "@mail/discuss/call/common/call_dropdown";
4 import { CONNECTION_TYPES } from "@mail/discuss/call/common/rtc_service";
5 import { useHover } from "@mail/utils/common/hooks";
6 import { isEventHandled } from "@web/core/utils/misc";
7 import { browser } from "@web/core/browser/browser";
8 import { isMobileOS } from "@web/core/browser/feature_detection";
9
10 import { Component, onMounted, onWillUnmount, useRef, useExternalListener } from "@odoo/owl";
11 import { useService } from "@web/core/utils/hooks";
12 import { rpc } from "@web/core/network/rpc";
13
14 const HIDDEN_CONNECTION_STATES = new Set(["connected", "completed"]);
15
16 export class CallParticipantCard extends Component {
17 static props = [
18 "className",
19 "cardData",
20 "thread",
21 "minimized?",
22 "inset?",
23 "isSidebarItem?",
24 "compact?",
25 ];
26 static components = { CallParticipantVideo, CallContextMenu, CallDropdown };
27 static template = "discuss.CallParticipantCard";
28
29 setup() {
30 super.setup();
31 this.contextMenuAnchorRef = useRef("contextMenuAnchor");
32 this.root = useRef("root");
33 this.rtc = useService("discuss.rtc");
34 this.store = useService("mail.store");
35 this.ui = useService("ui");
36 this.rootHover = useHover("root");
37 this.resumeStreamHover = useHover("resumeStream");
38 this.isMobileOS = isMobileOS();
39 this.dragPos = undefined;
40 this.isDrag = false;
41 this.parentBoundingRect = undefined;
42 onMounted(() => {
43 if (!this.rtcSession) {
44 return;
45 }
46 this.rtc.updateVideoDownload(this.rtcSession, {
47 viewCountIncrement: 1,
48 });
49 });
50 onWillUnmount(() => {
51 if (!this.rtcSession) {
52 return;
53 }
54 this.rtc.updateVideoDownload(this.rtcSession, {
55 viewCountIncrement: -1,
56 });
57 });
58 useExternalListener(browser, "fullscreenchange", this.onFullScreenChange);
59 }
60
61 get isContextMenuAvailable() {
62 return (
63 this.isOfActiveCall &&
64 (this.rtcSession.notEq(this.rtc.selfSession) ||
65 (this.env.debug && this.rtc.state.connectionType === CONNECTION_TYPES.SERVER))
66 );
67 }
68
69 get isRemoteVideo() {
70 if (!this.rtcSession) {
71 return false;
72 }
73 return (
74 this.rtc.isRemote &&
75 (this.rtcSession.is_screen_sharing_on || this.rtcSession.is_camera_on)
76 );
77 }
78
79 get isSmall() {
80 return Boolean(
81 this.props.isSidebarItem || this.ui.isSmall || this.props.minimized || this.props.inset
82 );
83 }
84
85 get window() {
86 return this.env.pipWindow || window;
87 }
88
89 get showLiveLabel() {
90 if (this.props.isSidebarItem) {
91 return false;
92 }
93 if (this.props.cardData.type === "screen") {
94 if (this.props.inset) {
95 return true;
96 } else {
97 return (
98 !this.rtcSession.eq(this.rtcSession.channel.activeRtcSession) &&
99 !this.props.minimized
100 );
101 }
102 }
103 return false;
104 }
105
106 get showRemoteWarning() {
107 return !this.props.minimized && !this.props.inset && this.isRemoteVideo;
108 }
109
110 get rtcSession() {
111 return this.props.cardData.session;
112 }
113
114 get channelMember() {
115 return this.rtcSession ? this.rtcSession.channel_member_id : this.props.cardData.member;
116 }
117
118 get isOfActiveCall() {
119 return Boolean(this.rtcSession && this.rtcSession.channel?.eq(this.rtc.channel));
120 }
121
122 get showConnectionState() {
123 if (
124 !this.rtcSession ||
125 !this.rtc.isHost ||
126 !this.isOfActiveCall ||
127 HIDDEN_CONNECTION_STATES.has(this.rtcSession.connectionState)
128 ) {
129 return false;
130 }
131 if (this.rtc.state.connectionType === CONNECTION_TYPES.SERVER) {
132 return this.rtcSession.eq(this.rtc?.selfSession);
133 } else {
134 return this.rtcSession.notEq(this.rtc?.selfSession);
135 }
136 }
137
138 /**
139 * @deprecated use `showConnectionState` instead
140 */
141 get showServerState() {
142 return false;
143 }
144
145 get name() {
146 return this.channelMember?.name;
147 }
148
149 get hasMediaError() {
150 return (
151 this.isOfActiveCall &&
152 Boolean(this.rtcSession?.videoError || this.rtcSession?.audioError)
153 );
154 }
155
156 get hasVideo() {
157 return Boolean(this.props.cardData.videoStream);
158 }
159
160 get isTalking() {
161 return Boolean(
162 this.rtcSession && this.rtcSession.isActuallyTalking && !this.rtc.selfSession?.is_deaf
163 );
164 }
165
166 get hasRaisingHand() {
167 const screenStream = this.rtcSession.videoStreams.get("screen");
168 return Boolean(
169 this.rtcSession.raisingHand &&
170 (!screenStream || screenStream !== this.props.cardData.videoStream)
171 );
172 }
173
174 get isActiveRtcSession() {
175 return this.rtcSession && this.rtcSession.eq(this.rtcSession.channel?.activeRtcSession);
176 }
177
178 async onClick(ev) {
179 if (isEventHandled(ev, "CallParticipantCard.clickVolumeAnchor")) {
180 return;
181 }
182 if (this.isDrag) {
183 this.isDrag = false;
184 return;
185 }
186 if (this.rtcSession) {
187 const channel = this.rtcSession.channel;
188 this.rtcSession.mainVideoStreamType = this.props.cardData.type;
189 if (this.rtcSession.eq(channel.activeRtcSession) && !this.props.inset) {
190 channel.activeRtcSession = undefined;
191 this.rtcSession.mainVideoStreamType = undefined;
192 } else {
193 const activeRtcSession = channel.activeRtcSession;
194 const currentMainVideoType = this.rtcSession.mainVideoStreamType;
195 channel.activeRtcSession = this.rtcSession;
196 if (this.props.inset && activeRtcSession) {
197 this.props.inset(activeRtcSession, currentMainVideoType);
198 }
199 }
200 return;
201 }
202 await rpc("/mail/rtc/channel/cancel_call_invitation", {
203 channel_id: this.props.thread.id,
204 member_ids: [this.channelMember.id],
205 });
206 }
207
208 async onClickReplay() {
209 this.env.bus.trigger("RTC-SERVICE:PLAY_MEDIA");
210 }
211
212 onMouseDown() {
213 if (!this.props.inset) {
214 return;
215 }
216 const onMousemove = (ev) => this.drag(ev);
217 const onMouseup = () => {
218 const insetEl = this.root.el;
219 const bottomOffset = this.env.inChatWindow ? this.window.innerHeight * 0.05 : 0; // 5vh in pixels
220 if (parseInt(insetEl.style.left) < insetEl.parentNode.offsetWidth / 2) {
221 insetEl.style.left = "1vh";
222 insetEl.style.right = "";
223 } else {
224 insetEl.style.left = "";
225 insetEl.style.right = "1vh";
226 }
227 if (
228 parseInt(insetEl.style.top) <
229 (insetEl.parentNode.offsetHeight - bottomOffset) / 2
230 ) {
231 insetEl.style.top = "1vh";
232 insetEl.style.bottom = "";
233 } else {
234 insetEl.style.bottom = this.env.inChatWindow ? "5vh" : "1vh";
235 insetEl.style.top = "unset";
236 }
237 this.dragPos = undefined;
238 this.parentBoundingRect = undefined;
239 document.removeEventListener("mouseup", onMouseup);
240 document.removeEventListener("mousemove", onMousemove);
241 };
242 document.addEventListener("mouseup", onMouseup);
243 document.addEventListener("mousemove", onMousemove);
244 }
245
246 onTouchMove(ev) {
247 if (!this.props.inset) {
248 return;
249 }
250 this.drag(ev);
251 }
252
253 drag(ev) {
254 this.isDrag = true;
255 const insetEl = this.root.el;
256 const parent = insetEl.parentNode;
257 const boundingRect =
258 this.parentBoundingRect || (this.parentBoundingRect = parent.getBoundingClientRect());
259 const bottomOffset = this.env.inChatWindow ? this.window.innerHeight * 0.05 : 0; // 5vh in pixels
260 const clientX = Math.max((ev.clientX ?? ev.touches[0].clientX) - boundingRect.left, 0);
261 const clientY = Math.max((ev.clientY ?? ev.touches[0].clientY) - boundingRect.top, 0);
262 if (!this.dragPos) {
263 this.dragPos = { posX: clientX, posY: clientY };
264 }
265 const dX = this.dragPos.posX - clientX;
266 const dY = this.dragPos.posY - clientY;
267 const widthOffset = parent.offsetWidth - insetEl.clientWidth;
268 const heightOffset = parent.offsetHeight - insetEl.clientHeight - bottomOffset;
269 this.dragPos.posX = Math.min(clientX, widthOffset);
270 this.dragPos.posY = Math.min(clientY, heightOffset);
271 insetEl.style.left = Math.min(Math.max(insetEl.offsetLeft - dX, 0), widthOffset) + "px";
272 insetEl.style.top = Math.min(Math.max(insetEl.offsetTop - dY, 0), heightOffset) + "px";
273 }
274
275 onFullScreenChange() {
276 this.root.el.style = "left:''; top:''";
277 }
278 }