-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78da39e
commit ae8dd81
Showing
14 changed files
with
256 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
function startLiveChat(license, userName, email) { | ||
window.__lc = window.__lc || {}; | ||
window.__lc.license = license;; | ||
window.__lc.asyncInit = true; | ||
(function(n, t, c) { | ||
function i(n) { | ||
return e._h ? e._h.apply(null, n) : e._q.push(n) | ||
} | ||
var e = { | ||
_q: [], | ||
_h: null, | ||
_v: "2.0", | ||
on: function() { | ||
i(["on", c.call(arguments)]) | ||
}, | ||
once: function() { | ||
i(["once", c.call(arguments)]) | ||
}, | ||
off: function() { | ||
i(["off", c.call(arguments)]) | ||
}, | ||
get: function() { | ||
if (!e._h) throw new Error("[LiveChatWidget] You can't use getters before load."); | ||
return i(["get", c.call(arguments)]) | ||
}, | ||
call: function() { | ||
i(["call", c.call(arguments)]) | ||
}, | ||
init: function() { | ||
var n = t.createElement("script"); | ||
n.async = !0, n.type = "text/javascript", n.src = "https://cdn.livechatinc.com/tracking.js", t.head.appendChild(n) | ||
} | ||
}; | ||
!n.__lc.asyncInit && e.init(), n.LiveChatWidget = n.LiveChatWidget || e | ||
}(window, document, [].slice)); | ||
window.LiveChatWidget.init(); | ||
window.LiveChatWidget.on('ready', function() { | ||
window.eventProducer.emit('event', 'chatOpen'); | ||
if (window.LiveChatWidget && typeof window.LiveChatWidget.call === 'function') { | ||
window.LiveChatWidget.call('set_customer_email', email); | ||
window.LiveChatWidget.call('set_customer_name', userName); | ||
} | ||
}); | ||
|
||
if (window.LiveChatWidget && typeof window.LiveChatWidget.call === 'function') { | ||
window.LiveChatWidget.call('maximize'); | ||
} | ||
|
||
window.LiveChatWidget.on('new_event', onNewEvent); | ||
} | ||
|
||
function onNewEvent(event) { | ||
window.eventProducer.emit('event', event.type); | ||
} | ||
|
||
function hideWindow() { | ||
LiveChatWidget.call("hide"); | ||
} | ||
|
||
function destroyWindow() { | ||
LiveChatWidget.call("destroy"); | ||
} | ||
|
||
|
||
class EventProducer { | ||
constructor() { | ||
this.listeners = {}; | ||
} | ||
|
||
on(event, listener) { | ||
if (!this.listeners[event]) { | ||
this.listeners[event] = []; | ||
} | ||
this.listeners[event].push(listener); | ||
} | ||
|
||
emit(event, data) { | ||
if (this.listeners[event]) { | ||
this.listeners[event].forEach(listener => listener(data)); | ||
} | ||
} | ||
} | ||
|
||
window.eventProducer = new EventProducer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
example/web/assets/packages/live_chat_plus/assets/live_chat.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
function startLiveChat(license, userName, email) { | ||
window.__lc = window.__lc || {}; | ||
window.__lc.license = license;; | ||
window.__lc.asyncInit = true; | ||
(function(n, t, c) { | ||
function i(n) { | ||
return e._h ? e._h.apply(null, n) : e._q.push(n) | ||
} | ||
var e = { | ||
_q: [], | ||
_h: null, | ||
_v: "2.0", | ||
on: function() { | ||
i(["on", c.call(arguments)]) | ||
}, | ||
once: function() { | ||
i(["once", c.call(arguments)]) | ||
}, | ||
off: function() { | ||
i(["off", c.call(arguments)]) | ||
}, | ||
get: function() { | ||
if (!e._h) throw new Error("[LiveChatWidget] You can't use getters before load."); | ||
return i(["get", c.call(arguments)]) | ||
}, | ||
call: function() { | ||
i(["call", c.call(arguments)]) | ||
}, | ||
init: function() { | ||
var n = t.createElement("script"); | ||
n.async = !0, n.type = "text/javascript", n.src = "https://cdn.livechatinc.com/tracking.js", t.head.appendChild(n) | ||
} | ||
}; | ||
!n.__lc.asyncInit && e.init(), n.LiveChatWidget = n.LiveChatWidget || e | ||
}(window, document, [].slice)); | ||
window.LiveChatWidget.init(); | ||
window.LiveChatWidget.on('ready', function() { | ||
window.eventProducer.emit('event', 'chatOpen'); | ||
if (window.LiveChatWidget && typeof window.LiveChatWidget.call === 'function') { | ||
window.LiveChatWidget.call('set_customer_email', email); | ||
window.LiveChatWidget.call('set_customer_name', userName); | ||
} | ||
}); | ||
|
||
if (window.LiveChatWidget && typeof window.LiveChatWidget.call === 'function') { | ||
window.LiveChatWidget.call('maximize'); | ||
} | ||
|
||
window.LiveChatWidget.on('new_event', onNewEvent); | ||
} | ||
|
||
function onNewEvent(event) { | ||
window.eventProducer.emit('event', event.type); | ||
} | ||
|
||
function hideWindow() { | ||
LiveChatWidget.call("hide"); | ||
} | ||
|
||
function destroyWindow() { | ||
LiveChatWidget.call("destroy"); | ||
} | ||
|
||
|
||
class EventProducer { | ||
constructor() { | ||
this.listeners = {}; | ||
} | ||
|
||
on(event, listener) { | ||
if (!this.listeners[event]) { | ||
this.listeners[event] = []; | ||
} | ||
this.listeners[event].push(listener); | ||
} | ||
|
||
emit(event, data) { | ||
if (this.listeners[event]) { | ||
this.listeners[event].forEach(listener => listener(data)); | ||
} | ||
} | ||
} | ||
|
||
window.eventProducer = new EventProducer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
import 'package:js/js.dart'; | ||
|
||
/// Producer class that will be called in javascript. | ||
@JS() | ||
class EventProducer { | ||
/// Triggers whenever a new event is emit in javascript. It should be listened | ||
/// to in dart. | ||
external void on(String event, Function listener); | ||
} | ||
|
||
/// Exposes [eventProducer]. | ||
@JS('window.eventProducer') | ||
external EventProducer get eventProducer; | ||
|
||
/// Triggers opening web live chat. | ||
@JS() | ||
external void startLiveChat(String licence, String userName, String email); | ||
|
||
/// Triggers hiding web live chat. | ||
@JS() | ||
external void hideWindow(); | ||
|
||
/// Triggers destroying web live chat. | ||
@JS() | ||
external void destroyWindow(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,43 @@ | ||
import 'package:live_chat_plus/src/live_chat_platform_interface.dart'; | ||
|
||
/// Live Chat Plus plugin class. | ||
class LiveChat { | ||
static final LiveChat _singleton = LiveChat._internal(); | ||
|
||
factory LiveChat() { | ||
return _singleton; | ||
} | ||
/// Constructs Livechat. | ||
factory LiveChat() => _singleton; | ||
|
||
LiveChat._internal(); | ||
|
||
static final LiveChat _singleton = LiveChat._internal(); | ||
|
||
/// Call to open the live chat window. It requires [licenseId], [username], | ||
/// and [email]. | ||
/// In addition, optional [groupId] and [customParameters] can be passed if | ||
/// needed. | ||
Future<void> openChatWindow({ | ||
required String licenseId, | ||
required String username, | ||
required String email, | ||
String? groupId, | ||
Map<String, String>? customParameters, | ||
}) async { | ||
return LiveChatPlatform.instance.openChatWindow( | ||
licenseId: licenseId, | ||
username: username, | ||
email: email, | ||
groupId: groupId, | ||
customParameters: customParameters, | ||
); | ||
} | ||
}) async => | ||
LiveChatPlatform.instance.openChatWindow( | ||
licenseId: licenseId, | ||
username: username, | ||
email: email, | ||
groupId: groupId, | ||
customParameters: customParameters, | ||
); | ||
|
||
Future<void> closeChatWindow() async { | ||
return LiveChatPlatform.instance.closeChatWindow(); | ||
} | ||
/// Call to close/hide the chat window. | ||
Future<void> closeChatWindow() async => | ||
LiveChatPlatform.instance.closeChatWindow(); | ||
|
||
Future<void> clearChatSession() async { | ||
return LiveChatPlatform.instance.clearChatSession(); | ||
} | ||
/// Call to clear the chat session, for example, after logout, | ||
Future<void> clearChatSession() async => | ||
LiveChatPlatform.instance.clearChatSession(); | ||
|
||
/// Subscribe to events stream coming from live chat windows such as: | ||
/// open, close, message, actual message text, etc. | ||
Stream<dynamic>? get onLiveChatEventReceived => | ||
LiveChatPlatform.instance.getLiveChatEventsStream(); | ||
} |
Oops, something went wrong.