Skip to content

Commit

Permalink
refactor(sdk): improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Oct 28, 2023
1 parent 147e267 commit 9029bd7
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions sdk/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { isPostMessageEvent, PostMessageEventName } from '../src/models/sdk'
import {
isPostMessageEvent,
PostMessageEvent,
PostMessageEventName,
} from '../src/models/sdk'
import { QueryParamKeys } from '../src/models/shell'
import { isColorMode, UserSettings } from '../src/models/settings'
import { iframeFeatureAllowList } from '../src/config/iframeFeatureAllowList'
Expand Down Expand Up @@ -45,8 +49,9 @@ class ChatEmbed extends HTMLElement {
}

if (this.hasAttribute(ChatEmbedAttributes.USER_NAME)) {
chatConfig.customUsername =
this.getAttribute(ChatEmbedAttributes.USER_NAME) ?? ''
chatConfig.customUsername = this.getAttribute(
ChatEmbedAttributes.USER_NAME
)!
}

chatConfig.playSoundOnNewMessage = Boolean(
Expand All @@ -70,13 +75,12 @@ class ChatEmbed extends HTMLElement {
const { iframe, rootUrl } = this
const { origin: rootUrlOrigin } = new URL(rootUrl)

iframe.contentWindow?.postMessage(
{
name: PostMessageEventName.CONFIG,
payload: this.chatConfig,
},
rootUrlOrigin
)
const postMessageEventData: PostMessageEvent['data'] = {
name: PostMessageEventName.CONFIG,
payload: this.chatConfig,
}

iframe.contentWindow?.postMessage(postMessageEventData, rootUrlOrigin)
}

private handleConfigRequestedMessage = (event: MessageEvent) => {
Expand Down

0 comments on commit 9029bd7

Please sign in to comment.