@nethesis/chat-island 0.1.13 → 0.1.14

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/README.md CHANGED
@@ -110,6 +110,8 @@ A complete example page is in `widget-example/`; the live demo is `index.html`.
110
110
  | `chat-island-close` | in | |
111
111
  | `chat-island-new` | in | open the new chat panel |
112
112
  | `chat-island-delete` | in | `{ username }` purge a conversation, leave or destroy a group |
113
+ | `chat-island-send` | in | `{ username, text }` send a text to an operator or group |
114
+ | `chat-island-group-create` | in | `{ name, members }` create a group with these usernames and open it |
113
115
  | `chat-island-contacts` | in | `{ contacts }` names, avatars, presence, number |
114
116
  | `chat-island-conversations-request` | in | ask for the list |
115
117
  | `chat-island-theme-change` | in | `{ theme }` light, dark or system, remembered |
@@ -122,6 +124,24 @@ A complete example page is in `widget-example/`; the live demo is `index.html`.
122
124
  | `chat-island-call` | out | `{ username, number }` |
123
125
  | `chat-island-notify` | out | `{ peer, name, body, kind, author, text, attachment, avatar, ts }` message not in view |
124
126
 
127
+ ## Integrate in an existing app
128
+
129
+ An app with its own users (WebTop, an intranet) embeds the widget and builds its view on the events:
130
+
131
+ 1. log the user in on the CTI (`/api/login`, or a QR code token with two-factor authentication) and pass `<cti_host>:<username>:<token>` as `data-config`;
132
+ 2. on `chat-island-status` `unauthorized`, log in again and set the new token in `data-config`: the island reconnects in place;
133
+ 3. keep its conversation list with `chat-island-conversations-request` / `chat-island-conversations`, badges with `chat-island-unread`;
134
+ 4. drive the island with `chat-island-open`, `chat-island-close`, `chat-island-send`, `chat-island-group-create`, `chat-island-delete`; `newChatButton: false` hides the island's own entry point;
135
+ 5. serve `chat-island-sw.js` from its own origin for notifications with the tab closed.
136
+
137
+ ```js
138
+ const send = (name, detail) => window.dispatchEvent(new CustomEvent(name, { detail }))
139
+ window.addEventListener('chat-island-conversations', (e) => render(e.detail.conversations))
140
+ send('chat-island-conversations-request')
141
+ send('chat-island-group-create', { name: 'Support', members: ['mario', 'anna'] })
142
+ send('chat-island-send', { username: 'mario', text: 'Ciao!' })
143
+ ```
144
+
125
145
  ## Live demo
126
146
 
127
147
  `index.html` is published on [GitHub Pages](https://nethesis.github.io/chat-island/) by `.github/workflows/pages.yml` at every push to `main`, with the widget built from the same commit. It logs in with NethVoice credentials (or a token), mounts the widget and shows its events.
package/dist/index.js CHANGED
@@ -5063,9 +5063,9 @@ function Jr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
5063
5063
  scope: "contacts",
5064
5064
  message: e.message
5065
5065
  }));
5066
- let d = X("chat-island-open", ({ username: t }) => t && e.openChat(t)), f = X("chat-island-close", () => e.closeChat()), p = X("chat-island-new", () => e.setPicker(!0)), m = X("chat-island-delete", ({ username: e }) => e && N.remove(e)), h = X("chat-island-contacts", ({ contacts: t }) => t && e.setContacts(t)), _ = X("chat-island-conversations-request", () => Y("chat-island-conversations", { conversations: Wr() }));
5066
+ let d = X("chat-island-open", ({ username: t }) => t && e.openChat(t)), f = X("chat-island-close", () => e.closeChat()), p = X("chat-island-new", () => e.setPicker(!0)), m = X("chat-island-delete", ({ username: e }) => e && N.remove(e)), h = X("chat-island-send", ({ username: e, text: t }) => e && t && N.send(e, t).catch(() => {})), _ = X("chat-island-group-create", ({ name: e, members: t }) => e && t?.length && N.createGroup(e, t)), v = X("chat-island-contacts", ({ contacts: t }) => t && e.setContacts(t)), x = X("chat-island-conversations-request", () => Y("chat-island-conversations", { conversations: Wr() }));
5067
5067
  return () => {
5068
- window.removeEventListener("pagehide", s), window.clearInterval(u), _(), p(), m(), d(), f(), h(), O.current && t.disablePush(O.current.service, O.current.node).catch(() => {}), O.current = null, t.stop(), C.current = null, D.current = !1;
5068
+ window.removeEventListener("pagehide", s), window.clearInterval(u), x(), p(), m(), h(), _(), d(), f(), v(), O.current && t.disablePush(O.current.service, O.current.node).catch(() => {}), O.current = null, t.stop(), C.current = null, D.current = !1;
5069
5069
  };
5070
5070
  }, [
5071
5071
  g,