releasebird-javascript-sdk 1.0.86 → 1.0.88
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/build/index.js +1 -1
- package/package.json +3 -2
- package/published/1.0.87/index.js +1 -0
- package/published/1.0.88/index.js +1 -0
- package/published/latest/index.js +1 -1
- package/src/RbirdFormManager.js +23 -4
- package/src/RbirdSurveyManager.js +720 -0
- package/src/RbirdWebsiteWidget.js +42 -1
- package/src/index.js +22 -0
|
@@ -54,6 +54,9 @@ export default class RbirdWebsiteWidget {
|
|
|
54
54
|
initialX = 0;
|
|
55
55
|
initialY = 0;
|
|
56
56
|
|
|
57
|
+
// Notification sound
|
|
58
|
+
audioContext = null;
|
|
59
|
+
|
|
57
60
|
static getInstance() {
|
|
58
61
|
if (!this.instance) {
|
|
59
62
|
this.instance = new RbirdWebsiteWidget();
|
|
@@ -369,8 +372,9 @@ export default class RbirdWebsiteWidget {
|
|
|
369
372
|
|
|
370
373
|
if (e.data === 'newMessageArrived') {
|
|
371
374
|
this.countNotifications();
|
|
372
|
-
//
|
|
375
|
+
// Play notification sound and refresh message bubbles when new message arrives
|
|
373
376
|
if (!RbirdUtils.hasClass(this.widgetContent, 'cta__modal--visible')) {
|
|
377
|
+
this.playNotificationSound();
|
|
374
378
|
this.fetchUnreadMessages();
|
|
375
379
|
if (this.iframe) {
|
|
376
380
|
this.iframe.contentWindow?.postMessage({
|
|
@@ -588,6 +592,43 @@ export default class RbirdWebsiteWidget {
|
|
|
588
592
|
this.messageBubblesContainer.style.right = 'unset';
|
|
589
593
|
}
|
|
590
594
|
|
|
595
|
+
/**
|
|
596
|
+
* Play a notification sound when new messages arrive
|
|
597
|
+
*/
|
|
598
|
+
playNotificationSound() {
|
|
599
|
+
try {
|
|
600
|
+
// Create AudioContext lazily (required for browser autoplay policies)
|
|
601
|
+
if (!this.audioContext) {
|
|
602
|
+
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
const ctx = this.audioContext;
|
|
606
|
+
const now = ctx.currentTime;
|
|
607
|
+
|
|
608
|
+
// Create oscillator for the "plopp" sound
|
|
609
|
+
const oscillator = ctx.createOscillator();
|
|
610
|
+
const gainNode = ctx.createGain();
|
|
611
|
+
|
|
612
|
+
oscillator.connect(gainNode);
|
|
613
|
+
gainNode.connect(ctx.destination);
|
|
614
|
+
|
|
615
|
+
// Plopp sound: quick frequency drop with fast decay
|
|
616
|
+
oscillator.type = 'sine';
|
|
617
|
+
oscillator.frequency.setValueAtTime(800, now);
|
|
618
|
+
oscillator.frequency.exponentialRampToValueAtTime(300, now + 0.1);
|
|
619
|
+
|
|
620
|
+
// Quick attack and decay for the "plopp" effect
|
|
621
|
+
gainNode.gain.setValueAtTime(0, now);
|
|
622
|
+
gainNode.gain.linearRampToValueAtTime(0.3, now + 0.02);
|
|
623
|
+
gainNode.gain.exponentialRampToValueAtTime(0.01, now + 0.15);
|
|
624
|
+
|
|
625
|
+
oscillator.start(now);
|
|
626
|
+
oscillator.stop(now + 0.15);
|
|
627
|
+
} catch (e) {
|
|
628
|
+
// Silently fail if audio is not supported
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
591
632
|
/**
|
|
592
633
|
* Create a single message bubble element
|
|
593
634
|
* @param {Object} msg - Message object with chatId, text, senderName, senderAvatar, timestamp
|
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import RbirdWebsiteWidget from "./RbirdWebsiteWidget";
|
|
|
4
4
|
import { ReleasebirdConsoleLogger } from "./ReleasebirdConsoleLogger";
|
|
5
5
|
import { RbirdBannerManager } from "./RbirdBannerManager";
|
|
6
6
|
import { RbirdFormManager } from "./RbirdFormManager";
|
|
7
|
+
import { RbirdSurveyManager } from "./RbirdSurveyManager";
|
|
7
8
|
|
|
8
9
|
class Rbird {
|
|
9
10
|
|
|
@@ -93,6 +94,10 @@ class Rbird {
|
|
|
93
94
|
// Initialize form manager
|
|
94
95
|
const formManager = RbirdFormManager.getInstance();
|
|
95
96
|
formManager.init(apiKey);
|
|
97
|
+
|
|
98
|
+
// Initialize survey manager
|
|
99
|
+
const surveyManager = RbirdSurveyManager.getInstance();
|
|
100
|
+
surveyManager.init(apiKey);
|
|
96
101
|
resolve();
|
|
97
102
|
});
|
|
98
103
|
});
|
|
@@ -161,6 +166,23 @@ class Rbird {
|
|
|
161
166
|
}
|
|
162
167
|
}
|
|
163
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Show a survey by its ID
|
|
171
|
+
* @param {string} surveyId - The ID of the survey to show
|
|
172
|
+
* @param {Object} options - Optional configuration
|
|
173
|
+
* @param {string} options.target - CSS selector for inline rendering (optional, shows as modal if not provided)
|
|
174
|
+
* @param {Function} options.onSubmit - Callback when survey is submitted
|
|
175
|
+
* @param {Function} options.onClose - Callback when survey is closed
|
|
176
|
+
*/
|
|
177
|
+
static showSurvey(surveyId, options = {}) {
|
|
178
|
+
if (typeof window === 'undefined') return;
|
|
179
|
+
try {
|
|
180
|
+
RbirdSurveyManager.getInstance().showSurvey(surveyId, options);
|
|
181
|
+
} catch (e) {
|
|
182
|
+
console.error(e);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
164
186
|
}
|
|
165
187
|
|
|
166
188
|
export const runFunctionWhenDomIsReady = (callback) => {
|