-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
284 lines (258 loc) · 12.2 KB
/
index.html
File metadata and controls
284 lines (258 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0">
</head>
<body>
<a href="http://websnapins.com">Root Domain</a>
<div id="button_goes_here">
<style type='text/css'>
.embeddedServiceLiveAgentChatButton .helpButton .uiButton { background-color: #005290; font-family: "Salesforce Sans", sans-serif; }
.embeddedServiceLiveAgentChatButton .helpButton .uiButton:focus {outline: 2px solid #005290}
@font-face {
font-family: 'Salesforce Sans';
src: url('https://www.sfdcstatic.com/system/shared/common/assets/fonts/SalesforceSans/SalesforceSans-Regular.woff') format('woff'),
url('https://www.sfdcstatic.com/system/shared/common/assets/fonts/SalesforceSans/SalesforceSans-Regular.ttf') format('truetype');
}
</style>
<script type='text/javascript' src='https://service.force.com/embeddedservice/1.0/esw.js'></script>
<script type='text/javascript'>
window.ESW_LOADED_FROM_IFRAME=false;
window.eswStorageIframe = null;
window.addEventListener("beforeunload", function(event){
console.log("SPOTIFY: WINDOWEVENT: BEFOREUNLOAD");
});
window.addEventListener("pagehide", function(event){
console.log("SPOTIFY: WINDOWEVENT: PAGEHIDE");
});
window.addEventListener("pageshow", function(event){
console.log("SPOTIFY: WINDOWEVENT: PAGESHOW");
});
window.addEventListener("load", function(event){
console.log("SPOTIFY: WINDOWEVENT: LOAD");
});
window.addEventListener("popstate", function(event){
console.log("SPOTIFY: WINDOWEVENT: POPSTATE");
});
//browser detection
var eswSafariFix = {}
eswSafariFix['getSafariType'] = function() {
var userAgent = navigator.userAgent.toLowerCase();
if(userAgent.indexOf("chrome") === -1 && userAgent.indexOf("safari") !== -1) {
if(userAgent.indexOf("mobile") === -1) {
return "desktop";
} else {
return "mobile";
}
}
return "none";
};
// Account for Safari cache quirks.
window.addEventListener("pageshow", function() {
if(eswSafariFix.getSafariType() === "desktop" && event.persisted) window.location.reload();
}, false);
window.addEventListener("popstate", function() {
if(eswSafariFix.getSafariType() === "mobile") document.location.reload();
}, false);
//set browser-specific handlers
document.domain = 'websnapins.com';
var unloadEvt = eswSafariFix.getSafariType() !== 'none' ? "pagehide" : "beforeunload";
var onloadEvt = eswSafariFix.getSafariType() !== 'none' ? "pageshow" : "load";
//load
var onPageLoad = function (event) {
var iframe;
iframe = document.createElement('iframe');
iframe.src = 'http://websnapins.com/spotify-storage.html';
iframe.id = 'storage_iframe';
iframe.style.display = 'none';
document.body.appendChild(iframe);
};
window.addEventListener(onloadEvt, onPageLoad);
//For back-forward cache
if(eswSafariFix.getSafariType() !== 'none'){
window.addEventListener("popstate", function(event){
if(event.state === "ESW_STATE_KEY" + document.location){
onPageLoad(event);
}
});
}
//unload
window.addEventListener(unloadEvt, function (event) {
console.log("SPOTIFY: UNLOAD EVENT");
// the iFrame decides based on isSafari wether to use sessionStorage or localStorage
console.log("SPOTIFY: liveagent type: " + typeof liveagent);
if(typeof liveagent !== "undefined"){
liveagent.chasitor.abortConnection();
var localChasitorData = liveagent.chasitor.serialize();
//not sure exactly why we need this, but its in liveAgentChatWindow.cmp...
var localChasitorJSON = JSON.parse(localChasitorData);
//magic to get chat state from aura component
var isChatEstablished = getESWChatState() === 'CHAT';
localChasitorJSON['chasitorData']['isChatEstablished'] = isChatEstablished;
localChasitorData = JSON.stringify(localChasitorJSON);
console.log("SPOTIFY: SETTING IFRAME DATA W/POLLCOUNT: " + window.chasitorPollCount(localChasitorData));
if(eswSafariFix.getSafariType() === "mobile"){
console.log("SPOTIFY: ABOUT TO CALL SAFARI COOKIE WORKAROUND");
safariIphoneStore(localChasitorJSON);
}else{
eswStorageIframe.storeSessionData("CHASITOR_SERIALIZED_KEY", localChasitorData);
}
}else{
if(eswStorageIframe && eswStorageIframe.removeSessionData){
eswStorageIframe.removeSessionData("CHASITOR_SERIALIZED_KEY");
}
}
if(eswStorageIframe && eswStorageIframe.removeSessionData){
eswStorageIframe.storeSessionData("ESW_MINIMIZED_WIDTH", window.sessionStorage.getItem("ESW_MINIMIZED_WIDTH"));
eswStorageIframe.storeSessionData("LA_ESW_MINIMIZED", window.sessionStorage.getItem('LA_ESW_MINIMIZED'));
eswStorageIframe.storeSessionData("LA_ESW_UNREAD_NOTIFS", window.sessionStorage.getItem('LA_ESW_UNREAD_NOTIFS'));
eswStorageIframe.storeSessionData("LA_ESW_MINIMIZED_TEXT", window.sessionStorage.getItem('LA_ESW_MINIMIZED_TEXT'));
}
});
//storage loaded
window.addEventListener('message', function (event) {
// Check for specific event: 'storage_iframe_initialize'
if (event.data == 'storage_iframe_initialized') {
eswStorageIframe = document.getElementById("storage_iframe").contentWindow;
var iFrameChasitorStr = eswStorageIframe.getSessionData("CHASITOR_SERIALIZED_KEY");
if(eswSafariFix.getSafariType() === "mobile"){
iFrameChasitorStr = safariIphoneRead();
}
if (iFrameChasitorStr) {
//get data, put into local sessionStorage
keys = ["ESW_MINIMIZED_WIDTH", "LA_ESW_MINIMIZED", "LA_ESW_UNREAD_NOTIFS", "LA_ESW_MINIMIZED_TEXT"];
keys.forEach(function(key) {
// for Safari - revert to using localStorage, otherwise sessionStorage
window.sessionStorage.setItem(key, eswStorageIframe.getSessionData(key));
});
var iFramePollCount = window.chasitorPollCount(iFrameChasitorStr);
var localPollCount = window.getLocalPollCount();
console.log("SPOTIFY: LOCAL POLL COUNT: " + localPollCount + ", SETTING TO IFRAME POLL COUNT: " + iFramePollCount);
window.sessionStorage.setItem("CHASITOR_SERIALIZED_KEY", iFrameChasitorStr);
window.ESW_LOADED_FROM_IFRAME = true;
}
//this is the normal init stuff
if (!window.embedded_svc) {
var s = document.createElement('script');
s.setAttribute('src', 'https://na1-blitz02.soma.salesforce.com/embeddedservice/1.0/esw.js');
s.onload = function() {
initESW(null);
};
document.body.appendChild(s);
} else {
initESW('https://na1-blitz02.soma.salesforce.com');
}
}
});
window.safariIphoneStore = function(chasitorObj){
console.log("SPOTIFY: safariIphoneStore");
//store chasitorData w/o messages and connection separately
//store last 3 messages in separate cookie
var chatMessages = chasitorObj.chasitorData.chatMessages;
if(chatMessages.length > 3){
chatMessages = chatMessages.slice(chatMessages.length - 3);
}
//remove these now - we will replace when we de-serialize
chasitorObj.chasitorData.chatMessages=[];
//we don't need this for an ongoing chat
chasitorObj.detailsInfo={};
var connectionStr = JSON.stringify(chasitorObj.connectionData);
var chasitorDataStr = JSON.stringify(chasitorObj.chasitorData);
var chasitorMsgStr = JSON.stringify(chatMessages);
//have to encode to store as cookie
var chasitorMsgEnc = btoa(chasitorMsgStr);
console.log("SPOTIFY: connectionStr: " + connectionStr);
console.log("SPOTIFY: chasitorDataStr: " + chasitorDataStr);
console.log("SPOTIFY: chasitorMsgEnc: " + chasitorMsgEnc);
eswStorageIframe.createCookie("ESW_CHASITOR_CONNECTION", connectionStr, 5);
eswStorageIframe.createCookie("ESW_CHASITOR_DATA", chasitorDataStr, 5);
eswStorageIframe.createCookie("ESW_CHASITOR_MESSAGES", chasitorMsgEnc, 5);
console.log("SPOTIFY: ESW_CHASITOR_CONNECTION COOKIE: " + eswStorageIframe.readCookie("ESW_CHASITOR_CONNECTION"));
console.log("SPOTIFY: ESW_CHASITOR_DATA COOKIE: " + eswStorageIframe.readCookie("ESW_CHASITOR_DATA"));
console.log("SPOTIFY: ESW_CHASITOR_MESSAGES COOKIE: " + eswStorageIframe.readCookie("ESW_CHASITOR_MESSAGES"));
}
window.safariIphoneRead = function(){
console.log("IN SAFARI IPHONE COOKIE READ FUNCTION");
//get chasitordata and connection from cookies and rebuild
var connectionStr = eswStorageIframe.readCookie("ESW_CHASITOR_CONNECTION");
var chasitorDataStr = eswStorageIframe.readCookie("ESW_CHASITOR_DATA");
var chasitorMsgStr = eswStorageIframe.readCookie("ESW_CHASITOR_MESSAGES");
console.log("SPOTIFY: READ ESW_CHASITOR_CONNECTION " + connectionStr);
console.log("SPOTIFY: READ ESW_CHASITOR_DATA " + chasitorDataStr);
if(!connectionStr || !chasitorDataStr){
console.log("SPOTIFY: NO CHASITOR DATA - RETURNING NULL");
return null;
}
var connectionObj = JSON.parse(connectionStr);
var chasitorDataObj = JSON.parse(chasitorDataStr);
//if we ran out of cookie space storing the messages they may not be here
try{
var chasitorMsgDec = atob(chasitorMsgStr);
console.log("SPOTIFY: READ ESW_CHASITOR_MESSAGES " + chasitorMsgDec);
var messagesObj = JSON.parse(chasitorMsgDec);
chasitorDataObj.chatMessages = messagesObj;
}catch(err) {
console.log("UNABLE TO RETRIEVE MESSAGES FROM COOKIE STRING: " + chasitorMsgDec);
}
console.log("SPOTIFY: GOT CHASITOR CONNECTION AND DATA OBJECTS");
var chasitorObj = {
connectionData : connectionObj,
chasitorData : chasitorDataObj
}
console.log("SPOTIFY: chasitorObj");
console.log(chasitorObj);
//done with these now
eswStorageIframe.eraseCookie("ESW_CHASITOR_CONNECTION");
eswStorageIframe.eraseCookie("ESW_CHASITOR_DATA");
var returnStr=JSON.stringify(chasitorObj);
console.log("SPOTIFY: RETURNING DATA: " + returnStr);
return returnStr;
}
//find Aura component and get chat state
window.getESWChatState = function(){
try{
if(typeof $A !== "undefined"){
var chatWindowHtml = document.querySelector(".embeddedServiceLiveAgentChatWindow");
var chatWindowHtmlCmp = $A.getComponent(chatWindowHtml);
var chatWindowCmp = chatWindowHtmlCmp.getComponentValueProvider();
if(chatWindowCmp){
return chatWindowCmp.get("v.chatWindowState");
}
}
}catch(err){
console.log("SPOTIFY: ERROR FINDING CHAT STATE: " + err);
}
return null;
}
window.getLocalPollCount = function(){
var chasitorStr = window.sessionStorage.getItem("CHASITOR_SERIALIZED_KEY");
return chasitorPollCount(chasitorStr);
}
window.chasitorPollCount = function(chasitorStr){
if(chasitorStr){
var jsonObj=JSON.parse(chasitorStr);
return jSONPollCount(jsonObj);
}
return null;
}
window.jSONPollCount = function(jsonObj){
if(jsonObj && jsonObj.connectionData){
return jsonObj.connectionData.pollCount;
}
return null;
}
var initESW = function(gslbBaseUrl) {
embedded_svc.settings.avatarImgURL = '';
embedded_svc.settings.prechatBackgroundImgURL = '';
embedded_svc.settings.waitingStateBackgroundImgURL = '';
embedded_svc.settings.smallCompanyLogoImgURL = '';
embedded_svc.settings.displayHelpButton = true; //Or false
//embedded_svc.settings.onlineText = '...'; (defaults to Chat with an Expert, localized)
//embedded_svc.settings.offlineText = '...'; (defaults to Agent Offline, localized)
//embedded_svc.settings.onlineLoadingText = '...'; (defaults to Loading, localized)
console.log("SPOTIFY: ABOUT TO CREATE WIDGET. LODADED DATA FROM IFRAME: " + window.ESW_LOADED_FROM_IFRAME);
embedded_svc.init('https://na1-blitz02.soma.salesforce.com', 'https://d.la-blitz02.soma.salesforce.com/chat', 'https://c.la-blitz02.soma.salesforce.com/content', 'https://snapins206-157442b0ff8-15ab0857300.blitz02.soma.force.com', '572D00000004EBQ', '00DD00000008amL', '573D00000004EPs', '1.0', gslbBaseUrl, '39.0', 'snappy2', 'EmbeddedServiceLiveAgent_Parent04ID000000000AuMAI_15ab097ee8f');};
</script>
</div>
</body>
</html>