comparison libervia/web/pages/calls/_browser/__init__.py @ 1562:4afafce0c4c9

browser (calls): correctly display avatar and entity in status on incoming call
author Goffi <goffi@goffi.org>
date Thu, 17 Aug 2023 14:59:01 +0200
parents 7dbb131bbb9e
children e3449beac8d8
comparison
equal deleted inserted replaced
1561:7dbb131bbb9e 1562:4afafce0c4c9
149 else: 149 else:
150 elt.classList.add("is-hidden") 150 elt.classList.add("is-hidden")
151 else: 151 else:
152 raise ValueError("Invalid call mode") 152 raise ValueError("Invalid call mode")
153 153
154 def set_avatar(self, entity_jid: JID|str) -> None:
155 """Set the avatar element from entity_jid
156
157 @param entity_jid: bare jid of the entity
158 """
159 call_avatar_elt = self.call_avatar_tpl.get_elt(
160 {
161 "entity": str(entity_jid),
162 "identities": cache.identities,
163 }
164 )
165 self.call_avatar_wrapper_elt.clear()
166 self.call_avatar_wrapper_elt <= call_avatar_elt
167
154 def _on_action_new( 168 def _on_action_new(
155 self, action_data_s: str, action_id: str, security_limit: int, profile: str 169 self, action_data_s: str, action_id: str, security_limit: int, profile: str
156 ) -> None: 170 ) -> None:
157 """Called when a call is received 171 """Called when a call is received
158 172
165 if action_data.get("type") != "call": 179 if action_data.get("type") != "call":
166 return 180 return
167 aio.run(self.on_action_new(action_data, action_id)) 181 aio.run(self.on_action_new(action_data, action_id))
168 182
169 async def on_action_new(self, action_data: dict, action_id: str) -> None: 183 async def on_action_new(self, action_data: dict, action_id: str) -> None:
170 peer_jid = action_data["from_jid"] 184 peer_jid = JID(action_data["from_jid"]).bare
171 log.info(f"{peer_jid} wants to start a call ({action_data['sub_type']})") 185 log.info(f"{peer_jid} wants to start a call ({action_data['sub_type']})")
172 if self.sid is not None: 186 if self.sid is not None:
173 log.warning( 187 log.warning(
174 f"already in a call ({self.sid}), can't receive a new call from " 188 f"already in a call ({self.sid}), can't receive a new call from "
175 f"{peer_jid}" 189 f"{peer_jid}"
176 ) 190 )
177 return 191 return
178 sid = self.sid = action_data["session_id"] 192 sid = self.sid = action_data["session_id"]
179 await cache.fill_identities([peer_jid]) 193 await cache.fill_identities([peer_jid])
180 identity = cache.identities[peer_jid] 194 identity = cache.identities[peer_jid]
195 self._callee = peer_jid
181 peer_name = identity["nicknames"][0] 196 peer_name = identity["nicknames"][0]
182 197
183 # we start the ring 198 # we start the ring
184 self.audio_player_elt.play() 199 self.audio_player_elt.play()
185 200
204 219
205 if accepted: 220 if accepted:
206 log.debug(f"Call SID: {sid}") 221 log.debug(f"Call SID: {sid}")
207 222
208 # Answer the call 223 # Answer the call
224 self.set_avatar(peer_jid)
209 self.status = "connecting" 225 self.status = "connecting"
210 self.switch_mode("call") 226 self.switch_mode("call")
211 else: 227 else:
212 log.info(f"your are declining the call from {peer_jid}") 228 log.info(f"your are declining the call from {peer_jid}")
213 self.sid = None 229 self.sid = None
306 return 322 return
307 323
308 self._callee = callee_jid 324 self._callee = callee_jid
309 await cache.fill_identities([callee_jid]) 325 await cache.fill_identities([callee_jid])
310 self.status = "dialing" 326 self.status = "dialing"
311 call_avatar_elt = self.call_avatar_tpl.get_elt( 327 self.set_avatar(callee_jid)
312 {
313 "entity": str(callee_jid),
314 "identities": cache.identities,
315 }
316 )
317 self.call_avatar_wrapper_elt.clear()
318 self.call_avatar_wrapper_elt <= call_avatar_elt
319 328
320 self.switch_mode("call") 329 self.switch_mode("call")
321 await self.webrtc.make_call(callee_jid, audio, video) 330 await self.webrtc.make_call(callee_jid, audio, video)
322 331
323 async def end_call(self, data: dict) -> None: 332 async def end_call(self, data: dict) -> None: