Skip to content

Commit 1b263d3

Browse files
authored
Merge pull request #36 from verloop/PL-6660/add-methods
add logout method for android
2 parents 5d4d842 + 1678540 commit 1b263d3

File tree

11 files changed

+52
-46
lines changed

11 files changed

+52
-46
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ repositories {
5555

5656
dependencies {
5757
implementation 'com.facebook.react:react-android:+' // Updated for RN 0.71+
58-
implementation 'com.github.verloop:android-sdk:1.1.18'
58+
implementation 'com.github.verloop:android-sdk:1.1.19'
5959
}

android/src/main/java/com/verloopsdk/VerloopSdkModule.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,17 @@ class VerloopModule(private val reactContext: ReactApplicationContext) :
202202
activity.sendBroadcast(intent)
203203
}
204204
}
205+
206+
@ReactMethod
207+
fun logout() {
208+
verloop?.logout()
209+
verloopConfigBuilder = null
210+
verloop = null
211+
customVariableList.clear()
212+
}
213+
214+
@ReactMethod
215+
fun closeChat() {
216+
verloop?.closeChat()
217+
}
205218
}

example/VerloopLivechat.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import {
1111
import VerloopSdk from 'react-native-verloop-sdk';
1212

1313
const VerloopLiveChat: React.FC = () => {
14-
1514
useEffect(() => {
1615
if (Platform.OS === 'ios') {
1716
const module = NativeModules.RNVerloopSdk;
1817
if (module?.createAnonymousUserConfig) {
1918
VerloopSdk.createAnonymousUserConfig('your-client-id');
2019
VerloopSdk.showChat();
2120
} else {
22-
console.error("RNVerloopSdk not available in useEffect");
21+
console.error('RNVerloopSdk not available in useEffect');
2322
}
2423
}
2524
}, []);
@@ -36,6 +35,8 @@ const VerloopLiveChat: React.FC = () => {
3635
'veloop_button_clicked',
3736
event => {
3837
console.log('Button clicked event:', event, VerloopSdk);
38+
// VerloopSdk.clearChat && VerloopSdk.clearChat();
39+
VerloopSdk.logout();
3940
VerloopSdk.dismissChat();
4041
},
4142
);

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"dependencies": {
1414
"react": "19.0.0",
1515
"react-native": "0.78.0",
16-
"react-native-verloop-sdk": "^1.1.3"
16+
"react-native-verloop-sdk": "1.1.5"
1717
},
1818
"devDependencies": {
1919
"@babel/core": "^7.25.2",

ios/VerloopSdk.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ @interface RCT_EXTERN_MODULE(RNVerloopSdk, NSObject)
1616
RCT_EXTERN_METHOD(setUserPhone:(NSString *)userPhone)
1717
RCT_EXTERN_METHOD(setUserName:(NSString *)userName)
1818
RCT_EXTERN_METHOD(showChat)
19-
RCT_EXTERN_METHOD(clearChat)
20-
RCT_EXTERN_METHOD(logOut)
19+
RCT_EXTERN_METHOD(closeChat)
20+
RCT_EXTERN_METHOD(logout)
2121
RCT_EXTERN_METHOD(openWidget)
2222
RCT_EXTERN_METHOD(closeWidget)
2323
RCT_EXTERN_METHOD(enableiOSNotification:(NSString *)notificatioDeviceToken)

ios/VerloopSdk.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,24 @@ public class RNVerloopSdk : RCTEventEmitter {
170170
}
171171

172172
@objc
173-
func clearChat() {
173+
func closeChat() {
174174
if self.config != nil {
175175
DispatchQueue.main.async {
176-
self.verloop?.clearConfig()
176+
self.verloop?.closeChat()
177177
}
178178
}else{
179-
debugPrint("error -> config not initialised before clearChat method is called")
179+
debugPrint("error -> config not initialised before closeChat method is called")
180180
}
181181
}
182182

183183
@objc
184-
func logOut() {
184+
func logout() {
185185
if self.config != nil {
186186
DispatchQueue.main.async {
187187
self.verloop?.logout()
188188
}
189189
}else{
190-
debugPrint("error -> config not initialised before logOut method is called")
190+
debugPrint("error -> config not initialised before logout method is called")
191191
}
192192
}
193193

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-verloop-sdk",
3-
"version": "1.1.3",
3+
"version": "1.1.5",
44
"description": "VerloopSDK is to display client side livechat widget on the mobile app.",
55
"main": "src/index.js",
66
"types": "src/index.d.ts",

react-native-verloop-sdk.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Pod::Spec.new do |s|
1515
s.source = { :git => "https://github.com/github_account/react-native-verloop-sdk.git.git", :tag => "#{s.version}" }
1616

1717
s.source_files = "ios/**/*.{h,m,mm,swift}"
18-
s.dependency 'VerloopSDKiOS','0.2.17'
18+
s.dependency 'VerloopSDKiOS','0.2.19'
1919

2020
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
2121
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.

src/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare module "react-native-verloop-sdk" {
1+
declare module 'react-native-verloop-sdk' {
22
interface VerloopInterface {
33
createUserConfig(clientId: string, userId: string): void;
44
createAnonymousUserConfig(clientId: string): void;
@@ -14,8 +14,8 @@ declare module "react-native-verloop-sdk" {
1414
showChat(): void;
1515
addListener(eventType: string): void; // Android-specific method
1616
removeListeners(count: number): void; // Android-specific method
17-
clearChat?(): void; // IOS-specific method
18-
logOut?(): void; // IOS-specific method
17+
logout(): void; // log out from chat but does not close existing chat
18+
closeChat(): void; // closes existing chat
1919
openWidget?(): void; // IOS-specific method
2020
closeWidget?(): void; // IOS-specific method
2121
enableiOSNotification?(notificatioDeviceToken: string): void; // IOS-specific method

src/index.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,19 @@ const Verloop = {
106106
}
107107
VerloopNative.removeListeners(count);
108108
},
109-
clearChat: () => {
110-
if (react_native_1.Platform.OS === 'ios') {
111-
if (!VerloopNative.clearChat) {
112-
console.error("clearChat not available on iOS");
113-
return;
114-
}
115-
VerloopNative.clearChat();
109+
closeChat: () => {
110+
if (!VerloopNative.closeChat) {
111+
console.error("closeChat not available on", react_native_1.Platform.OS);
112+
return;
116113
}
114+
VerloopNative.closeChat();
117115
},
118-
logOut: () => {
119-
if (react_native_1.Platform.OS === 'ios') {
120-
if (!VerloopNative.logOut) {
121-
console.error("logOut not available on iOS");
122-
return;
123-
}
124-
VerloopNative.logOut();
116+
logout: () => {
117+
if (!VerloopNative.logout) {
118+
console.error("logout not available on", react_native_1.Platform.OS);
119+
return;
125120
}
121+
VerloopNative.logout();
126122
},
127123
openWidget: () => {
128124
if (react_native_1.Platform.OS === 'ios') {

0 commit comments

Comments
 (0)