mirror of
https://github.com/hub-team/OnlineChatSdk-SwiftPM.git
synced 2026-04-15 09:03:05 +00:00
update
This commit is contained in:
@@ -29,11 +29,13 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
|
|||||||
public static let method_setOperator = "setOperator"
|
public static let method_setOperator = "setOperator"
|
||||||
public static let method_getContacts = "getContacts"
|
public static let method_getContacts = "getContacts"
|
||||||
private static let method_destroy = "destroy"
|
private static let method_destroy = "destroy"
|
||||||
|
private static let method_pageLoaded = "pageLoaded"
|
||||||
|
|
||||||
public var chatView: WKWebView!
|
public var chatView: WKWebView!
|
||||||
private var callJs: Array<String>!
|
private var callJs: Array<String>!
|
||||||
private var didFinish: Bool = false
|
private var didFinish: Bool = false
|
||||||
private var widgetUrl: String = ""
|
private var widgetUrl: String = ""
|
||||||
|
private var css: String = ""
|
||||||
|
|
||||||
private static func getUnreadedMessagesCallback(_ result: NSDictionary) -> NSDictionary {
|
private static func getUnreadedMessagesCallback(_ result: NSDictionary) -> NSDictionary {
|
||||||
let resultWrapper = ChatApiMessagesWrapper(result)
|
let resultWrapper = ChatApiMessagesWrapper(result)
|
||||||
@@ -209,7 +211,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
|
|||||||
return "{}"
|
return "{}"
|
||||||
}
|
}
|
||||||
|
|
||||||
public func load(_ id: String, _ domain: String, _ language: String = "", _ clientId: String = "", _ apiToken: String = "", _ showCloseButton: Bool = true) {
|
public func load(_ id: String, _ domain: String, _ language: String = "", _ clientId: String = "", _ apiToken: String = "", _ showCloseButton: Bool = true, css: String = "") {
|
||||||
if apiToken != "" {
|
if apiToken != "" {
|
||||||
ChatConfig.setApiToken(apiToken)
|
ChatConfig.setApiToken(apiToken)
|
||||||
}
|
}
|
||||||
@@ -221,6 +223,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
|
|||||||
setup["clientId"] = clientId
|
setup["clientId"] = clientId
|
||||||
}
|
}
|
||||||
widgetUrl = "https://admin.verbox.ru/support/chat/\(id)/\(domain)"
|
widgetUrl = "https://admin.verbox.ru/support/chat/\(id)/\(domain)"
|
||||||
|
self.css = css
|
||||||
var url = URL(string: widgetUrl)
|
var url = URL(string: widgetUrl)
|
||||||
if url == nil {
|
if url == nil {
|
||||||
var encodeDomain = String(describing: domain.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed))
|
var encodeDomain = String(describing: domain.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed))
|
||||||
@@ -256,6 +259,22 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
|
|||||||
chatView.allowsBackForwardNavigationGestures = true
|
chatView.allowsBackForwardNavigationGestures = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func injectCss(style: String) {
|
||||||
|
if (style.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let injectCssTemplate = "(function() {" +
|
||||||
|
"var parent = document.getElementsByTagName('head').item(0);" +
|
||||||
|
"var style = document.createElement('style');" +
|
||||||
|
"style.type = 'text/css';" +
|
||||||
|
"style.innerHTML = '\(style)';" +
|
||||||
|
"parent.appendChild(style);" +
|
||||||
|
"})()";
|
||||||
|
|
||||||
|
callJs(injectCssTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
public func callJsMethod(_ name: String, params: Array<Any>) {
|
public func callJsMethod(_ name: String, params: Array<Any>) {
|
||||||
if didFinish {
|
if didFinish {
|
||||||
callJs(getCallJsMethod(name, params: params))
|
callJs(getCallJsMethod(name, params: params))
|
||||||
@@ -326,6 +345,9 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
|
|||||||
}
|
}
|
||||||
let name = body!["name"] as! String
|
let name = body!["name"] as! String
|
||||||
switch name {
|
switch name {
|
||||||
|
case ChatController.method_pageLoaded:
|
||||||
|
injectCss(style: self.css)
|
||||||
|
break
|
||||||
case ChatController.event_closeSupport:
|
case ChatController.event_closeSupport:
|
||||||
onCloseSupport()
|
onCloseSupport()
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user