@chat-leo/chatleo 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/chatleo/chatleo.esm.js +1 -0
- package/dist/chatleo/index.esm.js +1 -0
- package/dist/chatleo/p-43ada232.entry.js +1 -0
- package/dist/chatleo/p-4485e141.entry.js +1 -0
- package/dist/chatleo/p-BnCPdbII.js +1 -0
- package/dist/chatleo/p-C-l90Wre.js +1 -0
- package/dist/chatleo/p-DQuL1Twl.js +1 -0
- package/dist/chatleo/p-DmL518NK.js +3 -0
- package/dist/chatleo/p-aed60255.entry.js +1 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
- package/dist/cjs/chatleo-avatar_13.cjs.entry.js +2986 -0
- package/dist/cjs/chatleo-call-adapter-B2OfC0VZ.js +35 -0
- package/dist/cjs/chatleo-chat-input.cjs.entry.js +67 -0
- package/dist/cjs/chatleo.cjs.js +25 -0
- package/dist/cjs/index-DkSDLR0y.js +56 -0
- package/dist/cjs/index-Dxw4YCA_.js +1741 -0
- package/dist/cjs/index.cjs.js +7 -0
- package/dist/cjs/loader.cjs.js +13 -0
- package/dist/cjs/my-component.cjs.entry.js +33 -0
- package/dist/collection/__mocks__/stencil-core.js +26 -0
- package/dist/collection/collection-manifest.json +27 -0
- package/dist/collection/components/chatleo-avatar/chatleo-avatar.css +40 -0
- package/dist/collection/components/chatleo-avatar/chatleo-avatar.js +116 -0
- package/dist/collection/components/chatleo-chat/chatleo-chat.css +108 -0
- package/dist/collection/components/chatleo-chat/chatleo-chat.js +459 -0
- package/dist/collection/components/chatleo-chat-header/chatleo-chat-header.css +22 -0
- package/dist/collection/components/chatleo-chat-header/chatleo-chat-header.js +105 -0
- package/dist/collection/components/chatleo-chat-input/chatleo-chat-input.css +84 -0
- package/dist/collection/components/chatleo-chat-input/chatleo-chat-input.js +141 -0
- package/dist/collection/components/chatleo-chat-message/chatleo-chat-message.css +149 -0
- package/dist/collection/components/chatleo-chat-message/chatleo-chat-message.js +259 -0
- package/dist/collection/components/chatleo-component/chatleo-component.css +271 -0
- package/dist/collection/components/chatleo-component/chatleo-component.js +1366 -0
- package/dist/collection/components/chatleo-new-message-selector/chatleo-new-message-selector.css +96 -0
- package/dist/collection/components/chatleo-new-message-selector/chatleo-new-message-selector.js +231 -0
- package/dist/collection/components/chatleo-rich-input/chatleo-rich-input.css +352 -0
- package/dist/collection/components/chatleo-rich-input/chatleo-rich-input.js +976 -0
- package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.css +169 -0
- package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.js +400 -0
- package/dist/collection/components/chatleo-room-list/chatleo-room-list.css +111 -0
- package/dist/collection/components/chatleo-room-list/chatleo-room-list.js +180 -0
- package/dist/collection/components/chatleo-room-tile-component/chatleo-room-tile-component.css +110 -0
- package/dist/collection/components/chatleo-room-tile-component/chatleo-room-tile-component.js +241 -0
- package/dist/collection/components/chatleo-room-view/chatleo-room-view.css +93 -0
- package/dist/collection/components/chatleo-room-view/chatleo-room-view.js +593 -0
- package/dist/collection/components/chatleo-tray-component/chatleo-tray-component.css +284 -0
- package/dist/collection/components/chatleo-tray-component/chatleo-tray-component.js +391 -0
- package/dist/collection/components/chatleo-user-tile/chatleo-user-tile.css +56 -0
- package/dist/collection/components/chatleo-user-tile/chatleo-user-tile.js +149 -0
- package/dist/collection/components/my-component/my-component.css +4 -0
- package/dist/collection/components/my-component/my-component.js +95 -0
- package/dist/collection/index.js +10 -0
- package/dist/collection/utils/call-entry.js +34 -0
- package/dist/collection/utils/delivery.js +7 -0
- package/dist/collection/utils/utils.js +51 -0
- package/dist/components/chatleo-avatar.d.ts +11 -0
- package/dist/components/chatleo-avatar.js +1 -0
- package/dist/components/chatleo-chat-header.d.ts +11 -0
- package/dist/components/chatleo-chat-header.js +1 -0
- package/dist/components/chatleo-chat-input.d.ts +11 -0
- package/dist/components/chatleo-chat-input.js +1 -0
- package/dist/components/chatleo-chat-message.d.ts +11 -0
- package/dist/components/chatleo-chat-message.js +1 -0
- package/dist/components/chatleo-chat.d.ts +11 -0
- package/dist/components/chatleo-chat.js +1 -0
- package/dist/components/chatleo-component.d.ts +11 -0
- package/dist/components/chatleo-component.js +1 -0
- package/dist/components/chatleo-new-message-selector.d.ts +11 -0
- package/dist/components/chatleo-new-message-selector.js +1 -0
- package/dist/components/chatleo-rich-input.d.ts +11 -0
- package/dist/components/chatleo-rich-input.js +1 -0
- package/dist/components/chatleo-rich-message-renderer.d.ts +11 -0
- package/dist/components/chatleo-rich-message-renderer.js +1 -0
- package/dist/components/chatleo-room-list.d.ts +11 -0
- package/dist/components/chatleo-room-list.js +1 -0
- package/dist/components/chatleo-room-tile-component.d.ts +11 -0
- package/dist/components/chatleo-room-tile-component.js +1 -0
- package/dist/components/chatleo-room-view.d.ts +11 -0
- package/dist/components/chatleo-room-view.js +1 -0
- package/dist/components/chatleo-tray-component.d.ts +11 -0
- package/dist/components/chatleo-tray-component.js +1 -0
- package/dist/components/chatleo-user-tile.d.ts +11 -0
- package/dist/components/chatleo-user-tile.js +1 -0
- package/dist/components/index.d.ts +35 -0
- package/dist/components/index.js +1 -0
- package/dist/components/my-component.d.ts +11 -0
- package/dist/components/my-component.js +1 -0
- package/dist/components/p-8kvQ-Uh-.js +1 -0
- package/dist/components/p-B7cdqAgv.js +1 -0
- package/dist/components/p-BdiOcOYZ.js +1 -0
- package/dist/components/p-BlbDSb7D.js +1 -0
- package/dist/components/p-BnCPdbII.js +1 -0
- package/dist/components/p-C-v19aUJ.js +1 -0
- package/dist/components/p-C1mF0s8g.js +1 -0
- package/dist/components/p-CRtBdzP3.js +1 -0
- package/dist/components/p-CfayCm9O.js +1 -0
- package/dist/components/p-DGjAxoQy.js +1 -0
- package/dist/components/p-Exj_2-yI.js +1 -0
- package/dist/components/p-XlwGxsqT.js +1 -0
- package/dist/components/p-fjMaTJam.js +1 -0
- package/dist/components/p-xt4kzz3B.js +1 -0
- package/dist/esm/app-globals-DQuL1Twl.js +3 -0
- package/dist/esm/chatleo-avatar_13.entry.js +2972 -0
- package/dist/esm/chatleo-call-adapter-BnCPdbII.js +33 -0
- package/dist/esm/chatleo-chat-input.entry.js +65 -0
- package/dist/esm/chatleo.js +21 -0
- package/dist/esm/index-C-l90Wre.js +53 -0
- package/dist/esm/index-DmL518NK.js +1733 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/loader.js +11 -0
- package/dist/esm/my-component.entry.js +31 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/types/__mocks__/stencil-core.d.ts +24 -0
- package/dist/types/components/chatleo-avatar/chatleo-avatar.d.ts +27 -0
- package/dist/types/components/chatleo-chat/chatleo-chat.d.ts +75 -0
- package/dist/types/components/chatleo-chat-header/chatleo-chat-header.d.ts +27 -0
- package/dist/types/components/chatleo-chat-input/chatleo-chat-input.d.ts +31 -0
- package/dist/types/components/chatleo-chat-message/chatleo-chat-message.d.ts +22 -0
- package/dist/types/components/chatleo-component/chatleo-component.d.ts +278 -0
- package/dist/types/components/chatleo-new-message-selector/chatleo-new-message-selector.d.ts +68 -0
- package/dist/types/components/chatleo-rich-input/chatleo-rich-input.d.ts +216 -0
- package/dist/types/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.d.ts +77 -0
- package/dist/types/components/chatleo-room-list/chatleo-room-list.d.ts +52 -0
- package/dist/types/components/chatleo-room-tile-component/chatleo-room-tile-component.d.ts +59 -0
- package/dist/types/components/chatleo-room-view/chatleo-room-view.d.ts +91 -0
- package/dist/types/components/chatleo-tray-component/chatleo-tray-component.d.ts +112 -0
- package/dist/types/components/chatleo-user-tile/chatleo-user-tile.d.ts +36 -0
- package/dist/types/components/my-component/my-component.d.ts +16 -0
- package/dist/types/components.d.ts +1593 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/stencil-public-runtime.d.ts +1879 -0
- package/dist/types/utils/call-entry.d.ts +9 -0
- package/dist/types/utils/delivery.d.ts +7 -0
- package/dist/types/utils/utils.d.ts +24 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/package.json +70 -3
- package/readme.md +111 -0
- package/README.md +0 -3
|
@@ -0,0 +1,1366 @@
|
|
|
1
|
+
import { h } from "@stencil/core";
|
|
2
|
+
/**
|
|
3
|
+
* @component ChatLeoComponent
|
|
4
|
+
* @description This is the root component for the ChatLeo application. It serves as the main entry point and orchestrates the overall functionality. It can be configured to render either a full-page chat client or a tray-based widget. It also handles the connection to the `ChatLeoLib` and manages the application's lifecycle.
|
|
5
|
+
* @property {string} username - The username of the user, which can be used for authentication.
|
|
6
|
+
* @property {string} ticket - An authentication ticket used to establish a connection with the chat service.
|
|
7
|
+
* @property {boolean} useTray - If `true`, the component will render as a tray-based chat widget.
|
|
8
|
+
* @property {boolean} useMain - If `true`, the component will render as a full-page chat application.
|
|
9
|
+
* @property {ChatLeoLib} chatLeoLib - An instance of the `ChatLeoLib` class, which provides the core chat functionalities.
|
|
10
|
+
* @property {ChatStore} chatStore - An instance of the `ChatStore` class, which manages the application's state.
|
|
11
|
+
*/
|
|
12
|
+
export class ChatLeoComponent {
|
|
13
|
+
/**
|
|
14
|
+
* The username of the user, which can be used for authentication.
|
|
15
|
+
*/
|
|
16
|
+
username; // optional, not currently used for login without password
|
|
17
|
+
/**
|
|
18
|
+
* An authentication ticket used to establish a connection with the chat service.
|
|
19
|
+
*/
|
|
20
|
+
ticket;
|
|
21
|
+
/**
|
|
22
|
+
* If `true`, the component will render as a tray-based chat widget.
|
|
23
|
+
*/
|
|
24
|
+
useTray;
|
|
25
|
+
/**
|
|
26
|
+
* If `true`, the component will render as a full-page chat application.
|
|
27
|
+
*/
|
|
28
|
+
useMain = false;
|
|
29
|
+
/**
|
|
30
|
+
* If `true`, the component will render as a single room view without the room list.
|
|
31
|
+
*/
|
|
32
|
+
useRoomView = false;
|
|
33
|
+
/**
|
|
34
|
+
* The ID of the room to display when using room view mode.
|
|
35
|
+
*/
|
|
36
|
+
roomId;
|
|
37
|
+
/**
|
|
38
|
+
* An instance of the `ChatLeoLib` class, which provides the core chat functionalities.
|
|
39
|
+
*/
|
|
40
|
+
chatLeoLib;
|
|
41
|
+
/**
|
|
42
|
+
* An instance of the `ChatStore` class, which manages the application's state.
|
|
43
|
+
*/
|
|
44
|
+
chatStore;
|
|
45
|
+
//
|
|
46
|
+
serverUrl;
|
|
47
|
+
/**
|
|
48
|
+
* Real-time protocol: `socketio` (default), `v2` (ChatLeo Protocol v2) or `auto`
|
|
49
|
+
* (use v2 when the server's `/.well-known/chatleo` offers it, otherwise Socket.IO).
|
|
50
|
+
* Overrides `ChatLeoLib.transport`.
|
|
51
|
+
*/
|
|
52
|
+
transport;
|
|
53
|
+
/** `auto` shows call controls when the server advertises calls; `off` disables the call UI. */
|
|
54
|
+
calls = 'auto';
|
|
55
|
+
/** `manual` shows a notification control; `prompt` also shows an in-page explanation; `off` hides it. */
|
|
56
|
+
push = 'manual';
|
|
57
|
+
/** Path of the push service worker served by the host. */
|
|
58
|
+
pushSwPath;
|
|
59
|
+
isLoggedIn = false;
|
|
60
|
+
loading = false;
|
|
61
|
+
isSessionExpired = false;
|
|
62
|
+
connectionStatus = 'disconnected';
|
|
63
|
+
callsAvailable = false;
|
|
64
|
+
incomingCall = null;
|
|
65
|
+
callView = null;
|
|
66
|
+
showCall = false;
|
|
67
|
+
pushState = null;
|
|
68
|
+
pushPromptDismissed = false;
|
|
69
|
+
/** Fires when the open conversation changes, so a host can drive navigation/history. */
|
|
70
|
+
activeRoomChange;
|
|
71
|
+
/** Fires when the total unread count changes (app badge, title, ...). */
|
|
72
|
+
unreadTotalChange;
|
|
73
|
+
chatEl;
|
|
74
|
+
boundActiveRoomChanged = (e) => this.activeRoomChange.emit(e.detail ?? { roomId: null });
|
|
75
|
+
boundUnreadTotalChanged = (e) => this.unreadTotalChange.emit(e.detail ?? { count: 0 });
|
|
76
|
+
callRingtoneTimer;
|
|
77
|
+
incomingRef;
|
|
78
|
+
callRingtoneContext;
|
|
79
|
+
callsChannel;
|
|
80
|
+
callAdapterRef;
|
|
81
|
+
trayEl;
|
|
82
|
+
// --- External integration event names (global custom events) ---
|
|
83
|
+
// detail: { roomId: string }
|
|
84
|
+
static OPEN_ROOM_EVENT = 'chatleo:openRoom';
|
|
85
|
+
// detail: { userId: string }
|
|
86
|
+
static START_DM_EVENT = 'chatleo:startDM';
|
|
87
|
+
// detail: none or { open: true }
|
|
88
|
+
static NEW_CHAT_EVENT = 'chatleo:newChat';
|
|
89
|
+
// Keep bound listeners for removal
|
|
90
|
+
boundOpenRoomListener = (e) => this.handleExternalOpenRoom(e);
|
|
91
|
+
boundStartDmListener = (e) => this.handleExternalStartDm(e);
|
|
92
|
+
boundNewChatListener = (e) => this.handleExternalNewChat(e);
|
|
93
|
+
boundStartCallListener = (e) => this.handleExternalStartCall(e);
|
|
94
|
+
boundCallRinging = (e) => this.handleCallRinging(e);
|
|
95
|
+
boundCallChanged = (e) => this.handleCallChanged(e);
|
|
96
|
+
boundCallRole = (e) => this.handleCallRole(e);
|
|
97
|
+
boundServiceWorkerMessage = (event) => this.handleServiceWorkerMessage(event);
|
|
98
|
+
/**
|
|
99
|
+
* @function onChatLeoLibChange
|
|
100
|
+
* @description A Stencil watcher that triggers when the `chatLeoLib` prop is updated. This is mainly used for debugging to observe when the library is injected.
|
|
101
|
+
* @param {ChatLeoLib} newValue - The new instance of `ChatLeoLib`.
|
|
102
|
+
*/
|
|
103
|
+
onChatLeoLibChange(newValue) {
|
|
104
|
+
console.debug('onChatLeoLibChange', newValue);
|
|
105
|
+
if (newValue) {
|
|
106
|
+
this.requestLibConnection();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @function onChatStoreChange
|
|
111
|
+
* @description A Stencil watcher that triggers when the `chatStore` prop is updated. It attaches an event listener to the new store to listen for new rooms being added.
|
|
112
|
+
* @param {ChatStore} newStore - The new `ChatStore` instance.
|
|
113
|
+
* @param {ChatStore} oldStore - The previous `ChatStore` instance.
|
|
114
|
+
*/
|
|
115
|
+
onChatStoreChange(newStore, oldStore) {
|
|
116
|
+
console.debug('onChatStoreChange', newStore, oldStore);
|
|
117
|
+
oldStore?.removeEventListener('callRinging', this.boundCallRinging);
|
|
118
|
+
oldStore?.removeEventListener('callChanged', this.boundCallChanged);
|
|
119
|
+
oldStore?.removeEventListener('callRole', this.boundCallRole);
|
|
120
|
+
oldStore?.removeEventListener('activeRoomChanged', this.boundActiveRoomChanged);
|
|
121
|
+
oldStore?.removeEventListener('unreadTotalChanged', this.boundUnreadTotalChanged);
|
|
122
|
+
newStore.addEventListener('callRinging', this.boundCallRinging);
|
|
123
|
+
newStore.addEventListener('callChanged', this.boundCallChanged);
|
|
124
|
+
newStore.addEventListener('callRole', this.boundCallRole);
|
|
125
|
+
newStore.addEventListener('activeRoomChanged', this.boundActiveRoomChanged);
|
|
126
|
+
newStore.addEventListener('unreadTotalChanged', this.boundUnreadTotalChanged);
|
|
127
|
+
// TODO: unbind oldStore listeners
|
|
128
|
+
newStore.addEventListener('roomAdded', r => {
|
|
129
|
+
console.warn(r);
|
|
130
|
+
});
|
|
131
|
+
this.activeRoomChange.emit({ roomId: newStore.activeRoomId });
|
|
132
|
+
this.unreadTotalChange.emit({ count: newStore.unreadTotal });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* @function onTicketChange
|
|
136
|
+
* @description A Stencil watcher that is called when the `ticket` prop changes. This will trigger a reconnection attempt to the chat library with the new ticket.
|
|
137
|
+
* @param {string} _newValue - The new authentication ticket.
|
|
138
|
+
*/
|
|
139
|
+
onTicketChange(_newValue) {
|
|
140
|
+
console.debug('onTicketChange', _newValue);
|
|
141
|
+
this.requestLibConnection();
|
|
142
|
+
}
|
|
143
|
+
/** A host can turn the call UI on/off after sign-in (settings screen). */
|
|
144
|
+
onCallsChange(value) {
|
|
145
|
+
this.chatLeoLib?.setCallsEnabled?.(value !== 'off');
|
|
146
|
+
void this.refreshCallsAvailability();
|
|
147
|
+
}
|
|
148
|
+
componentDidLoad() {
|
|
149
|
+
console.debug('ChatLeoComponent:componentDidLoad', this.serverUrl);
|
|
150
|
+
this.requestLibConnection(); // XXX: this triggers: @Prop() "chatStore" on <chatleo-component> is immutable but was modified from within the component.
|
|
151
|
+
// https://stenciljs.com/docs/properties#prop-mutability
|
|
152
|
+
}
|
|
153
|
+
connectedCallback() {
|
|
154
|
+
console.debug(`ChatLeoComponent:connectedCallback`);
|
|
155
|
+
// Register global custom event listeners for external integration
|
|
156
|
+
window.addEventListener(ChatLeoComponent.OPEN_ROOM_EVENT, this.boundOpenRoomListener);
|
|
157
|
+
window.addEventListener(ChatLeoComponent.START_DM_EVENT, this.boundStartDmListener);
|
|
158
|
+
window.addEventListener(ChatLeoComponent.NEW_CHAT_EVENT, this.boundNewChatListener);
|
|
159
|
+
window.addEventListener('chatleo:startCall', this.boundStartCallListener);
|
|
160
|
+
if (typeof navigator !== 'undefined' && 'serviceWorker' in navigator) {
|
|
161
|
+
navigator.serviceWorker.addEventListener('message', this.boundServiceWorkerMessage);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
disconnectedCallback() {
|
|
165
|
+
console.debug('ChatLeoComponent:disconnectedCallback');
|
|
166
|
+
this.chatLeoLib?.unregisterClient(this);
|
|
167
|
+
window.removeEventListener(ChatLeoComponent.OPEN_ROOM_EVENT, this.boundOpenRoomListener);
|
|
168
|
+
window.removeEventListener(ChatLeoComponent.START_DM_EVENT, this.boundStartDmListener);
|
|
169
|
+
window.removeEventListener(ChatLeoComponent.NEW_CHAT_EVENT, this.boundNewChatListener);
|
|
170
|
+
window.removeEventListener('chatleo:startCall', this.boundStartCallListener);
|
|
171
|
+
if (typeof navigator !== 'undefined' && 'serviceWorker' in navigator) {
|
|
172
|
+
navigator.serviceWorker.removeEventListener('message', this.boundServiceWorkerMessage);
|
|
173
|
+
}
|
|
174
|
+
this.chatStore?.removeEventListener('callRinging', this.boundCallRinging);
|
|
175
|
+
this.chatStore?.removeEventListener('callChanged', this.boundCallChanged);
|
|
176
|
+
this.chatStore?.removeEventListener('activeRoomChanged', this.boundActiveRoomChanged);
|
|
177
|
+
this.chatStore?.removeEventListener('unreadTotalChanged', this.boundUnreadTotalChanged);
|
|
178
|
+
this.chatStore?.removeEventListener('callRole', this.boundCallRole);
|
|
179
|
+
this.stopRingtone();
|
|
180
|
+
this.callsChannel?.close();
|
|
181
|
+
}
|
|
182
|
+
async requestLibConnection() {
|
|
183
|
+
console.debug('requestLibConnection', this.chatLeoLib);
|
|
184
|
+
this.chatLeoLib?.setCallsEnabled?.(this.calls !== 'off');
|
|
185
|
+
if (this.pushSwPath)
|
|
186
|
+
this.chatLeoLib?.setPushServiceWorkerPath?.(this.pushSwPath);
|
|
187
|
+
// Register and request connection; ticket preferred when provided
|
|
188
|
+
await this.chatLeoLib?.requestConnection(this, {
|
|
189
|
+
...(this.ticket ? { ticket: this.ticket } : {}),
|
|
190
|
+
...(this.transport ? { transport: this.transport } : {}),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
// ChatLeoClient callbacks
|
|
194
|
+
/**
|
|
195
|
+
* @function setLoading
|
|
196
|
+
* @description This method is part of the `ChatLeoClient` interface. It is called by the `ChatLeoLib` to update the component's loading state.
|
|
197
|
+
* @param {boolean} loading - A boolean indicating whether the application is in a loading state.
|
|
198
|
+
*/
|
|
199
|
+
setLoading(loading) {
|
|
200
|
+
this.loading = loading;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* @function setLoggedIn
|
|
204
|
+
* @description This method is part of the `ChatLeoClient` interface. It is called by the `ChatLeoLib` to update the component's logged-in state.
|
|
205
|
+
* @param {boolean} isLoggedIn - A boolean indicating whether the user is logged in.
|
|
206
|
+
*/
|
|
207
|
+
setLoggedIn(isLoggedIn) {
|
|
208
|
+
// XXX: The state/prop "isLoggedIn" changed during "componentDidLoad()", this triggers extra re-renders, try to setup on "componentWillLoad()"
|
|
209
|
+
this.isLoggedIn = isLoggedIn;
|
|
210
|
+
if (isLoggedIn) {
|
|
211
|
+
void this.refreshCallsAvailability();
|
|
212
|
+
void this.refreshPush();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* @function setSessionExpired
|
|
217
|
+
* @description Called by ChatLeoLib when token refresh fails. Shows an overlay prompting the user to reload.
|
|
218
|
+
*/
|
|
219
|
+
setSessionExpired(expired) {
|
|
220
|
+
this.isSessionExpired = expired;
|
|
221
|
+
}
|
|
222
|
+
/** Called by ChatLeoLib when the socket connection status changes. */
|
|
223
|
+
setConnectionStatus(status) {
|
|
224
|
+
this.connectionStatus = status;
|
|
225
|
+
}
|
|
226
|
+
// --- Public API Methods (callable from DOM element) ---
|
|
227
|
+
/**
|
|
228
|
+
* @function getConnectionStatus
|
|
229
|
+
* @description Returns the current connection and session status of the chat component.
|
|
230
|
+
*
|
|
231
|
+
* Embedding applications should call this method on `window` focus events (or any
|
|
232
|
+
* other relevant trigger) to determine whether the user's session is still valid
|
|
233
|
+
* and whether the page needs to be reloaded.
|
|
234
|
+
*
|
|
235
|
+
* @returns {Promise<{ isConnected: boolean; isSessionExpired: boolean }>}
|
|
236
|
+
* - `isConnected` – `true` when the underlying WebSocket is currently connected.
|
|
237
|
+
* - `isSessionExpired` – `true` when the token refresh has permanently failed
|
|
238
|
+
* (HTTP 401/403 from the refresh endpoint, or too many transient errors).
|
|
239
|
+
* When this is `true` the user must reload the page to restore the session.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* const chatEl = document.querySelector('chatleo-component');
|
|
243
|
+
*
|
|
244
|
+
* // Check on every tab-focus whether a reload is needed
|
|
245
|
+
* window.addEventListener('focus', async () => {
|
|
246
|
+
* const { isSessionExpired } = await chatEl.getConnectionStatus();
|
|
247
|
+
* if (isSessionExpired) {
|
|
248
|
+
* window.location.reload();
|
|
249
|
+
* }
|
|
250
|
+
* });
|
|
251
|
+
*/
|
|
252
|
+
async getConnectionStatus() {
|
|
253
|
+
return {
|
|
254
|
+
isConnected: this.chatStore?.isConnected ?? false,
|
|
255
|
+
isSessionExpired: this.isSessionExpired || (this.chatStore?.isSessionExpired ?? false),
|
|
256
|
+
connectionStatus: this.chatStore?.connectionStatus ?? this.connectionStatus,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* @function openRoom
|
|
261
|
+
* @description This method provides a public API to programmatically open a specific chat room in the tray view. It calls the `openChatPanel` method on the `chatleo-tray-component` element.
|
|
262
|
+
* @param {string} roomId - The ID of the room to be opened.
|
|
263
|
+
*/
|
|
264
|
+
async openRoom(roomId) {
|
|
265
|
+
if (!roomId) {
|
|
266
|
+
console.warn('[chatleo-component] openRoom called without roomId');
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (this.useTray) {
|
|
270
|
+
await this.trayEl?.openChatPanel(roomId, false);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
await this.chatEl?.openRoom?.(roomId);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* @function closeRoom
|
|
277
|
+
* @description Returns to the room list (used for the device back action and deep links
|
|
278
|
+
* that could not be opened).
|
|
279
|
+
*/
|
|
280
|
+
async closeRoom() {
|
|
281
|
+
if (this.useTray) {
|
|
282
|
+
await this.trayEl?.closeChatPanel?.();
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
await this.chatEl?.closeRoom?.();
|
|
286
|
+
}
|
|
287
|
+
/** The currently open room, or `null` on the room list. */
|
|
288
|
+
async getActiveRoomId() {
|
|
289
|
+
return this.chatStore?.activeRoomId ?? null;
|
|
290
|
+
}
|
|
291
|
+
/** Unsent composer text (used to preserve a draft across an app update). */
|
|
292
|
+
async getDraft() {
|
|
293
|
+
return (await this.chatEl?.getDraft?.()) ?? '';
|
|
294
|
+
}
|
|
295
|
+
/** Restores unsent composer text. */
|
|
296
|
+
async setDraft(text) {
|
|
297
|
+
if (text)
|
|
298
|
+
await this.chatEl?.setDraft?.(text);
|
|
299
|
+
}
|
|
300
|
+
/** Adds shared files to the composer of the open room. */
|
|
301
|
+
async addFiles(files) {
|
|
302
|
+
await this.chatEl?.addFiles?.(files ?? []);
|
|
303
|
+
}
|
|
304
|
+
/** Focuses the composer (share text, deep link). */
|
|
305
|
+
async focusComposer() {
|
|
306
|
+
await this.chatEl?.focusComposer?.();
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* @function openDirectMessageWithUser
|
|
310
|
+
* @description This method allows programmatically opening a direct message conversation with a specific user. It will either find an existing DM room or create a new one.
|
|
311
|
+
* @param {string} userId - The ID of the user to start a direct message with.
|
|
312
|
+
* @param use_external_id
|
|
313
|
+
*/
|
|
314
|
+
async openDirectMessageWithUser(userId, use_external_id = false) {
|
|
315
|
+
if (!userId) {
|
|
316
|
+
console.warn('[chatleo-component] openDirectMessageWithUser called without userId');
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
await this.internalStartDmFlow(userId, use_external_id);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* @function openNewChatDraft
|
|
323
|
+
* @description This method programmatically opens the new chat draft view in the tray, allowing the user to start a new conversation.
|
|
324
|
+
*/
|
|
325
|
+
async openNewChatDraft() {
|
|
326
|
+
await this.trayEl?.openChatPanel(undefined, true);
|
|
327
|
+
}
|
|
328
|
+
// --- Internal helpers reused by events & @Method API ---
|
|
329
|
+
async internalStartDmFlow(userId, use_external_id = false) {
|
|
330
|
+
if (!userId)
|
|
331
|
+
return;
|
|
332
|
+
try {
|
|
333
|
+
// await this.trayEl?.openChatPanel(undefined, true); // pending state while ensuring DM
|
|
334
|
+
const existingRoomId = this.chatLeoLib?.findDirectMessageRoomIdByUser(userId);
|
|
335
|
+
console.debug(`internalStartDmFlow`, { existingRoomId });
|
|
336
|
+
if (existingRoomId) {
|
|
337
|
+
await this.openRoom(existingRoomId);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const ensureResult = await this.chatLeoLib?.ensureDirectMessageRoom(userId, use_external_id);
|
|
341
|
+
const roomId = ensureResult?.roomId;
|
|
342
|
+
if (roomId) {
|
|
343
|
+
await this.openRoom(roomId);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
console.warn('[chatleo-component] ensureDirectMessageRoom returned no roomId');
|
|
347
|
+
await this.trayEl?.openChatPanel(undefined, false);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
catch (e) {
|
|
351
|
+
console.error('[chatleo-component] Failed to start DM', e);
|
|
352
|
+
await this.trayEl?.openChatPanel(undefined, false);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// --- Global external event handlers ---
|
|
356
|
+
async handleExternalOpenRoom(event) {
|
|
357
|
+
// Allow sloppy callers that forgot { detail: { roomId }} and instead passed { roomId }
|
|
358
|
+
const sloppy = event.roomId;
|
|
359
|
+
const roomId = event?.detail?.roomId || sloppy;
|
|
360
|
+
if (!roomId) {
|
|
361
|
+
if (!event?.detail) {
|
|
362
|
+
console.warn('[chatleo-component] chatleo:openRoom event missing detail. Use new CustomEvent("chatleo:openRoom", { detail: { roomId: "..." } })');
|
|
363
|
+
}
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
await this.openRoom(roomId);
|
|
367
|
+
}
|
|
368
|
+
async handleExternalStartDm(event) {
|
|
369
|
+
console.log('handleExternalStartDm', event);
|
|
370
|
+
// Support sloppy dispatch new CustomEvent('chatleo:startDM', { userId })
|
|
371
|
+
const sloppy = event.userId;
|
|
372
|
+
const userId = event?.detail?.userId || sloppy;
|
|
373
|
+
const use_external_id = event?.detail?.use_external_id ?? false;
|
|
374
|
+
if (!userId) {
|
|
375
|
+
if (!event?.detail) {
|
|
376
|
+
console.warn('[chatleo-component] chatleo:startDM event missing detail. Dispatch like: new CustomEvent("chatleo:startDM", { detail: { userId: "123" } })');
|
|
377
|
+
}
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
await this.openDirectMessageWithUser(userId, use_external_id);
|
|
381
|
+
}
|
|
382
|
+
async handleExternalNewChat(_event) {
|
|
383
|
+
await this.openNewChatDraft();
|
|
384
|
+
}
|
|
385
|
+
// --- Calls -----------------------------------------------------------------
|
|
386
|
+
async refreshCallsAvailability() {
|
|
387
|
+
if (this.calls === 'off' || !this.chatLeoLib?.ensureCallsAvailable) {
|
|
388
|
+
this.callsAvailable = false;
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
this.callsAvailable = await this.chatLeoLib.ensureCallsAvailable();
|
|
392
|
+
}
|
|
393
|
+
async loadCallComponents() {
|
|
394
|
+
if (typeof window === 'undefined' || window.customElements.get('chatleo-call-adapter'))
|
|
395
|
+
return true;
|
|
396
|
+
try {
|
|
397
|
+
// The self-contained custom-elements build: importing it defines the adapter and every
|
|
398
|
+
// call component it renders. It is bundled into this build as a lazy chunk, so it loads
|
|
399
|
+
// from wherever the chat components are served (the lazy loader of call-components would
|
|
400
|
+
// look for its own entry files next to this build and not find them).
|
|
401
|
+
await import('@chat-leo/call-components/components/chatleo-call-adapter.js');
|
|
402
|
+
return !!window.customElements.get('chatleo-call-adapter');
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
console.warn('[chatleo-component] call components could not be loaded', error);
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
async startOrJoinCall(roomId, callId, mode) {
|
|
410
|
+
if (!this.chatLeoLib)
|
|
411
|
+
return;
|
|
412
|
+
// Already in this call (the chat was in front): show it again instead of joining twice.
|
|
413
|
+
const running = this.callView && (callId ? this.callView.callId === callId : this.callView.roomId === roomId);
|
|
414
|
+
if (running) {
|
|
415
|
+
this.showCall = true;
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
try {
|
|
419
|
+
const room = this.chatStore?.rooms.find(candidate => candidate.id === roomId);
|
|
420
|
+
const call = callId ? { id: callId, mode: room?.type === 'DirectMessage' ? 'direct' : 'group' } : await this.chatLeoLib.startCall(roomId, mode);
|
|
421
|
+
const credentials = await this.chatLeoLib.joinCall(call.id);
|
|
422
|
+
const loaded = await this.loadCallComponents();
|
|
423
|
+
if (!loaded)
|
|
424
|
+
return;
|
|
425
|
+
this.callView = {
|
|
426
|
+
callId: call.id,
|
|
427
|
+
roomId,
|
|
428
|
+
// The join response names the mode: a call joined from the banner may be a stage call.
|
|
429
|
+
mode: credentials.mode ?? call.mode,
|
|
430
|
+
credentials: {
|
|
431
|
+
sfuUrl: credentials.sfu_url,
|
|
432
|
+
token: credentials.token,
|
|
433
|
+
roomId: credentials.room_id,
|
|
434
|
+
mode: credentials.mode,
|
|
435
|
+
iceServers: credentials.ice_servers,
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
this.showCall = true;
|
|
439
|
+
this.incomingCall = null;
|
|
440
|
+
this.stopRingtone();
|
|
441
|
+
}
|
|
442
|
+
catch (error) {
|
|
443
|
+
console.warn('[chatleo-component] call start/join failed', error);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
onIncomingCallChange(call) {
|
|
447
|
+
if (!call)
|
|
448
|
+
return;
|
|
449
|
+
setTimeout(() => this.incomingRef?.focus(), 0);
|
|
450
|
+
}
|
|
451
|
+
handleCallRinging(event) {
|
|
452
|
+
this.incomingCall = event.detail?.call ?? null;
|
|
453
|
+
if (this.incomingCall)
|
|
454
|
+
this.startRingtone(this.incomingCall.id);
|
|
455
|
+
else
|
|
456
|
+
this.stopRingtone();
|
|
457
|
+
}
|
|
458
|
+
handleCallChanged(event) {
|
|
459
|
+
if (this.callView && !event.detail?.call) {
|
|
460
|
+
this.callView = null;
|
|
461
|
+
this.showCall = false;
|
|
462
|
+
this.stopRingtone();
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
async acceptIncomingCall() {
|
|
466
|
+
if (!this.incomingCall)
|
|
467
|
+
return;
|
|
468
|
+
const call = this.incomingCall;
|
|
469
|
+
this.incomingCall = null;
|
|
470
|
+
this.stopRingtone();
|
|
471
|
+
await this.startOrJoinCall(call.room_id, call.id);
|
|
472
|
+
}
|
|
473
|
+
async declineIncomingCall() {
|
|
474
|
+
if (!this.incomingCall || !this.chatLeoLib)
|
|
475
|
+
return;
|
|
476
|
+
const call = this.incomingCall;
|
|
477
|
+
this.incomingCall = null;
|
|
478
|
+
this.stopRingtone();
|
|
479
|
+
try {
|
|
480
|
+
await this.chatLeoLib.declineCall(call.id);
|
|
481
|
+
}
|
|
482
|
+
catch (error) {
|
|
483
|
+
console.warn('[chatleo-component] decline failed', error);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
handleExternalStartCall(event) {
|
|
487
|
+
const roomId = event?.detail?.roomId;
|
|
488
|
+
if (roomId)
|
|
489
|
+
void this.startOrJoinCall(roomId, undefined, event.detail.mode);
|
|
490
|
+
}
|
|
491
|
+
/** ChatLeo changed this user's role in a stage call: present a new token so the SFU applies it. */
|
|
492
|
+
handleCallRole(event) {
|
|
493
|
+
const { callId, userId } = event.detail ?? {};
|
|
494
|
+
if (!this.callView || this.callView.callId !== callId)
|
|
495
|
+
return;
|
|
496
|
+
if (userId && userId !== this.chatStore?.profile?.id)
|
|
497
|
+
return;
|
|
498
|
+
this.callAdapterRef
|
|
499
|
+
?.refreshToken?.()
|
|
500
|
+
.catch(error => console.warn('[chatleo-component] token refresh after a role change failed', error));
|
|
501
|
+
}
|
|
502
|
+
/** Fresh SFU credentials for the running call: token expiry and role changes. */
|
|
503
|
+
callToken = async () => {
|
|
504
|
+
const view = this.callView;
|
|
505
|
+
if (!view || !this.chatLeoLib)
|
|
506
|
+
throw new Error('no call');
|
|
507
|
+
const fresh = await this.chatLeoLib.refreshCallToken(view.callId);
|
|
508
|
+
return { token: fresh.token, sfuUrl: fresh.sfu_url, iceServers: fresh.ice_servers };
|
|
509
|
+
};
|
|
510
|
+
promoteInCall = async (_participantId, _capabilities, participant) => {
|
|
511
|
+
const view = this.callView;
|
|
512
|
+
if (!view || !this.chatLeoLib || !participant?.userId)
|
|
513
|
+
throw new Error('unknown participant');
|
|
514
|
+
await this.chatLeoLib.promoteCallParticipant(view.callId, participant.userId);
|
|
515
|
+
};
|
|
516
|
+
demoteInCall = async (_participantId, participant) => {
|
|
517
|
+
const view = this.callView;
|
|
518
|
+
if (!view || !this.chatLeoLib || !participant?.userId)
|
|
519
|
+
throw new Error('unknown participant');
|
|
520
|
+
await this.chatLeoLib.demoteCallParticipant(view.callId, participant.userId);
|
|
521
|
+
};
|
|
522
|
+
startRingtone(callId) {
|
|
523
|
+
if (typeof window === 'undefined')
|
|
524
|
+
return;
|
|
525
|
+
this.callsChannel ??= typeof BroadcastChannel !== 'undefined' ? new BroadcastChannel('chatleo-calls') : undefined;
|
|
526
|
+
if (this.callsChannel) {
|
|
527
|
+
const claimed = this.callsChannel;
|
|
528
|
+
const handler = (event) => {
|
|
529
|
+
if (event.data?.type === 'ring' && event.data.callId === callId)
|
|
530
|
+
this.stopRingtone();
|
|
531
|
+
};
|
|
532
|
+
claimed.addEventListener('message', handler, { once: true });
|
|
533
|
+
claimed.postMessage({ type: 'ring', callId });
|
|
534
|
+
}
|
|
535
|
+
try {
|
|
536
|
+
const context = this.callRingtoneContext ?? new AudioContext();
|
|
537
|
+
this.callRingtoneContext = context;
|
|
538
|
+
const beep = () => {
|
|
539
|
+
const oscillator = context.createOscillator();
|
|
540
|
+
const gain = context.createGain();
|
|
541
|
+
oscillator.frequency.value = 660;
|
|
542
|
+
gain.gain.value = 0.04;
|
|
543
|
+
oscillator.connect(gain).connect(context.destination);
|
|
544
|
+
oscillator.start();
|
|
545
|
+
setTimeout(() => oscillator.stop(), 180);
|
|
546
|
+
};
|
|
547
|
+
beep();
|
|
548
|
+
this.callRingtoneTimer = setInterval(beep, 1200);
|
|
549
|
+
}
|
|
550
|
+
catch {
|
|
551
|
+
// Autoplay or WebAudio may be unavailable; the visual ringing is enough.
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
stopRingtone() {
|
|
555
|
+
if (this.callRingtoneTimer) {
|
|
556
|
+
clearInterval(this.callRingtoneTimer);
|
|
557
|
+
this.callRingtoneTimer = undefined;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
async refreshPush() {
|
|
561
|
+
if (this.push === 'off' || !this.chatLeoLib?.pushState) {
|
|
562
|
+
this.pushState = null;
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
try {
|
|
566
|
+
this.pushState = await this.chatLeoLib.pushState();
|
|
567
|
+
}
|
|
568
|
+
catch {
|
|
569
|
+
this.pushState = null;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
async enablePush() {
|
|
573
|
+
if (!this.chatLeoLib?.enablePush)
|
|
574
|
+
return;
|
|
575
|
+
try {
|
|
576
|
+
this.pushState = await this.chatLeoLib.enablePush();
|
|
577
|
+
this.pushPromptDismissed = true;
|
|
578
|
+
}
|
|
579
|
+
catch (error) {
|
|
580
|
+
console.warn('[chatleo-component] enabling push failed', error);
|
|
581
|
+
await this.refreshPush();
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
async disablePush() {
|
|
585
|
+
if (!this.chatLeoLib?.disablePush)
|
|
586
|
+
return;
|
|
587
|
+
try {
|
|
588
|
+
this.pushState = await this.chatLeoLib.disablePush();
|
|
589
|
+
}
|
|
590
|
+
catch (error) {
|
|
591
|
+
console.warn('[chatleo-component] disabling push failed', error);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
handleServiceWorkerMessage(event) {
|
|
595
|
+
if (event.data?.type === 'chatleo:pushVisibility') {
|
|
596
|
+
const roomId = String(event.data.roomId ?? '');
|
|
597
|
+
const visible = typeof document !== 'undefined' && document.visibilityState === 'visible' && this.chatStore?.activeRoomId === roomId;
|
|
598
|
+
event.ports?.[0]?.postMessage({ visible });
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
if (event.data?.type === 'chatleo:openRoom' && event.data.roomId) {
|
|
602
|
+
void this.openRoom(String(event.data.roomId));
|
|
603
|
+
if (typeof navigator !== 'undefined' && 'clearAppBadge' in navigator) {
|
|
604
|
+
void navigator.clearAppBadge();
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
renderPushControl() {
|
|
609
|
+
if (this.push === 'off' || !this.pushState)
|
|
610
|
+
return null;
|
|
611
|
+
const state = this.pushState;
|
|
612
|
+
if (state.availability === 'ios_install_required') {
|
|
613
|
+
return h("div", { class: "push-control push-control--hint" }, "Add ChatLeo to your home screen to enable notifications.");
|
|
614
|
+
}
|
|
615
|
+
if (state.availability !== 'available')
|
|
616
|
+
return null;
|
|
617
|
+
if (state.permission === 'denied') {
|
|
618
|
+
return h("div", { class: "push-control push-control--hint" }, "Notifications are blocked in your browser settings.");
|
|
619
|
+
}
|
|
620
|
+
if (state.subscribed && state.accountEnabled) {
|
|
621
|
+
return (h("button", { type: "button", class: "push-control", onClick: () => void this.disablePush() }, "Notifications on"));
|
|
622
|
+
}
|
|
623
|
+
if (this.push === 'prompt' && !this.pushPromptDismissed) {
|
|
624
|
+
return (h("div", { class: "push-control push-control--prompt", role: "region", "aria-label": "Enable notifications" }, h("span", null, "Get notified about new messages when ChatLeo is in the background."), h("button", { type: "button", onClick: () => void this.enablePush() }, "Enable"), h("button", { type: "button", class: "push-control__secondary", onClick: () => {
|
|
625
|
+
this.pushPromptDismissed = true;
|
|
626
|
+
} }, "Not now")));
|
|
627
|
+
}
|
|
628
|
+
return (h("button", { type: "button", class: "push-control", onClick: () => void this.enablePush() }, "Enable notifications"));
|
|
629
|
+
}
|
|
630
|
+
identityResolver = {
|
|
631
|
+
resolve: (ids) => Object.fromEntries(ids.map(id => {
|
|
632
|
+
const user = this.chatStore?.usernameResolver(id);
|
|
633
|
+
return [
|
|
634
|
+
id,
|
|
635
|
+
{
|
|
636
|
+
displayName: user?.display_name ?? id,
|
|
637
|
+
avatarUrl: user?.profile_picture_url ?? undefined,
|
|
638
|
+
},
|
|
639
|
+
];
|
|
640
|
+
})),
|
|
641
|
+
};
|
|
642
|
+
/**
|
|
643
|
+
* The call cannot go on for this user: they were removed or lost access, joined on another
|
|
644
|
+
* device, the room ended, or the connection could not be restored. Close the call view.
|
|
645
|
+
*/
|
|
646
|
+
onCallError(event) {
|
|
647
|
+
const view = this.callView;
|
|
648
|
+
const code = event.detail?.code;
|
|
649
|
+
if (!view || !code || !['auth_rejected', 'removed', 'session_replaced', 'room_ended', 'room_full', 'network_failed'].includes(code))
|
|
650
|
+
return;
|
|
651
|
+
this.callView = null;
|
|
652
|
+
this.showCall = false;
|
|
653
|
+
// After a failure to reconnect the server still counts this device as in the call.
|
|
654
|
+
if (code === 'network_failed')
|
|
655
|
+
this.chatLeoLib?.leaveCall(view.callId).catch(() => undefined);
|
|
656
|
+
}
|
|
657
|
+
/** The user hung up in the call room: tell the server and return to the conversation. */
|
|
658
|
+
onCallLeft() {
|
|
659
|
+
const view = this.callView;
|
|
660
|
+
if (!view)
|
|
661
|
+
return;
|
|
662
|
+
this.callView = null;
|
|
663
|
+
this.showCall = false;
|
|
664
|
+
this.chatLeoLib?.leaveCall(view.callId).catch(error => console.warn('[chatleo-component] leave failed', error));
|
|
665
|
+
}
|
|
666
|
+
onCallRequested(event) {
|
|
667
|
+
const detail = event.detail;
|
|
668
|
+
if (detail?.roomId)
|
|
669
|
+
void this.startOrJoinCall(detail.roomId, detail.callId);
|
|
670
|
+
}
|
|
671
|
+
//
|
|
672
|
+
/**
|
|
673
|
+
* @function onNewChatClicked
|
|
674
|
+
* @description A listener for the `newChatClicked` event. This event is handled within the tray component to open the user selector.
|
|
675
|
+
* @param {CustomEvent<string>} _event - The custom event object.
|
|
676
|
+
*/
|
|
677
|
+
onNewChatClicked(_event) {
|
|
678
|
+
// handled inside tray to open selector
|
|
679
|
+
}
|
|
680
|
+
// from in site
|
|
681
|
+
/**
|
|
682
|
+
* @function onChatMessage
|
|
683
|
+
* @description This listener captures the `messageChatSent` event, which is fired by child components when a user sends a message. It then calls the `sendChatMessage` method on the `chatLeoLib` to send the message to the server.
|
|
684
|
+
* @param {CustomEvent<ChatMessageSent>} event - The custom event containing the message payload.
|
|
685
|
+
*/
|
|
686
|
+
onChatMessage(event) {
|
|
687
|
+
console.debug(`messageChatSent`, event);
|
|
688
|
+
this.chatLeoLib?.sendChatMessage(event.detail);
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* @function onUserSelectedForChat
|
|
692
|
+
* @description This listener handles the `userSelected` event, which is fired when a user is selected from the new message selector. It initiates the process of starting a new direct message conversation with the selected user.
|
|
693
|
+
* @param {CustomEvent<UserProfile>} event - The custom event containing the profile of the selected user.
|
|
694
|
+
*/
|
|
695
|
+
async onUserSelectedForChat(event) {
|
|
696
|
+
const user = event.detail;
|
|
697
|
+
if (!user || !user.id)
|
|
698
|
+
return;
|
|
699
|
+
await this.internalStartDmFlow(user.id);
|
|
700
|
+
}
|
|
701
|
+
//
|
|
702
|
+
/**
|
|
703
|
+
* @function render
|
|
704
|
+
* @description The render method for the `ChatLeoComponent`. It conditionally renders the `chatleo-chat` (main view), `chatleo-tray-component`, or `chatleo-room-view` based on the `useMain`, `useTray`, and `useRoomView` props.
|
|
705
|
+
* @returns {any} A VNode representing the component's UI.
|
|
706
|
+
*/
|
|
707
|
+
get _connectionBannerLabel() {
|
|
708
|
+
switch (this.connectionStatus) {
|
|
709
|
+
case 'connecting':
|
|
710
|
+
return 'Verbindung wird hergestellt…';
|
|
711
|
+
case 'reconnecting':
|
|
712
|
+
return 'Verbindung wird wiederhergestellt…';
|
|
713
|
+
case 'disconnected':
|
|
714
|
+
return 'Offline';
|
|
715
|
+
default:
|
|
716
|
+
return null;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
render() {
|
|
720
|
+
const bannerLabel = this._connectionBannerLabel;
|
|
721
|
+
return (h("div", { key: 'd0c7c84ebf5fe164868f6e2250252a0899493ee3', style: { height: '100%', maxHeight: 'inherit', width: '100%', display: 'flex', flexDirection: 'column', position: 'relative', overflow: 'hidden', minHeight: '0' } }, this.renderPushControl(), bannerLabel && !this.isSessionExpired && (h("div", { key: 'd5147662da351b027aba0542ae3dc5af161d2aa3', class: `connection-banner connection-banner--${this.connectionStatus}` }, h("span", { key: '43cad2fcb7fd75d099fa8b73f482e7eb282c0957', class: "connection-banner__dot" }), bannerLabel)), this.useMain && h("chatleo-chat", { key: '609457ee0ab1ceaa2484d91d4c54d734770f4d01', ref: el => (this.chatEl = el), chatStore: this.chatStore, callsAvailable: this.callsAvailable, inCall: !!this.callView }), this.useTray && h("chatleo-tray-component", { key: 'ebd656fd966561d4f982859b9c36a1e233b204b6', chatStore: this.chatStore, ref: el => (this.trayEl = el) }), this.useRoomView && (h("chatleo-room-view", { key: '6af1a89788728c21f72ee1a31b7e70bd7d096f0f', chatStore: this.chatStore, roomId: this.roomId, isOnline: this.chatStore?.isConnected ?? false, pending: this.loading, callsAvailable: this.callsAvailable, inCall: !!this.callView })), this.callView && (h("div", { key: '3a346cdaf24c1fe758f86e1233cc4626db023a32', class: "call-layer", style: { display: this.showCall ? 'flex' : 'none' } }, h("button", { key: '7720dc641239eb8da833c63c1f30d4ed29fece7c', type: "button", class: "call-layer__back", onClick: () => {
|
|
722
|
+
this.showCall = false;
|
|
723
|
+
} }, "Chat"), h('chatleo-call-adapter', {
|
|
724
|
+
ref: (el) => (this.callAdapterRef = el),
|
|
725
|
+
callId: this.callView.callId,
|
|
726
|
+
mode: this.callView.mode,
|
|
727
|
+
connection: this.callView.credentials,
|
|
728
|
+
autoJoin: true,
|
|
729
|
+
identity: this.identityResolver,
|
|
730
|
+
getToken: this.callToken,
|
|
731
|
+
promoteHandler: this.promoteInCall,
|
|
732
|
+
demoteHandler: this.demoteInCall,
|
|
733
|
+
style: { flex: '1', minHeight: '0' },
|
|
734
|
+
}))), this.incomingCall && (h("div", { key: 'ebdc317f30b07009f41f7f729b9e8631ea039752', class: "incoming-call", role: "dialog", "aria-modal": "true", "aria-label": `Incoming call from ${this.incomingCall.caller.display_name ?? this.incomingCall.caller.id}`, tabIndex: -1, ref: el => (this.incomingRef = el) }, h("div", { key: '4eac45f10551a47c7bf1ad8035a9da5ed2955e29', class: "incoming-call__box" }, h("p", { key: '6f74dee9aa261dc889b70c18e5b110e18b1a2111', class: "incoming-call__eyebrow" }, "Incoming call"), h("chatleo-avatar", { key: 'e097d46809d6202d64ebc1eaf42418b74c990e80', name: this.incomingCall.caller.display_name ?? this.incomingCall.caller.id, url: this.incomingCall.caller.profile_picture_url ?? null, isOnline: false }), h("p", { key: 'b160c0021f003d230d5fb544d82fd8d23f7df332', class: "incoming-call__name" }, this.incomingCall.caller.display_name ?? this.incomingCall.caller.id), h("div", { key: 'b238c1352384a0f14a2abd130fe0f3495da156f3', class: "incoming-call__actions" }, h("button", { key: '1b44cc1c87dfb89b4715fb370c490a05d97b6512', type: "button", class: "incoming-call__accept", onClick: () => void this.acceptIncomingCall() }, "Accept"), h("button", { key: '97276ec614d0be526f16573a3d0e9f6cb9e24b7c', type: "button", class: "incoming-call__decline", onClick: () => void this.declineIncomingCall() }, "Decline"))))), this.isSessionExpired && (h("div", { key: 'b387b49bc31378c63c6520a95bf732c47a142e88', class: "session-expired-overlay" }, h("div", { key: '118687b87cc612d9ad47692a3e8f2a38f3b71f32', class: "session-expired-box" }, h("svg", { key: '562cf50bb4f6cdd0e4076267c6dea5f8b76b06d7', class: "session-expired-icon", xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none" }, h("path", { key: '628579c8dad4064d6fcfdfd75801160fe8f0ef8f', d: "M12 9v4M12 17h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" })), h("p", { key: 'e49e2388dad8df0e961cb7e0dc605a4011775eed', class: "session-expired-title" }, "Session abgelaufen"), h("p", { key: '0b69cf4687411c7e9f117712b28da57bc798ce07', class: "session-expired-message" }, "Deine Sitzung ist abgelaufen. Bitte lade die Seite neu, um fortzufahren."), h("button", { key: '9532b50dccc9f05dc3ee4a5ea2b28eea462a0ed1', class: "session-expired-button", onClick: () => window.location.reload() }, "Seite neu laden"))))));
|
|
735
|
+
}
|
|
736
|
+
static get is() { return "chatleo-component"; }
|
|
737
|
+
static get encapsulation() { return "shadow"; }
|
|
738
|
+
static get originalStyleUrls() {
|
|
739
|
+
return {
|
|
740
|
+
"$": ["chatleo-component.css"]
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
static get styleUrls() {
|
|
744
|
+
return {
|
|
745
|
+
"$": ["chatleo-component.css"]
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
static get properties() {
|
|
749
|
+
return {
|
|
750
|
+
"username": {
|
|
751
|
+
"type": "string",
|
|
752
|
+
"mutable": false,
|
|
753
|
+
"complexType": {
|
|
754
|
+
"original": "string",
|
|
755
|
+
"resolved": "string",
|
|
756
|
+
"references": {}
|
|
757
|
+
},
|
|
758
|
+
"required": false,
|
|
759
|
+
"optional": false,
|
|
760
|
+
"docs": {
|
|
761
|
+
"tags": [],
|
|
762
|
+
"text": "The username of the user, which can be used for authentication."
|
|
763
|
+
},
|
|
764
|
+
"getter": false,
|
|
765
|
+
"setter": false,
|
|
766
|
+
"reflect": false,
|
|
767
|
+
"attribute": "username"
|
|
768
|
+
},
|
|
769
|
+
"ticket": {
|
|
770
|
+
"type": "string",
|
|
771
|
+
"mutable": false,
|
|
772
|
+
"complexType": {
|
|
773
|
+
"original": "string",
|
|
774
|
+
"resolved": "string",
|
|
775
|
+
"references": {}
|
|
776
|
+
},
|
|
777
|
+
"required": false,
|
|
778
|
+
"optional": false,
|
|
779
|
+
"docs": {
|
|
780
|
+
"tags": [],
|
|
781
|
+
"text": "An authentication ticket used to establish a connection with the chat service."
|
|
782
|
+
},
|
|
783
|
+
"getter": false,
|
|
784
|
+
"setter": false,
|
|
785
|
+
"reflect": false,
|
|
786
|
+
"attribute": "ticket"
|
|
787
|
+
},
|
|
788
|
+
"useTray": {
|
|
789
|
+
"type": "boolean",
|
|
790
|
+
"mutable": false,
|
|
791
|
+
"complexType": {
|
|
792
|
+
"original": "boolean",
|
|
793
|
+
"resolved": "boolean",
|
|
794
|
+
"references": {}
|
|
795
|
+
},
|
|
796
|
+
"required": false,
|
|
797
|
+
"optional": false,
|
|
798
|
+
"docs": {
|
|
799
|
+
"tags": [],
|
|
800
|
+
"text": "If `true`, the component will render as a tray-based chat widget."
|
|
801
|
+
},
|
|
802
|
+
"getter": false,
|
|
803
|
+
"setter": false,
|
|
804
|
+
"reflect": false,
|
|
805
|
+
"attribute": "use-tray"
|
|
806
|
+
},
|
|
807
|
+
"useMain": {
|
|
808
|
+
"type": "boolean",
|
|
809
|
+
"mutable": false,
|
|
810
|
+
"complexType": {
|
|
811
|
+
"original": "boolean",
|
|
812
|
+
"resolved": "boolean",
|
|
813
|
+
"references": {}
|
|
814
|
+
},
|
|
815
|
+
"required": false,
|
|
816
|
+
"optional": false,
|
|
817
|
+
"docs": {
|
|
818
|
+
"tags": [],
|
|
819
|
+
"text": "If `true`, the component will render as a full-page chat application."
|
|
820
|
+
},
|
|
821
|
+
"getter": false,
|
|
822
|
+
"setter": false,
|
|
823
|
+
"reflect": false,
|
|
824
|
+
"attribute": "use-main",
|
|
825
|
+
"defaultValue": "false"
|
|
826
|
+
},
|
|
827
|
+
"useRoomView": {
|
|
828
|
+
"type": "boolean",
|
|
829
|
+
"mutable": false,
|
|
830
|
+
"complexType": {
|
|
831
|
+
"original": "boolean",
|
|
832
|
+
"resolved": "boolean",
|
|
833
|
+
"references": {}
|
|
834
|
+
},
|
|
835
|
+
"required": false,
|
|
836
|
+
"optional": false,
|
|
837
|
+
"docs": {
|
|
838
|
+
"tags": [],
|
|
839
|
+
"text": "If `true`, the component will render as a single room view without the room list."
|
|
840
|
+
},
|
|
841
|
+
"getter": false,
|
|
842
|
+
"setter": false,
|
|
843
|
+
"reflect": false,
|
|
844
|
+
"attribute": "use-room-view",
|
|
845
|
+
"defaultValue": "false"
|
|
846
|
+
},
|
|
847
|
+
"roomId": {
|
|
848
|
+
"type": "string",
|
|
849
|
+
"mutable": false,
|
|
850
|
+
"complexType": {
|
|
851
|
+
"original": "string",
|
|
852
|
+
"resolved": "string",
|
|
853
|
+
"references": {}
|
|
854
|
+
},
|
|
855
|
+
"required": false,
|
|
856
|
+
"optional": true,
|
|
857
|
+
"docs": {
|
|
858
|
+
"tags": [],
|
|
859
|
+
"text": "The ID of the room to display when using room view mode."
|
|
860
|
+
},
|
|
861
|
+
"getter": false,
|
|
862
|
+
"setter": false,
|
|
863
|
+
"reflect": false,
|
|
864
|
+
"attribute": "room-id"
|
|
865
|
+
},
|
|
866
|
+
"chatLeoLib": {
|
|
867
|
+
"type": "unknown",
|
|
868
|
+
"mutable": false,
|
|
869
|
+
"complexType": {
|
|
870
|
+
"original": "ChatLeoLib",
|
|
871
|
+
"resolved": "ChatLeoLib",
|
|
872
|
+
"references": {
|
|
873
|
+
"ChatLeoLib": {
|
|
874
|
+
"location": "import",
|
|
875
|
+
"path": "@chat-leo/chatleolib",
|
|
876
|
+
"id": "../chatleolib/dist/index.d.ts::ChatLeoLib",
|
|
877
|
+
"referenceLocation": "ChatLeoLib"
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
},
|
|
881
|
+
"required": false,
|
|
882
|
+
"optional": true,
|
|
883
|
+
"docs": {
|
|
884
|
+
"tags": [],
|
|
885
|
+
"text": "An instance of the `ChatLeoLib` class, which provides the core chat functionalities."
|
|
886
|
+
},
|
|
887
|
+
"getter": false,
|
|
888
|
+
"setter": false
|
|
889
|
+
},
|
|
890
|
+
"chatStore": {
|
|
891
|
+
"type": "unknown",
|
|
892
|
+
"mutable": false,
|
|
893
|
+
"complexType": {
|
|
894
|
+
"original": "ChatStore",
|
|
895
|
+
"resolved": "ChatStore",
|
|
896
|
+
"references": {
|
|
897
|
+
"ChatStore": {
|
|
898
|
+
"location": "import",
|
|
899
|
+
"path": "@chat-leo/chatleolib",
|
|
900
|
+
"id": "../chatleolib/dist/ChatStore.d.ts::ChatStore",
|
|
901
|
+
"referenceLocation": "ChatStore"
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
},
|
|
905
|
+
"required": false,
|
|
906
|
+
"optional": true,
|
|
907
|
+
"docs": {
|
|
908
|
+
"tags": [],
|
|
909
|
+
"text": "An instance of the `ChatStore` class, which manages the application's state."
|
|
910
|
+
},
|
|
911
|
+
"getter": false,
|
|
912
|
+
"setter": false
|
|
913
|
+
},
|
|
914
|
+
"serverUrl": {
|
|
915
|
+
"type": "string",
|
|
916
|
+
"mutable": false,
|
|
917
|
+
"complexType": {
|
|
918
|
+
"original": "string",
|
|
919
|
+
"resolved": "string",
|
|
920
|
+
"references": {}
|
|
921
|
+
},
|
|
922
|
+
"required": false,
|
|
923
|
+
"optional": true,
|
|
924
|
+
"docs": {
|
|
925
|
+
"tags": [],
|
|
926
|
+
"text": ""
|
|
927
|
+
},
|
|
928
|
+
"getter": false,
|
|
929
|
+
"setter": false,
|
|
930
|
+
"reflect": false,
|
|
931
|
+
"attribute": "server-url"
|
|
932
|
+
},
|
|
933
|
+
"transport": {
|
|
934
|
+
"type": "string",
|
|
935
|
+
"mutable": false,
|
|
936
|
+
"complexType": {
|
|
937
|
+
"original": "'auto' | 'socketio' | 'v2'",
|
|
938
|
+
"resolved": "\"auto\" | \"socketio\" | \"v2\"",
|
|
939
|
+
"references": {}
|
|
940
|
+
},
|
|
941
|
+
"required": false,
|
|
942
|
+
"optional": true,
|
|
943
|
+
"docs": {
|
|
944
|
+
"tags": [],
|
|
945
|
+
"text": "Real-time protocol: `socketio` (default), `v2` (ChatLeo Protocol v2) or `auto`\n(use v2 when the server's `/.well-known/chatleo` offers it, otherwise Socket.IO).\nOverrides `ChatLeoLib.transport`."
|
|
946
|
+
},
|
|
947
|
+
"getter": false,
|
|
948
|
+
"setter": false,
|
|
949
|
+
"reflect": false,
|
|
950
|
+
"attribute": "transport"
|
|
951
|
+
},
|
|
952
|
+
"calls": {
|
|
953
|
+
"type": "string",
|
|
954
|
+
"mutable": false,
|
|
955
|
+
"complexType": {
|
|
956
|
+
"original": "'auto' | 'off'",
|
|
957
|
+
"resolved": "\"auto\" | \"off\"",
|
|
958
|
+
"references": {}
|
|
959
|
+
},
|
|
960
|
+
"required": false,
|
|
961
|
+
"optional": false,
|
|
962
|
+
"docs": {
|
|
963
|
+
"tags": [],
|
|
964
|
+
"text": "`auto` shows call controls when the server advertises calls; `off` disables the call UI."
|
|
965
|
+
},
|
|
966
|
+
"getter": false,
|
|
967
|
+
"setter": false,
|
|
968
|
+
"reflect": false,
|
|
969
|
+
"attribute": "calls",
|
|
970
|
+
"defaultValue": "'auto'"
|
|
971
|
+
},
|
|
972
|
+
"push": {
|
|
973
|
+
"type": "string",
|
|
974
|
+
"mutable": false,
|
|
975
|
+
"complexType": {
|
|
976
|
+
"original": "'off' | 'manual' | 'prompt'",
|
|
977
|
+
"resolved": "\"manual\" | \"off\" | \"prompt\"",
|
|
978
|
+
"references": {}
|
|
979
|
+
},
|
|
980
|
+
"required": false,
|
|
981
|
+
"optional": false,
|
|
982
|
+
"docs": {
|
|
983
|
+
"tags": [],
|
|
984
|
+
"text": "`manual` shows a notification control; `prompt` also shows an in-page explanation; `off` hides it."
|
|
985
|
+
},
|
|
986
|
+
"getter": false,
|
|
987
|
+
"setter": false,
|
|
988
|
+
"reflect": false,
|
|
989
|
+
"attribute": "push",
|
|
990
|
+
"defaultValue": "'manual'"
|
|
991
|
+
},
|
|
992
|
+
"pushSwPath": {
|
|
993
|
+
"type": "string",
|
|
994
|
+
"mutable": false,
|
|
995
|
+
"complexType": {
|
|
996
|
+
"original": "string",
|
|
997
|
+
"resolved": "string",
|
|
998
|
+
"references": {}
|
|
999
|
+
},
|
|
1000
|
+
"required": false,
|
|
1001
|
+
"optional": true,
|
|
1002
|
+
"docs": {
|
|
1003
|
+
"tags": [],
|
|
1004
|
+
"text": "Path of the push service worker served by the host."
|
|
1005
|
+
},
|
|
1006
|
+
"getter": false,
|
|
1007
|
+
"setter": false,
|
|
1008
|
+
"reflect": false,
|
|
1009
|
+
"attribute": "push-sw-path"
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
static get states() {
|
|
1014
|
+
return {
|
|
1015
|
+
"isLoggedIn": {},
|
|
1016
|
+
"loading": {},
|
|
1017
|
+
"isSessionExpired": {},
|
|
1018
|
+
"connectionStatus": {},
|
|
1019
|
+
"callsAvailable": {},
|
|
1020
|
+
"incomingCall": {},
|
|
1021
|
+
"callView": {},
|
|
1022
|
+
"showCall": {},
|
|
1023
|
+
"pushState": {},
|
|
1024
|
+
"pushPromptDismissed": {}
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
static get events() {
|
|
1028
|
+
return [{
|
|
1029
|
+
"method": "activeRoomChange",
|
|
1030
|
+
"name": "activeRoomChange",
|
|
1031
|
+
"bubbles": true,
|
|
1032
|
+
"cancelable": true,
|
|
1033
|
+
"composed": true,
|
|
1034
|
+
"docs": {
|
|
1035
|
+
"tags": [],
|
|
1036
|
+
"text": "Fires when the open conversation changes, so a host can drive navigation/history."
|
|
1037
|
+
},
|
|
1038
|
+
"complexType": {
|
|
1039
|
+
"original": "{ roomId: string | null }",
|
|
1040
|
+
"resolved": "{ roomId: string; }",
|
|
1041
|
+
"references": {}
|
|
1042
|
+
}
|
|
1043
|
+
}, {
|
|
1044
|
+
"method": "unreadTotalChange",
|
|
1045
|
+
"name": "unreadTotalChange",
|
|
1046
|
+
"bubbles": true,
|
|
1047
|
+
"cancelable": true,
|
|
1048
|
+
"composed": true,
|
|
1049
|
+
"docs": {
|
|
1050
|
+
"tags": [],
|
|
1051
|
+
"text": "Fires when the total unread count changes (app badge, title, ...)."
|
|
1052
|
+
},
|
|
1053
|
+
"complexType": {
|
|
1054
|
+
"original": "{ count: number }",
|
|
1055
|
+
"resolved": "{ count: number; }",
|
|
1056
|
+
"references": {}
|
|
1057
|
+
}
|
|
1058
|
+
}];
|
|
1059
|
+
}
|
|
1060
|
+
static get methods() {
|
|
1061
|
+
return {
|
|
1062
|
+
"getConnectionStatus": {
|
|
1063
|
+
"complexType": {
|
|
1064
|
+
"signature": "() => Promise<{ isConnected: boolean; isSessionExpired: boolean; connectionStatus: ConnectionStatus; }>",
|
|
1065
|
+
"parameters": [],
|
|
1066
|
+
"references": {
|
|
1067
|
+
"Promise": {
|
|
1068
|
+
"location": "global",
|
|
1069
|
+
"id": "global::Promise"
|
|
1070
|
+
},
|
|
1071
|
+
"ConnectionStatus": {
|
|
1072
|
+
"location": "import",
|
|
1073
|
+
"path": "@chat-leo/chatleolib",
|
|
1074
|
+
"id": "../chatleolib/dist/index.d.ts::ConnectionStatus",
|
|
1075
|
+
"referenceLocation": "ConnectionStatus"
|
|
1076
|
+
}
|
|
1077
|
+
},
|
|
1078
|
+
"return": "Promise<{ isConnected: boolean; isSessionExpired: boolean; connectionStatus: ConnectionStatus; }>"
|
|
1079
|
+
},
|
|
1080
|
+
"docs": {
|
|
1081
|
+
"text": "",
|
|
1082
|
+
"tags": [{
|
|
1083
|
+
"name": "function",
|
|
1084
|
+
"text": "getConnectionStatus"
|
|
1085
|
+
}, {
|
|
1086
|
+
"name": "description",
|
|
1087
|
+
"text": "Returns the current connection and session status of the chat component.\n\nEmbedding applications should call this method on `window` focus events (or any\nother relevant trigger) to determine whether the user's session is still valid\nand whether the page needs to be reloaded."
|
|
1088
|
+
}, {
|
|
1089
|
+
"name": "returns",
|
|
1090
|
+
"text": "- `isConnected` \u2013 `true` when the underlying WebSocket is currently connected.\n- `isSessionExpired` \u2013 `true` when the token refresh has permanently failed\n (HTTP 401/403 from the refresh endpoint, or too many transient errors).\n When this is `true` the user must reload the page to restore the session."
|
|
1091
|
+
}, {
|
|
1092
|
+
"name": "example",
|
|
1093
|
+
"text": "const chatEl = document.querySelector('chatleo-component');\n\n// Check on every tab-focus whether a reload is needed\nwindow.addEventListener('focus', async () => {\n const { isSessionExpired } = await chatEl.getConnectionStatus();\n if (isSessionExpired) {\n window.location.reload();\n }\n});"
|
|
1094
|
+
}]
|
|
1095
|
+
}
|
|
1096
|
+
},
|
|
1097
|
+
"openRoom": {
|
|
1098
|
+
"complexType": {
|
|
1099
|
+
"signature": "(roomId: string) => Promise<void>",
|
|
1100
|
+
"parameters": [{
|
|
1101
|
+
"name": "roomId",
|
|
1102
|
+
"type": "string",
|
|
1103
|
+
"docs": "- The ID of the room to be opened."
|
|
1104
|
+
}],
|
|
1105
|
+
"references": {
|
|
1106
|
+
"Promise": {
|
|
1107
|
+
"location": "global",
|
|
1108
|
+
"id": "global::Promise"
|
|
1109
|
+
}
|
|
1110
|
+
},
|
|
1111
|
+
"return": "Promise<void>"
|
|
1112
|
+
},
|
|
1113
|
+
"docs": {
|
|
1114
|
+
"text": "",
|
|
1115
|
+
"tags": [{
|
|
1116
|
+
"name": "function",
|
|
1117
|
+
"text": "openRoom"
|
|
1118
|
+
}, {
|
|
1119
|
+
"name": "description",
|
|
1120
|
+
"text": "This method provides a public API to programmatically open a specific chat room in the tray view. It calls the `openChatPanel` method on the `chatleo-tray-component` element."
|
|
1121
|
+
}, {
|
|
1122
|
+
"name": "param",
|
|
1123
|
+
"text": "roomId - The ID of the room to be opened."
|
|
1124
|
+
}]
|
|
1125
|
+
}
|
|
1126
|
+
},
|
|
1127
|
+
"closeRoom": {
|
|
1128
|
+
"complexType": {
|
|
1129
|
+
"signature": "() => Promise<void>",
|
|
1130
|
+
"parameters": [],
|
|
1131
|
+
"references": {
|
|
1132
|
+
"Promise": {
|
|
1133
|
+
"location": "global",
|
|
1134
|
+
"id": "global::Promise"
|
|
1135
|
+
}
|
|
1136
|
+
},
|
|
1137
|
+
"return": "Promise<void>"
|
|
1138
|
+
},
|
|
1139
|
+
"docs": {
|
|
1140
|
+
"text": "",
|
|
1141
|
+
"tags": [{
|
|
1142
|
+
"name": "function",
|
|
1143
|
+
"text": "closeRoom"
|
|
1144
|
+
}, {
|
|
1145
|
+
"name": "description",
|
|
1146
|
+
"text": "Returns to the room list (used for the device back action and deep links\nthat could not be opened)."
|
|
1147
|
+
}]
|
|
1148
|
+
}
|
|
1149
|
+
},
|
|
1150
|
+
"getActiveRoomId": {
|
|
1151
|
+
"complexType": {
|
|
1152
|
+
"signature": "() => Promise<string | null>",
|
|
1153
|
+
"parameters": [],
|
|
1154
|
+
"references": {
|
|
1155
|
+
"Promise": {
|
|
1156
|
+
"location": "global",
|
|
1157
|
+
"id": "global::Promise"
|
|
1158
|
+
}
|
|
1159
|
+
},
|
|
1160
|
+
"return": "Promise<string>"
|
|
1161
|
+
},
|
|
1162
|
+
"docs": {
|
|
1163
|
+
"text": "The currently open room, or `null` on the room list.",
|
|
1164
|
+
"tags": []
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
"getDraft": {
|
|
1168
|
+
"complexType": {
|
|
1169
|
+
"signature": "() => Promise<string>",
|
|
1170
|
+
"parameters": [],
|
|
1171
|
+
"references": {
|
|
1172
|
+
"Promise": {
|
|
1173
|
+
"location": "global",
|
|
1174
|
+
"id": "global::Promise"
|
|
1175
|
+
}
|
|
1176
|
+
},
|
|
1177
|
+
"return": "Promise<string>"
|
|
1178
|
+
},
|
|
1179
|
+
"docs": {
|
|
1180
|
+
"text": "Unsent composer text (used to preserve a draft across an app update).",
|
|
1181
|
+
"tags": []
|
|
1182
|
+
}
|
|
1183
|
+
},
|
|
1184
|
+
"setDraft": {
|
|
1185
|
+
"complexType": {
|
|
1186
|
+
"signature": "(text: string) => Promise<void>",
|
|
1187
|
+
"parameters": [{
|
|
1188
|
+
"name": "text",
|
|
1189
|
+
"type": "string",
|
|
1190
|
+
"docs": ""
|
|
1191
|
+
}],
|
|
1192
|
+
"references": {
|
|
1193
|
+
"Promise": {
|
|
1194
|
+
"location": "global",
|
|
1195
|
+
"id": "global::Promise"
|
|
1196
|
+
}
|
|
1197
|
+
},
|
|
1198
|
+
"return": "Promise<void>"
|
|
1199
|
+
},
|
|
1200
|
+
"docs": {
|
|
1201
|
+
"text": "Restores unsent composer text.",
|
|
1202
|
+
"tags": []
|
|
1203
|
+
}
|
|
1204
|
+
},
|
|
1205
|
+
"addFiles": {
|
|
1206
|
+
"complexType": {
|
|
1207
|
+
"signature": "(files: File[]) => Promise<void>",
|
|
1208
|
+
"parameters": [{
|
|
1209
|
+
"name": "files",
|
|
1210
|
+
"type": "File[]",
|
|
1211
|
+
"docs": ""
|
|
1212
|
+
}],
|
|
1213
|
+
"references": {
|
|
1214
|
+
"Promise": {
|
|
1215
|
+
"location": "global",
|
|
1216
|
+
"id": "global::Promise"
|
|
1217
|
+
},
|
|
1218
|
+
"File": {
|
|
1219
|
+
"location": "global",
|
|
1220
|
+
"id": "global::File"
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1223
|
+
"return": "Promise<void>"
|
|
1224
|
+
},
|
|
1225
|
+
"docs": {
|
|
1226
|
+
"text": "Adds shared files to the composer of the open room.",
|
|
1227
|
+
"tags": []
|
|
1228
|
+
}
|
|
1229
|
+
},
|
|
1230
|
+
"focusComposer": {
|
|
1231
|
+
"complexType": {
|
|
1232
|
+
"signature": "() => Promise<void>",
|
|
1233
|
+
"parameters": [],
|
|
1234
|
+
"references": {
|
|
1235
|
+
"Promise": {
|
|
1236
|
+
"location": "global",
|
|
1237
|
+
"id": "global::Promise"
|
|
1238
|
+
}
|
|
1239
|
+
},
|
|
1240
|
+
"return": "Promise<void>"
|
|
1241
|
+
},
|
|
1242
|
+
"docs": {
|
|
1243
|
+
"text": "Focuses the composer (share text, deep link).",
|
|
1244
|
+
"tags": []
|
|
1245
|
+
}
|
|
1246
|
+
},
|
|
1247
|
+
"openDirectMessageWithUser": {
|
|
1248
|
+
"complexType": {
|
|
1249
|
+
"signature": "(userId: string, use_external_id?: boolean) => Promise<void>",
|
|
1250
|
+
"parameters": [{
|
|
1251
|
+
"name": "userId",
|
|
1252
|
+
"type": "string",
|
|
1253
|
+
"docs": "- The ID of the user to start a direct message with."
|
|
1254
|
+
}, {
|
|
1255
|
+
"name": "use_external_id",
|
|
1256
|
+
"type": "boolean",
|
|
1257
|
+
"docs": ""
|
|
1258
|
+
}],
|
|
1259
|
+
"references": {
|
|
1260
|
+
"Promise": {
|
|
1261
|
+
"location": "global",
|
|
1262
|
+
"id": "global::Promise"
|
|
1263
|
+
}
|
|
1264
|
+
},
|
|
1265
|
+
"return": "Promise<void>"
|
|
1266
|
+
},
|
|
1267
|
+
"docs": {
|
|
1268
|
+
"text": "",
|
|
1269
|
+
"tags": [{
|
|
1270
|
+
"name": "function",
|
|
1271
|
+
"text": "openDirectMessageWithUser"
|
|
1272
|
+
}, {
|
|
1273
|
+
"name": "description",
|
|
1274
|
+
"text": "This method allows programmatically opening a direct message conversation with a specific user. It will either find an existing DM room or create a new one."
|
|
1275
|
+
}, {
|
|
1276
|
+
"name": "param",
|
|
1277
|
+
"text": "userId - The ID of the user to start a direct message with."
|
|
1278
|
+
}, {
|
|
1279
|
+
"name": "param",
|
|
1280
|
+
"text": "use_external_id"
|
|
1281
|
+
}]
|
|
1282
|
+
}
|
|
1283
|
+
},
|
|
1284
|
+
"openNewChatDraft": {
|
|
1285
|
+
"complexType": {
|
|
1286
|
+
"signature": "() => Promise<void>",
|
|
1287
|
+
"parameters": [],
|
|
1288
|
+
"references": {
|
|
1289
|
+
"Promise": {
|
|
1290
|
+
"location": "global",
|
|
1291
|
+
"id": "global::Promise"
|
|
1292
|
+
}
|
|
1293
|
+
},
|
|
1294
|
+
"return": "Promise<void>"
|
|
1295
|
+
},
|
|
1296
|
+
"docs": {
|
|
1297
|
+
"text": "",
|
|
1298
|
+
"tags": [{
|
|
1299
|
+
"name": "function",
|
|
1300
|
+
"text": "openNewChatDraft"
|
|
1301
|
+
}, {
|
|
1302
|
+
"name": "description",
|
|
1303
|
+
"text": "This method programmatically opens the new chat draft view in the tray, allowing the user to start a new conversation."
|
|
1304
|
+
}]
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
static get watchers() {
|
|
1310
|
+
return [{
|
|
1311
|
+
"propName": "chatLeoLib",
|
|
1312
|
+
"methodName": "onChatLeoLibChange"
|
|
1313
|
+
}, {
|
|
1314
|
+
"propName": "chatStore",
|
|
1315
|
+
"methodName": "onChatStoreChange"
|
|
1316
|
+
}, {
|
|
1317
|
+
"propName": "ticket",
|
|
1318
|
+
"methodName": "onTicketChange"
|
|
1319
|
+
}, {
|
|
1320
|
+
"propName": "calls",
|
|
1321
|
+
"methodName": "onCallsChange"
|
|
1322
|
+
}, {
|
|
1323
|
+
"propName": "incomingCall",
|
|
1324
|
+
"methodName": "onIncomingCallChange"
|
|
1325
|
+
}];
|
|
1326
|
+
}
|
|
1327
|
+
static get listeners() {
|
|
1328
|
+
return [{
|
|
1329
|
+
"name": "callError",
|
|
1330
|
+
"method": "onCallError",
|
|
1331
|
+
"target": undefined,
|
|
1332
|
+
"capture": false,
|
|
1333
|
+
"passive": false
|
|
1334
|
+
}, {
|
|
1335
|
+
"name": "callLeft",
|
|
1336
|
+
"method": "onCallLeft",
|
|
1337
|
+
"target": undefined,
|
|
1338
|
+
"capture": false,
|
|
1339
|
+
"passive": false
|
|
1340
|
+
}, {
|
|
1341
|
+
"name": "callRequested",
|
|
1342
|
+
"method": "onCallRequested",
|
|
1343
|
+
"target": undefined,
|
|
1344
|
+
"capture": false,
|
|
1345
|
+
"passive": false
|
|
1346
|
+
}, {
|
|
1347
|
+
"name": "newChatClicked",
|
|
1348
|
+
"method": "onNewChatClicked",
|
|
1349
|
+
"target": undefined,
|
|
1350
|
+
"capture": false,
|
|
1351
|
+
"passive": false
|
|
1352
|
+
}, {
|
|
1353
|
+
"name": "messageChatSent",
|
|
1354
|
+
"method": "onChatMessage",
|
|
1355
|
+
"target": undefined,
|
|
1356
|
+
"capture": false,
|
|
1357
|
+
"passive": false
|
|
1358
|
+
}, {
|
|
1359
|
+
"name": "userSelected",
|
|
1360
|
+
"method": "onUserSelectedForChat",
|
|
1361
|
+
"target": undefined,
|
|
1362
|
+
"capture": false,
|
|
1363
|
+
"passive": false
|
|
1364
|
+
}];
|
|
1365
|
+
}
|
|
1366
|
+
}
|