Skip to content

Commit 4747eca

Browse files
authored
Use latest Call Widget in the docs (#469)
* release 3.14 with error log removals * use v3.14 * use 3.15
1 parent aa31f39 commit 4747eca

File tree

4 files changed

+72
-22
lines changed

4 files changed

+72
-22
lines changed

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
"@double-great/alt-text": "^3.1.0",
4646
"@material/web": "^2.3.0",
4747
"@mdx-js/react": "^3.0.1",
48-
"@niravcodes/call-widget": "^3.0.0",
4948
"@popperjs/core": "^2.11.8",
49+
"@signalwire/call-widget": "^3.15.0",
5050
"@signalwire/docusaurus-plugin-llms-txt": "1.2.1",
5151
"canvas": "^3.1.2",
5252
"clsx": "^2.1.1",

website/src/components/Sigmond/C2CWidgetInternal.tsx

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ export default function C2CWidgetInternal({
1515
token: string;
1616
}) {
1717
const rootRef = useRef<HTMLDivElement>(null);
18+
const showContactFormRef = useRef<any>(null);
1819

1920
useEffect(() => {
20-
import("@niravcodes/call-widget");
21+
const loadWidget = async () => {
22+
const module = await import("@signalwire/call-widget");
23+
showContactFormRef.current = module.showContactForm;
24+
};
25+
loadWidget();
2126
}, []);
2227

2328
// react doesn't like other scripts controlling the DOM,
@@ -27,19 +32,50 @@ export default function C2CWidgetInternal({
2732
useEffect(() => {
2833
if (rootRef.current) {
2934
rootRef.current.innerHTML = "";
30-
const widget = document.createElement("c2c-widget");
31-
32-
widget.setAttribute("buttonId", buttonId);
33-
widget.setAttribute(
34-
"callDetails",
35-
JSON.stringify({
36-
destination,
37-
supportsVideo,
38-
supportsAudio,
39-
}),
40-
);
35+
const widget = document.createElement("call-widget");
36+
37+
widget.setAttribute("button-id", buttonId);
4138
widget.setAttribute("token", token);
39+
widget.setAttribute("support-video", supportsVideo.toString());
40+
widget.setAttribute("support-audio", supportsAudio.toString());
41+
widget.setAttribute("destination", destination);
42+
43+
const handleBeforeDial = (event: any) => {
44+
const approve = event.detail.approve;
45+
const reject = event.detail.reject;
46+
47+
event.detail.hasListeners = true;
48+
49+
if (!showContactFormRef.current) {
50+
console.error("showContactForm not loaded yet");
51+
reject();
52+
return;
53+
}
54+
55+
showContactFormRef.current(
56+
{
57+
onSubmit: (data: any) => {
58+
(widget as any).newCallVariable({
59+
email: data.email,
60+
name: data.name,
61+
phone: data.number,
62+
});
63+
approve();
64+
},
65+
onCancel: () => {
66+
reject();
67+
},
68+
},
69+
widget,
70+
);
71+
};
72+
73+
widget.addEventListener("beforeDial", handleBeforeDial);
4274
rootRef.current.appendChild(widget);
75+
76+
return () => {
77+
widget.removeEventListener("beforeDial", handleBeforeDial);
78+
};
4379
}
4480
return () => {
4581
if (rootRef.current) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module "@signalwire/call-widget";

yarn.lock

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,14 +2591,6 @@
25912591
"@emnapi/runtime" "^1.4.5"
25922592
"@tybys/wasm-util" "^0.10.0"
25932593

2594-
"@niravcodes/call-widget@^3.0.0":
2595-
version "3.0.0"
2596-
resolved "https://registry.npmjs.org/@niravcodes/call-widget/-/call-widget-3.0.0.tgz"
2597-
integrity sha512-byP0+XLwmMBYSiQ+APiO6//Y1OlthJQiR6ZbSQ3yqMHE+s/BZxdk0J9a2svCm7rCtDmKTXYw0xl5frmoyzzkUw==
2598-
dependencies:
2599-
"@signalwire/js" dev
2600-
nanomorph "^5.4.3"
2601-
26022594
"@nodelib/[email protected]":
26032595
version "2.1.5"
26042596
resolved "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz"
@@ -2929,6 +2921,15 @@
29292921
resolved "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz"
29302922
integrity sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==
29312923

2924+
"@signalwire/call-widget@^3.15.0":
2925+
version "3.15.0"
2926+
resolved "https://registry.yarnpkg.com/@signalwire/call-widget/-/call-widget-3.15.0.tgz#cb93d5c2d38e34ae9c9304e9ab85ef904ac8dd2a"
2927+
integrity sha512-pQRNtEsYHPpSf6KZFpPjR1vMQNzJKQiaUHJvWJURcc9U6esuEMoR5XzYLFbMNsohKA4YZI7E05hhVMk3hfsKFw==
2928+
dependencies:
2929+
"@signalwire/js" "3.29.1"
2930+
nanomorph "^5.4.3"
2931+
showdown "^2.1.0"
2932+
29322933
"@signalwire/[email protected]":
29332934
version "4.3.1"
29342935
resolved "https://registry.npmjs.org/@signalwire/core/-/core-4.3.1.tgz"
@@ -2958,7 +2959,7 @@
29582959
unified "^11"
29592960
unist-util-visit "^5"
29602961

2961-
"@signalwire/[email protected]", "@signalwire/js@dev":
2962+
"@signalwire/[email protected]":
29622963
version "3.29.1"
29632964
resolved "https://registry.yarnpkg.com/@signalwire/js/-/js-3.29.1.tgz#d39def63d80942aa35abcd1504a13e9476255298"
29642965
integrity sha512-YIu1NTul4zaFk0yNXve3k41GaAlYChopbjSTmB4skyCUDNtRAdasc+xOqEcSWzDFpkKQTeIYXPC4mWA8kliwcg==
@@ -4982,6 +4983,11 @@ commander@^8.3.0:
49824983
resolved "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz"
49834984
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==
49844985

4986+
commander@^9.0.0:
4987+
version "9.5.0"
4988+
resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30"
4989+
integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==
4990+
49854991
common-path-prefix@^3.0.0:
49864992
version "3.0.0"
49874993
resolved "https://registry.npmjs.org/common-path-prefix/-/common-path-prefix-3.0.0.tgz"
@@ -11459,6 +11465,13 @@ should@^13.2.1:
1145911465
should-type-adaptors "^1.0.1"
1146011466
should-util "^1.0.0"
1146111467

11468+
showdown@^2.1.0:
11469+
version "2.1.0"
11470+
resolved "https://registry.yarnpkg.com/showdown/-/showdown-2.1.0.tgz#1251f5ed8f773f0c0c7bfc8e6fd23581f9e545c5"
11471+
integrity sha512-/6NVYu4U819R2pUIk79n67SYgJHWCce0a5xTP979WbNp0FL9MN1I1QK662IDU1b6JzKTvmhgI7T7JYIxBi3kMQ==
11472+
dependencies:
11473+
commander "^9.0.0"
11474+
1146211475
shx@^0.3.4:
1146311476
version "0.3.4"
1146411477
resolved "https://registry.npmjs.org/shx/-/shx-0.3.4.tgz"

0 commit comments

Comments
 (0)