Skip to content

Commit 0d82acb

Browse files
authored
Send SDK message to HubSpot if usesCallingWindow=false (#266)
* Send SDK message to HubSpot if usesCallingWindow=false
1 parent 6c9a5a3 commit 0d82acb

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

demos/demo-minimal-js/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ const cti = new CallingExtensions({
145145
if (hostUrl && usesCallingWindow === false) {
146146
state.usesCallingWindow = false;
147147

148-
const hostUrl = "https://app.hubspotqa.com/";
149148
const url = `${hostUrl}/calling-integration-popup-ui/${portalId}?usesCallingWindow=false`;
150149

151150
document

demos/demo-react-ts/src/components/App.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ function App() {
163163
cti.broadcastChannel.onmessage = ({
164164
data,
165165
}: MessageEvent<{ type: string; payload?: any }>) => {
166-
// Send SDK message to HubSpot in the calling window
167-
if (cti.isFromWindow) {
166+
// Send SDK message to HubSpot in the calling window or if usesCallingWindow is false
167+
if (
168+
cti.usesCallingWindow ? cti.isFromWindow : cti.isFromRemoteWithoutWindow
169+
) {
168170
// TODO: Refactor to use eventHandler to invoke the appropriate function
169171
// const eventHandler = broadcastEventHandlers[data.type];
170172
// cti.contract[eventHandler](data.payload);

demos/demo-react-ts/src/components/screens/LoginScreen.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ function LoginScreen({ cti, handleNextScreen }: ScreenProps) {
2828
target: { value },
2929
}: ChangeEvent<HTMLInputElement>) => setPassword(value);
3030

31+
const handleOpenWindow = () => {
32+
const url = `${cti.hostUrl}/calling-integration-popup-ui/${cti.portalId}?usesCallingWindow=false`;
33+
window.open(url, "_blank");
34+
};
35+
3136
return (
3237
<Wrapper style={{ color: PANTERA }}>
3338
<form>
@@ -67,6 +72,18 @@ function LoginScreen({ cti, handleNextScreen }: ScreenProps) {
6772
Sign in with SSO
6873
</LinkButton>
6974
</Row>
75+
<br />
76+
{!cti.usesCallingWindow && (
77+
<Row>
78+
<LinkButton
79+
use="transparent-on-primary"
80+
onClick={handleOpenWindow}
81+
type="button"
82+
>
83+
Open calling window
84+
</LinkButton>
85+
</Row>
86+
)}
7087
</form>
7188
</Wrapper>
7289
);

demos/demo-react-ts/src/hooks/useCti.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class CallingExtensionsWrapper implements CallingExtensionsContract {
5555

5656
private _usesCallingWindow = true;
5757

58+
portalId = 0;
59+
60+
hostUrl = "";
61+
5862
broadcastChannel: BroadcastChannel = new BroadcastChannel(
5963
"calling-extensions-demo-react-ts"
6064
);
@@ -100,14 +104,18 @@ class CallingExtensionsWrapper implements CallingExtensionsContract {
100104
this._usesCallingWindow = usesCallingWindow;
101105
}
102106

107+
get isFromRemoteWithoutWindow() {
108+
return !this._usesCallingWindow && this._iframeLocation === "remote";
109+
}
110+
103111
/** Do not send messages to HubSpot in the remote */
104112
get isFromRemote() {
105113
return this._usesCallingWindow && this._iframeLocation === "remote";
106114
}
107115

108116
/** Send messages to HubSpot in the calling window */
109117
get isFromWindow() {
110-
return this._usesCallingWindow && this._iframeLocation === "window";
118+
return this._iframeLocation === "window";
111119
}
112120

113121
/** Broadcast message from remote or window */
@@ -135,6 +143,14 @@ class CallingExtensionsWrapper implements CallingExtensionsContract {
135143
this._usesCallingWindow = userData.usesCallingWindow;
136144
}
137145

146+
if (userData.portalId) {
147+
this.portalId = userData.portalId;
148+
}
149+
150+
if (userData.hostUrl) {
151+
this.hostUrl = userData.hostUrl;
152+
}
153+
138154
return this._cti.initialized(userData);
139155
}
140156

@@ -328,14 +344,7 @@ export const useCti = (setDialNumber: (phoneNumber: string) => void) => {
328344
return new CallingExtensionsWrapper({
329345
debugMode: true,
330346
eventHandlers: {
331-
onReady: (data: {
332-
engagementId?: number;
333-
portalId?: number;
334-
userId?: number;
335-
ownerId?: number;
336-
iframeLocation?: string;
337-
usesCallingWindow?: boolean;
338-
}) => {
347+
onReady: (data: OnInitialized) => {
339348
const engagementId = (data && data.engagementId) || 0;
340349

341350
cti.initialized({
@@ -348,6 +357,8 @@ export const useCti = (setDialNumber: (phoneNumber: string) => void) => {
348357
},
349358
iframeLocation: data.iframeLocation,
350359
usesCallingWindow: data.usesCallingWindow,
360+
portalId: data.portalId,
361+
hostUrl: data.hostUrl,
351362
} as OnInitialized);
352363
},
353364
onDialNumber: (data: any, _rawEvent: any) => {

0 commit comments

Comments
 (0)