Skip to content

Commit

Permalink
fix(sdk): use dynamic rootUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Oct 17, 2023
1 parent 789a9ac commit 2374f44
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sdk/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { iframeFeatureAllowList } from '../src/config/iframeFeatureAllowList'

export const defaultRootDomain = 'https://chitchatter.im/'
export const defaultRoot = `${window.location.origin}${window.location.pathname}`

// NOTE: This is a subset of standard iframe attributes:
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attributes
Expand All @@ -13,7 +13,7 @@ const allowedAttributes = [
]

enum ChatEmbedAttributes {
ROOT_DOMAIN = 'domain',
ROOT_URL = 'root-url',
ROOM_NAME = 'room',
}

Expand All @@ -22,12 +22,12 @@ class ChatEmbed extends HTMLElement {
const shadow = this.attachShadow({ mode: 'open' })
const iframe = document.createElement('iframe')

const rootDomain =
this.getAttribute(ChatEmbedAttributes.ROOT_DOMAIN) ?? defaultRootDomain
const rootUrl =
this.getAttribute(ChatEmbedAttributes.ROOT_URL) ?? defaultRoot
const roomName = encodeURIComponent(
this.getAttribute(ChatEmbedAttributes.ROOM_NAME) ?? window.location.href
)
const iframeSrc = `${rootDomain}public/${roomName}/?embed=1`
const iframeSrc = `${rootUrl}public/${roomName}/?embed=1`

iframe.setAttribute('src', iframeSrc)
iframe.style.border = 'none'
Expand Down

0 comments on commit 2374f44

Please sign in to comment.