@@ -34,6 +34,14 @@ class VLWebViewManager: NSObject,WKUIDelegate, WKNavigationDelegate {
3434 var _eventDelegate : VLEventDelegate ?
3535 private var configParams : [ VLConfig . APIMethods ] = [ ]
3636 var onMessageReceived : ( ( ) -> Void ) ?
37+
38+ func getRoomReadyConfigurations( ) -> [ VLConfig . APIMethods ] {
39+ return roomReadyConfigurations
40+ }
41+
42+ func setRoomReadyConfigurations( _ configs: [ VLConfig . APIMethods ] ) {
43+ roomReadyConfigurations = configs
44+ }
3745
3846 init ( config: VLConfig ) {
3947
@@ -163,6 +171,14 @@ class VLWebViewManager: NSObject,WKUIDelegate, WKNavigationDelegate {
163171 }
164172
165173 func logoutSession( ) {
174+ // If webview not ready, queue logout to execute when room is ready
175+ if !isRoomReady {
176+ if !roomReadyConfigurations. contains ( . logout) {
177+ roomReadyConfigurations. append ( . logout)
178+ }
179+ return
180+ }
181+
166182 webView. evaluateJavaScript ( String . getLogoutEvaluationJS ( ) ) { [ weak self] _, error in
167183 print ( " logout error \( error? . localizedDescription ?? " NA " ) " )
168184 if error == nil { // when user is logged out, clear the local cookies
@@ -303,6 +319,15 @@ extension VLWebViewManager {
303319 case . close :
304320 webView. evaluateJavaScript ( String . getCloseEvaluateJS ( ) ) { _, error in
305321 print ( " getCloseEvaluateJS error \( error? . localizedDescription ?? " NA " ) " )
322+ self . loadWebView ( )
323+ }
324+ case . logout:
325+ webView. evaluateJavaScript ( String . getLogoutEvaluationJS ( ) ) { [ weak self] _, error in
326+ print ( " processRoomReadyConfigurations logout error \( error? . localizedDescription ?? " NA " ) " )
327+ if error == nil {
328+ self ? . clearLocalStorageVistorToken ( )
329+ self ? . loadWebView ( )
330+ }
306331 }
307332 case . closeWidget:
308333 webView. evaluateJavaScript ( String . getWidgetClosedEvaluationJS ( ) ) { [ weak self] _, error in
@@ -496,6 +521,7 @@ extension VLWebViewManager:ScriptMessageDelegate {
496521 case . FunctionCloseComplete:
497522 clearLocalStorageVistorToken ( )
498523 self . didReceiveCallbackEventsOnLivechat ( message: bodyString, data: bodyData)
524+ self . loadWebView ( )
499525 case . FunctionChatMinimized:
500526 _eventDelegate? . onChatMinimized ? ( )
501527 // _eventDelegate?.didEventOccurOnLiveChat(.onChatMinimized)
@@ -548,6 +574,7 @@ extension VLWebViewManager:ScriptMessageDelegate {
548574 _eventDelegate? . onChatStarted ? ( )
549575 case FunctionType . FunctionLogOutCompleted. rawValue:
550576 _eventDelegate? . onLogoutComplete ? ( )
577+ self . loadWebView ( )
551578 default : break
552579 }
553580 }
0 commit comments