@rehers/rehers-roleplay-sdk 2.2.0 → 2.3.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/README.md CHANGED
@@ -47,7 +47,10 @@ Or load via CDN:
47
47
  onError: function(data) { console.error('Error:', data.code, data.message); },
48
48
  });
49
49
 
50
- // 2b. Or mount into a container (full-page embed)
50
+ // 2b. Or mount the full app into a container (full-page embed)
51
+ SeamlessRoleplay.mount(document.getElementById('roleplay-container'));
52
+
53
+ // 2c. Or mount a call for a specific contact into a container
51
54
  SeamlessRoleplay.mount(document.getElementById('roleplay-container'), {
52
55
  name: 'Jane Smith',
53
56
  domain: 'acme.com',
@@ -110,9 +113,12 @@ Opens the roleplay in a modal dialog overlay.
110
113
  | `onClose` | `function` | No | Called when dialog closes |
111
114
  | `onError` | `function` | No | `({ code, message })` |
112
115
 
113
- ### `SeamlessRoleplay.mount(container, data)`
116
+ ### `SeamlessRoleplay.mount(container, data?)`
117
+
118
+ Mounts into a DOM element. Two modes:
114
119
 
115
- Mounts the roleplay into a DOM element (full-page embed). Same `data` options as `open()`.
120
+ - **`mount(container)`** embeds the full Roleplay app (dashboard, scenarios, call logs)
121
+ - **`mount(container, data)`** — embeds a roleplay call for a specific contact (same `data` options as `open()`)
116
122
 
117
123
  ### `SeamlessRoleplay.addToScenario(options)`
118
124
 
package/index.d.ts CHANGED
@@ -78,8 +78,8 @@ export interface SeamlessRoleplaySDK {
78
78
  init(options: SeamlessRoleplayInitOptions): void;
79
79
  /** Open the roleplay modal for a contact (dialog mode). */
80
80
  open(data: SeamlessRoleplayOpenData): void;
81
- /** Mount the roleplay into a container element (full-page embed). */
82
- mount(container: HTMLElement, data: SeamlessRoleplayOpenData): void;
81
+ /** Mount the full Roleplay app into a container (no data), or a call embed for a specific contact (with data). */
82
+ mount(container: HTMLElement, data?: SeamlessRoleplayOpenData): void;
83
83
  /** Open the add-to-scenario dialog for bulk contact import. */
84
84
  addToScenario(options: AddToScenarioOptions): void;
85
85
  /** Close the roleplay dialog or unmount. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rehers/rehers-roleplay-sdk",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Seamless Roleplay SDK — embed roleplay call sessions via a modal + iframe",
5
5
  "main": "roleplay-sdk.js",
6
6
  "types": "index.d.ts",
package/roleplay-sdk.js CHANGED
@@ -219,19 +219,20 @@
219
219
  };
220
220
  if (paymentLink) msg.paymentLink = paymentLink;
221
221
  sendToIframe(msg);
222
- } else if (token && pendingContactData) {
223
- sendToIframe({
222
+ } else if (token) {
223
+ var msg = {
224
224
  type: "seamless-session-init",
225
225
  sessionToken: token,
226
- contact: {
226
+ contact: pendingContactData ? {
227
227
  name: pendingContactData.name,
228
228
  domain: pendingContactData.domain,
229
229
  company: pendingContactData.company,
230
230
  title: pendingContactData.title,
231
231
  companyDescription: pendingContactData.companyDescription || undefined,
232
232
  liUrl: pendingContactData.liUrl || undefined,
233
- },
234
- });
233
+ } : null,
234
+ };
235
+ sendToIframe(msg);
235
236
  } else if (paymentLink) {
236
237
  sendToIframe({
237
238
  type: "seamless-session-init",
@@ -336,9 +337,9 @@
336
337
 
337
338
  // ── Create iframe ───────────────────────────────────────────────────
338
339
 
339
- function createIframe() {
340
+ function createIframe(path) {
340
341
  var iframeEl = document.createElement("iframe");
341
- iframeEl.src = getOrigin() + "/embed/roleplay-call";
342
+ iframeEl.src = getOrigin() + (path || "/embed/roleplay-call");
342
343
  iframeEl.allow = "camera; microphone; display-capture; autoplay";
343
344
  iframeEl.style.width = "100%";
344
345
  iframeEl.style.height = "100%";
@@ -502,7 +503,11 @@
502
503
  },
503
504
 
504
505
  /**
505
- * Mount the roleplay into a container element (full-page embed).
506
+ * Mount the roleplay into a container element.
507
+ *
508
+ * Two modes:
509
+ * mount(container) — full app embed (dashboard, scenarios, call logs, etc.)
510
+ * mount(container, contactData) — roleplay call embed for a specific contact
506
511
  */
507
512
  mount: function (container, data) {
508
513
  try {
@@ -514,19 +519,22 @@
514
519
  logError("mount", "requires a DOM element as first argument");
515
520
  return;
516
521
  }
517
- if (!data || !data.name || !data.domain || !data.company || !data.title) {
518
- logError("mount", "requires { name, domain, company, title }");
522
+
523
+ // If contact data is provided, validate required fields
524
+ var hasContactData = data && data.name && data.domain && data.company && data.title;
525
+ if (data && !hasContactData && (data.name || data.domain || data.company || data.title)) {
526
+ logError("mount", "contact data requires { name, domain, company, title }");
519
527
  return;
520
528
  }
521
529
 
522
530
  // If already open, tear down first (also cancels any pending close timer)
523
531
  if (overlay || (iframe && mode)) teardown();
524
532
 
525
- pendingContactData = data;
526
- callbacks.onCallStarted = data.onCallStarted || null;
527
- callbacks.onCallEnded = data.onCallEnded || null;
528
- callbacks.onClose = data.onClose || null;
529
- callbacks.onError = data.onError || null;
533
+ pendingContactData = hasContactData ? data : null;
534
+ callbacks.onCallStarted = (data && data.onCallStarted) || null;
535
+ callbacks.onCallEnded = (data && data.onCallEnded) || null;
536
+ callbacks.onClose = (data && data.onClose) || null;
537
+ callbacks.onError = (data && data.onError) || null;
530
538
  mode = "mount";
531
539
  mountContainer = container;
532
540
 
@@ -534,7 +542,8 @@
534
542
  listener = handleMessage;
535
543
  window.addEventListener("message", listener);
536
544
 
537
- var iframeEl = createIframe();
545
+ // No contact data → full app embed at root; with contact → /embed/roleplay-call
546
+ var iframeEl = createIframe(hasContactData ? "/embed/roleplay-call" : "/");
538
547
  iframe = iframeEl;
539
548
  container.appendChild(iframeEl);
540
549
  } catch (e) {