@meetelise/chat
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -6,6 +6,6 @@ /** | ||
*/ | ||
export declare function getChatID(buildingId: number): string; | ||
export declare function getChatID(org: string, building: string): string; | ||
/** | ||
* Create a new chat ID and discard any old one. | ||
*/ | ||
export declare function createChatID(buildingId: number): string; | ||
export declare function createChatID(org: string, building: string): string; |
import { v4 as uuid } from "uuid"; | ||
const keyPrefix = "com.meetelise.chatID"; | ||
function generateFullKey(buildingId) { | ||
return `${keyPrefix}-${buildingId}`; | ||
function generateFullKey(org, building) { | ||
return `${keyPrefix}-${org}-${building}`; | ||
} | ||
@@ -11,4 +11,4 @@ /** | ||
*/ | ||
export function getChatID(buildingId) { | ||
const key = generateFullKey(buildingId); | ||
export function getChatID(org, building) { | ||
const key = generateFullKey(org, building); | ||
const existingID = localStorage.getItem(key); | ||
@@ -18,3 +18,3 @@ if (existingID) | ||
else | ||
return createChatID(buildingId); | ||
return createChatID(org, building); | ||
} | ||
@@ -24,5 +24,5 @@ /** | ||
*/ | ||
export function createChatID(buildingId) { | ||
export function createChatID(org, building) { | ||
const id = uuid(); | ||
const key = generateFullKey(buildingId); | ||
const key = generateFullKey(org, building); | ||
localStorage.setItem(key, id); | ||
@@ -29,0 +29,0 @@ return id; |
@@ -0,1 +1,2 @@ | ||
import Talk from "talkjs"; | ||
import { Theme } from "./resolveTheme"; | ||
@@ -15,2 +16,3 @@ /** | ||
export default class MEChat { | ||
static session: Promise<Talk.Session>; | ||
/** | ||
@@ -48,2 +50,4 @@ * Start an instance of MeetElise chat and add to the web page. | ||
hide(): void; | ||
private buildingSlug; | ||
private orgSlug; | ||
private popup; | ||
@@ -53,2 +57,3 @@ private launcher; | ||
private theme; | ||
private chatId; | ||
private constructor(); | ||
@@ -55,0 +60,0 @@ } |
@@ -0,5 +1,8 @@ | ||
import Talk from "talkjs"; | ||
import fetchBuildingInfo from "./fetchBuildingInfo"; | ||
import { initialize, restartConversation, updateTheme, createTalkJSPopup, } from "./talkjsFns"; | ||
import { getChatID, createChatID } from "./chatID"; | ||
import createConversation from "./createConversation"; | ||
import installTalkJSStyles from "./installTalkJSStyles"; | ||
import resolveTheme from "./resolveTheme"; | ||
import { ping } from "./analytics"; | ||
/** | ||
@@ -19,8 +22,15 @@ * The interface to MeetElise chat. | ||
constructor({ organization, building, theme = {} }) { | ||
this.orgSlug = organization; | ||
this.buildingSlug = building; | ||
this.chatId = getChatID(organization, building); | ||
ping("load", this.chatId); | ||
this.theme = theme; | ||
this.building = fetchBuildingInfo(organization, building); | ||
this.popup = Promise.all([this.building, initialize()]).then(async ([building]) => { | ||
this.popup = Promise.all([this.building, MEChat.session]).then(async ([building, session]) => { | ||
const resolvedTheme = (this.theme = resolveTheme(building, theme)); | ||
installTalkJSStyles(resolvedTheme); | ||
const p = createTalkJSPopup(building, resolvedTheme); | ||
const p = session.createPopup(createConversation(session, building, resolvedTheme, this.chatId)); | ||
p.on("open", () => { | ||
ping("open", this.chatId); | ||
}); | ||
if (building.conversationMaintenanceMode) { | ||
@@ -72,4 +82,5 @@ return new Promise(() => { | ||
restartConversation() { | ||
Promise.all([this.building, this.popup]).then(([b, p]) => { | ||
restartConversation(p, b, resolveTheme(b, this.theme)); | ||
Promise.all([MEChat.session, this.building, this.popup]).then(([session, building, popup]) => { | ||
this.chatId = createChatID(this.orgSlug, this.buildingSlug); | ||
popup.select(createConversation(session, building, resolveTheme(building, this.theme), this.chatId)); | ||
}); | ||
@@ -84,9 +95,9 @@ } | ||
const focusedElement = document.activeElement; | ||
Promise.all([this.building, this.popup]) | ||
.then(([b, p]) => { | ||
const resolvedTheme = (this.theme = resolveTheme(b, { | ||
Promise.all([MEChat.session, this.building, this.popup]) | ||
.then(([session, building, popup]) => { | ||
const resolvedTheme = (this.theme = resolveTheme(building, { | ||
...this.theme, | ||
...theme, | ||
})); | ||
updateTheme(p, b, resolvedTheme); | ||
popup.select(createConversation(session, building, resolvedTheme, this.chatId)); | ||
installTalkJSStyles(resolvedTheme); | ||
@@ -122,2 +133,14 @@ return new Promise(requestAnimationFrame); | ||
} | ||
MEChat.session = Talk.ready.then(() => { | ||
const me = new Talk.User({ | ||
id: "anonymous", | ||
name: "Me", | ||
email: null, | ||
role: "default", | ||
}); | ||
return new Talk.Session({ | ||
appId: "ogKIvCor", | ||
me, | ||
}); | ||
}); | ||
//# sourceMappingURL=MEChat.js.map |
{ | ||
"name": "@meetelise/chat", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -5,4 +5,4 @@ import { v4 as uuid } from "uuid"; | ||
function generateFullKey(buildingId: number): string { | ||
return `${keyPrefix}-${buildingId}`; | ||
function generateFullKey(org: string, building: string): string { | ||
return `${keyPrefix}-${org}-${building}`; | ||
} | ||
@@ -15,7 +15,7 @@ | ||
*/ | ||
export function getChatID(buildingId: number): string { | ||
const key = generateFullKey(buildingId); | ||
export function getChatID(org: string, building: string): string { | ||
const key = generateFullKey(org, building); | ||
const existingID = localStorage.getItem(key); | ||
if (existingID) return existingID; | ||
else return createChatID(buildingId); | ||
else return createChatID(org, building); | ||
} | ||
@@ -26,7 +26,7 @@ | ||
*/ | ||
export function createChatID(buildingId: number): string { | ||
export function createChatID(org: string, building: string): string { | ||
const id = uuid(); | ||
const key = generateFullKey(buildingId); | ||
const key = generateFullKey(org, building); | ||
localStorage.setItem(key, id); | ||
return id; | ||
} |
import Talk from "talkjs"; | ||
import fetchBuildingInfo, { Building } from "./fetchBuildingInfo"; | ||
import { | ||
initialize, | ||
restartConversation, | ||
updateTheme, | ||
createTalkJSPopup, | ||
} from "./talkjsFns"; | ||
import { getChatID, createChatID } from "./chatID"; | ||
import createConversation from "./createConversation"; | ||
import installTalkJSStyles from "./installTalkJSStyles"; | ||
import resolveTheme, { Theme } from "./resolveTheme"; | ||
import { ping } from "./analytics"; | ||
@@ -25,2 +22,15 @@ /** | ||
export default class MEChat { | ||
static session: Promise<Talk.Session> = Talk.ready.then(() => { | ||
const me = new Talk.User({ | ||
id: "anonymous", | ||
name: "Me", | ||
email: null, | ||
role: "default", | ||
}); | ||
return new Talk.Session({ | ||
appId: "ogKIvCor", | ||
me, | ||
}); | ||
}); | ||
/** | ||
@@ -50,5 +60,15 @@ * Start an instance of MeetElise chat and add to the web page. | ||
restartConversation(): void { | ||
Promise.all([this.building, this.popup]).then(([b, p]) => { | ||
restartConversation(p, b, resolveTheme(b, this.theme)); | ||
}); | ||
Promise.all([MEChat.session, this.building, this.popup]).then( | ||
([session, building, popup]) => { | ||
this.chatId = createChatID(this.orgSlug, this.buildingSlug); | ||
popup.select( | ||
createConversation( | ||
session, | ||
building, | ||
resolveTheme(building, this.theme), | ||
this.chatId | ||
) | ||
); | ||
} | ||
); | ||
} | ||
@@ -63,9 +83,11 @@ | ||
const focusedElement = document.activeElement; | ||
Promise.all([this.building, this.popup]) | ||
.then(([b, p]) => { | ||
const resolvedTheme = (this.theme = resolveTheme(b, { | ||
Promise.all([MEChat.session, this.building, this.popup]) | ||
.then(([session, building, popup]) => { | ||
const resolvedTheme = (this.theme = resolveTheme(building, { | ||
...this.theme, | ||
...theme, | ||
})); | ||
updateTheme(p, b, resolvedTheme); | ||
popup.select( | ||
createConversation(session, building, resolvedTheme, this.chatId) | ||
); | ||
installTalkJSStyles(resolvedTheme); | ||
@@ -101,2 +123,4 @@ return new Promise(requestAnimationFrame); | ||
private buildingSlug: string; | ||
private orgSlug: string; | ||
private popup: Promise<Talk.Popup>; | ||
@@ -106,11 +130,21 @@ private launcher: Promise<HTMLAnchorElement>; | ||
private theme: Partial<Theme>; | ||
private chatId: string; | ||
private constructor({ organization, building, theme = {} }: Options) { | ||
this.orgSlug = organization; | ||
this.buildingSlug = building; | ||
this.chatId = getChatID(organization, building); | ||
ping("load", this.chatId); | ||
this.theme = theme; | ||
this.building = fetchBuildingInfo(organization, building); | ||
this.popup = Promise.all([this.building, initialize()]).then( | ||
async ([building]) => { | ||
this.popup = Promise.all([this.building, MEChat.session]).then( | ||
async ([building, session]) => { | ||
const resolvedTheme = (this.theme = resolveTheme(building, theme)); | ||
installTalkJSStyles(resolvedTheme); | ||
const p = createTalkJSPopup(building, resolvedTheme); | ||
const p = session.createPopup( | ||
createConversation(session, building, resolvedTheme, this.chatId) | ||
); | ||
p.on("open", () => { | ||
ping("open", this.chatId); | ||
}); | ||
if (building.conversationMaintenanceMode) { | ||
@@ -117,0 +151,0 @@ return new Promise(() => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66492
57
1107
2