Skip to content

Commit

Permalink
fix: init issue in web
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Nov 22, 2021
1 parent 25fc602 commit a62040c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capacitor-crisp",
"version": "1.0.7",
"version": "1.0.9",
"description": "Crisp native SDK for capacitor",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down
22 changes: 13 additions & 9 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ export class CapacitorCrispWeb
name: 'CapacitorCrisp',
platforms: ['web'],
});
window.$crisp = [
['safe', true],
window.$crisp = []
const s = document.createElement('script')
s.src = 'https://client.crisp.chat/l.js'
s.async = true
document.getElementsByTagName('head')[0].appendChild(s)
this.setAutoHide()
}

private setAutoHide() {
window.$crisp.push(['safe', true],
['do', 'chat:hide'],
[
'on',
Expand All @@ -35,12 +43,7 @@ export class CapacitorCrispWeb
() => {
window.$crisp.push(['do', 'chat:show'])
},
],
]
const s = document.createElement('script')
s.src = 'https://client.crisp.chat/l.js'
s.async = true
document.getElementsByTagName('head')[0].appendChild(s)
])
}

async configure(data: { websiteID: string }): Promise<void> {
Expand All @@ -54,7 +57,7 @@ export class CapacitorCrispWeb

async setTokenID(data: { tokenID: string }): Promise<void> {
window.CRISP_TOKEN_ID = data.tokenID
window.$crisp.push(["do", "session:reset"])
this.reset()
}

async setUser(data: { nickname?: string, phone?: string, email?: string, avatar?: string }): Promise<void> {
Expand Down Expand Up @@ -116,5 +119,6 @@ export class CapacitorCrispWeb

async reset(): Promise<void> {
window.$crisp.push(["do", "session:reset"]);
this.setAutoHide()
}
}

0 comments on commit a62040c

Please sign in to comment.