mirror of
https://github.com/hub-team/OnlineChatSdk-SwiftPM.git
synced 2026-04-15 17:06:09 +00:00
open link in browser
This commit is contained in:
@@ -10,7 +10,7 @@ import UIKit
|
|||||||
import WebKit
|
import WebKit
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
|
|
||||||
open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler{
|
open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {
|
||||||
|
|
||||||
public static let event_operatorSendMessage = "operatorSendMessage";
|
public static let event_operatorSendMessage = "operatorSendMessage";
|
||||||
public static let event_clientSendMessage = "clientSendMessage";
|
public static let event_clientSendMessage = "clientSendMessage";
|
||||||
@@ -31,6 +31,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
|
|||||||
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 = ""
|
||||||
|
|
||||||
override public func loadView() {
|
override public func loadView() {
|
||||||
let contentController = WKUserContentController()
|
let contentController = WKUserContentController()
|
||||||
@@ -65,6 +66,17 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> ()) {
|
||||||
|
if let host = navigationAction.request.url?.host {
|
||||||
|
if navigationAction.request.url?.absoluteString == self.widgetUrl {
|
||||||
|
decisionHandler(.allow)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UIApplication.shared.openURL(navigationAction.request.url!)
|
||||||
|
decisionHandler(.cancel)
|
||||||
|
}
|
||||||
|
|
||||||
private func getCallJsMethod(_ name: String, params: Array<Any>) -> String {
|
private func getCallJsMethod(_ name: String, params: Array<Any>) -> String {
|
||||||
var res: String = "window.MeTalk('"
|
var res: String = "window.MeTalk('"
|
||||||
res.append(name)
|
res.append(name)
|
||||||
@@ -110,16 +122,15 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
|
|||||||
if !clientId.isEmpty {
|
if !clientId.isEmpty {
|
||||||
setup["clientId"] = clientId
|
setup["clientId"] = clientId
|
||||||
}
|
}
|
||||||
let surl = "https://admin.verbox.ru/support/chat/\(id)/\(domain)"
|
self.widgetUrl = "https://admin.verbox.ru/support/chat/\(id)/\(domain)"
|
||||||
// print("tetttt : \(surl)")
|
var url = URL(string: self.widgetUrl)
|
||||||
var url = URL(string: surl)
|
|
||||||
if !setup.isEmpty {
|
if !setup.isEmpty {
|
||||||
var urlComponents = URLComponents(url: url!, resolvingAgainstBaseURL: false)
|
var urlComponents = URLComponents(url: url!, resolvingAgainstBaseURL: false)
|
||||||
urlComponents?.queryItems = [URLQueryItem(name: "setup", value: toJson(setup as AnyObject))]
|
urlComponents?.queryItems = [URLQueryItem(name: "setup", value: toJson(setup as AnyObject))]
|
||||||
url = urlComponents!.url!
|
url = urlComponents!.url!
|
||||||
}
|
}
|
||||||
if url == nil {
|
if url == nil {
|
||||||
url = URL(string: surl)
|
url = URL(string: self.widgetUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.chatView.load(URLRequest(url: url!))
|
self.chatView.load(URLRequest(url: url!))
|
||||||
@@ -138,7 +149,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func callJsSetClientInfo(_ jsonInfo: String) {
|
public func callJsSetClientInfo(_ jsonInfo: String) {
|
||||||
callJsMethod(ChatController.method_setClientInfo, params: [jsonInfo])
|
callJsMethod(ChatController.method_setClientInfo, params: [Command(jsonInfo)])
|
||||||
}
|
}
|
||||||
|
|
||||||
public func callJsSetTarget(_ reason: String) {
|
public func callJsSetTarget(_ reason: String) {
|
||||||
|
|||||||
Reference in New Issue
Block a user