From 77b89938dcbe5a2d958bcfdde28954cf65551dcd Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 28 Aug 2024 17:23:21 +0300 Subject: [PATCH 01/57] feat(android): add SRSyncCallback --- .../com/instabug/reactlibrary/Constants.java | 2 + .../RNInstabugSessionReplayModule.java | 73 ++++++++++++++++++- .../RNInstabugSessionReplayModuleTest.java | 73 +++++++++++++++---- 3 files changed, 131 insertions(+), 17 deletions(-) diff --git a/android/src/main/java/com/instabug/reactlibrary/Constants.java b/android/src/main/java/com/instabug/reactlibrary/Constants.java index f78d3a732d..fcab683326 100644 --- a/android/src/main/java/com/instabug/reactlibrary/Constants.java +++ b/android/src/main/java/com/instabug/reactlibrary/Constants.java @@ -9,4 +9,6 @@ final class Constants { final static String IBG_ON_NEW_MESSAGE_HANDLER = "IBGonNewMessageHandler"; final static String IBG_ON_NEW_REPLY_RECEIVED_CALLBACK = "IBGOnNewReplyReceivedCallback"; + final static String IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION = "IBGSessionReplayOnSyncCallback"; + } diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index 5024c61804..0d836832ca 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -1,24 +1,40 @@ package com.instabug.reactlibrary; + +import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; -import com.instabug.chat.Replies; +import com.facebook.react.bridge.WritableMap; import com.instabug.library.OnSessionReplayLinkReady; +import com.instabug.library.SessionSyncListener; import com.instabug.library.sessionreplay.SessionReplay; +import com.instabug.library.sessionreplay.model.SessionMetadata; +import com.instabug.reactlibrary.utils.EventEmitterModule; import com.instabug.reactlibrary.utils.MainThreadHandler; +import java.util.concurrent.CountDownLatch; import javax.annotation.Nonnull; -public class RNInstabugSessionReplayModule extends ReactContextBaseJavaModule { +public class RNInstabugSessionReplayModule extends EventEmitterModule { public RNInstabugSessionReplayModule(ReactApplicationContext reactApplicationContext) { super(reactApplicationContext); } + @ReactMethod + public void addListener(String event) { + super.addListener(event); + } + + @ReactMethod + public void removeListeners(Integer count) { + super.removeListeners(count); + } + @Nonnull @Override public String getName() { @@ -99,4 +115,55 @@ public void onSessionReplayLinkReady(@Nullable String link) { } + + volatile boolean shouldSync = false; + CountDownLatch latch; + @ReactMethod + public void setSyncCallback() { + MainThreadHandler.runOnMainThread(new Runnable() { + @Override + public void run() { + try { + SessionReplay.setSyncCallback(new SessionSyncListener() { + @Override + public boolean onSessionReadyToSync(@NonNull SessionMetadata sessionMetadata) { + WritableMap params = Arguments.createMap(); + params.putString("appVersion",sessionMetadata.getAppVersion()); + params.putString("OS",sessionMetadata.getOs()); + params.putString("device",sessionMetadata.getDevice()); + params.putDouble("sessionDurationInSeconds",(double)sessionMetadata.getSessionDurationInSeconds()); + + sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION,params); + + latch = new CountDownLatch(1); + + try { + latch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + return shouldSync; + } + }); + } + catch(Exception e){ + e.printStackTrace(); + } + + } + }); + } + + @ReactMethod + public void evaluateSync(boolean result) { + shouldSync = result; + + if (latch != null) { + latch.countDown(); + } + } + + + } diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java index ecf339c72b..cf3928e295 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java @@ -1,28 +1,26 @@ package com.instabug.reactlibrary; +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertTrue; + import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.times; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import android.os.Handler; import android.os.Looper; import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.JavaOnlyArray; +import com.facebook.react.bridge.JavaOnlyMap; import com.facebook.react.bridge.Promise; -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.bridge.WritableArray; -import com.instabug.chat.Replies; -import com.instabug.featuresrequest.ActionType; -import com.instabug.featuresrequest.FeatureRequests; -import com.instabug.library.Feature; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.WritableMap; import com.instabug.library.OnSessionReplayLinkReady; +import com.instabug.library.SessionSyncListener; import com.instabug.library.sessionreplay.SessionReplay; +import com.instabug.library.sessionreplay.model.SessionMetadata; import com.instabug.reactlibrary.utils.MainThreadHandler; import org.junit.After; @@ -33,6 +31,7 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -44,8 +43,8 @@ public class RNInstabugSessionReplayModuleTest { // Mock Objects private MockedStatic mockLooper; - private MockedStatic mockMainThreadHandler; - private MockedStatic mockSessionReplay; + private MockedStatic mockMainThreadHandler; + private MockedStatic mockSessionReplay; @Before public void mockMainThreadHandler() throws Exception { @@ -107,7 +106,7 @@ public void testSetInstabugLogsEnabled() { @Test public void testGetSessionReplayLink() { Promise promise = mock(Promise.class); - String link="instabug link"; + String link = "instabug link"; mockSessionReplay.when(() -> SessionReplay.getSessionReplayLink(any())).thenAnswer( invocation -> { @@ -136,5 +135,51 @@ public void testSetUserStepsEnabled() { mockSessionReplay.verifyNoMoreInteractions(); } + @Test + + public void testSetSyncCallback() throws Exception { + MockedStatic mockArgument = mockStatic(Arguments.class); + RNInstabugSessionReplayModule SRModule = spy(new RNInstabugSessionReplayModule(mock(ReactApplicationContext.class))); + + CountDownLatch latch =new CountDownLatch(1); + SRModule.latch=latch; + + when(Arguments.createMap()).thenReturn(new JavaOnlyMap()); + + mockSessionReplay.when(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))) + .thenAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocation) { + ((SessionSyncListener) invocation.getArguments()[0]).onSessionReadyToSync(new SessionMetadata("device","android","1.0",20)); + return null; + } + }); + + Thread thread= new Thread (() ->{ + try { + Thread.sleep(500); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + SRModule.evaluateSync(true); + }); + thread.start(); + + SRModule.setSyncCallback(); + + WritableMap params = Arguments.createMap(); + params.putString("appVersion","1.0"); + params.putString("OS","android"); + params.putString("device","device"); + params.putDouble("sessionDurationInSeconds",20); + + assertEquals(SRModule.shouldSync,true); + assertTrue("Latch should be zero after evaluateSync is called", SRModule.latch.getCount() == 0); + + verify(SRModule).sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION, params); + mockSessionReplay.verify(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))); + + mockArgument.close(); + } } From e6b816f68141f27dc6543fa22fcad131400cd8e6 Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 28 Aug 2024 17:24:53 +0300 Subject: [PATCH 02/57] feat: implement and test syncCallback CP side --- src/modules/SessionReplay.ts | 37 +++++++++++++++++++++++++++++- src/native/NativeSessionReplay.ts | 9 +++++++- test/mocks/mockSessionReplay.ts | 2 ++ test/modules/SessionReplay.spec.ts | 13 ++++++++++- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index edfef456f3..70a296915c 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -1,4 +1,4 @@ -import { NativeSessionReplay } from '../native/NativeSessionReplay'; +import { NativeSessionReplay, NativeEvents, emitter } from '../native/NativeSessionReplay'; /** * Enables or disables Session Replay for your Instabug integration. @@ -75,3 +75,38 @@ export const setUserStepsEnabled = (isEnabled: boolean) => { export const getSessionReplayLink = async (): Promise => { return NativeSessionReplay.getSessionReplayLink(); }; + +/** + * Set a callback for weather this session should sync + * + * @param handler + + * @example + * ```ts + * SessionReplay.setSyncCallback((payload)=>{ + * if(payload.device == "Xiaomi M2007J3SY" && + * payload.os == "OS Level 33" && + * payload.appVersion == "3.1.4 (4)" || + * payload.sessionDurationInSeconds > 20 ) + * {return true} + * }); + * ``` + */ +export const setSyncCallback = async ( + handler: (payload: { + appVersion: string; + OS: string; + device: string; + sessionDurationInSeconds: number; + }) => boolean, +): Promise => { + emitter.addListener(NativeEvents.SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION, (payload) => { + if (typeof handler(payload) != 'boolean') { + console.warn('setSyncCallback expects boolean value'); + } + + NativeSessionReplay.evaluateSync(Boolean(handler(payload))); + }); + + return NativeSessionReplay.setSyncCallback(); +}; diff --git a/src/native/NativeSessionReplay.ts b/src/native/NativeSessionReplay.ts index 9c3090fb19..2d0637e3d1 100644 --- a/src/native/NativeSessionReplay.ts +++ b/src/native/NativeSessionReplay.ts @@ -1,4 +1,4 @@ -import type { NativeModule } from 'react-native'; +import { NativeEventEmitter, type NativeModule } from 'react-native'; import { NativeModules } from './NativePackage'; @@ -8,6 +8,13 @@ export interface SessionReplayNativeModule extends NativeModule { setInstabugLogsEnabled(isEnabled: boolean): void; setUserStepsEnabled(isEnabled: boolean): void; getSessionReplayLink(): Promise; + setSyncCallback(): Promise; + evaluateSync(shouldSync: boolean): void; } export const NativeSessionReplay = NativeModules.IBGSessionReplay; +export enum NativeEvents { + SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION = 'IBGSessionReplayOnSyncCallback', +} + +export const emitter = new NativeEventEmitter(NativeSessionReplay); diff --git a/test/mocks/mockSessionReplay.ts b/test/mocks/mockSessionReplay.ts index ea61a8356f..9106a205a0 100644 --- a/test/mocks/mockSessionReplay.ts +++ b/test/mocks/mockSessionReplay.ts @@ -8,6 +8,8 @@ const mockSessionReplay: SessionReplayNativeModule = { setInstabugLogsEnabled: jest.fn(), setUserStepsEnabled: jest.fn(), getSessionReplayLink: jest.fn().mockReturnValue('link'), + setSyncCallback: jest.fn(), + evaluateSync: jest.fn(), }; export default mockSessionReplay; diff --git a/test/modules/SessionReplay.spec.ts b/test/modules/SessionReplay.spec.ts index 052a63891e..b42b7fa646 100644 --- a/test/modules/SessionReplay.spec.ts +++ b/test/modules/SessionReplay.spec.ts @@ -1,5 +1,5 @@ import * as SessionReplay from '../../src/modules/SessionReplay'; -import { NativeSessionReplay } from '../../src/native/NativeSessionReplay'; +import { NativeSessionReplay, emitter, NativeEvents } from '../../src/native/NativeSessionReplay'; describe('Session Replay Module', () => { it('should call the native method setEnabled', () => { @@ -36,4 +36,15 @@ describe('Session Replay Module', () => { expect(NativeSessionReplay.getSessionReplayLink).toBeCalledTimes(1); expect(NativeSessionReplay.getSessionReplayLink).toReturnWith('link'); }); + + it('should call the native method setSyncCallback', () => { + const callback = jest.fn().mockReturnValue(true); + + SessionReplay.setSyncCallback(callback); + emitter.emit(NativeEvents.SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION); + + expect(NativeSessionReplay.setSyncCallback).toBeCalledTimes(1); + expect(emitter.listenerCount(NativeEvents.SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION)).toBe(1); + expect(NativeSessionReplay.evaluateSync).toBeCalledTimes(1); + }); }); From bad72d60bb5474b8a5eccaa956cbaac954f38d42 Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 28 Aug 2024 17:25:57 +0300 Subject: [PATCH 03/57] feat(example): use SRSyncCallback in example app --- examples/default/src/App.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/examples/default/src/App.tsx b/examples/default/src/App.tsx index 33a3c34f94..fa31d67f0a 100644 --- a/examples/default/src/App.tsx +++ b/examples/default/src/App.tsx @@ -8,6 +8,7 @@ import Instabug, { InvocationEvent, LogLevel, ReproStepsMode, + SessionReplay, } from 'instabug-reactnative'; import { NativeBaseProvider } from 'native-base'; @@ -20,8 +21,26 @@ import { QueryClient, QueryClientProvider } from 'react-query'; const queryClient = new QueryClient(); export const App: React.FC = () => { + const shouldSyncSession = (data: { + appVersion: string; + OS: string; + device: string; + sessionDurationInSeconds: number; + }) => { + if (data.sessionDurationInSeconds > 20) { + return true; + } + if (data.OS == 'OS Level 34') { + return true; + } + return false; + }; + const navigationRef = useNavigationContainerRef(); + useEffect(() => { + SessionReplay.setSyncCallback((data) => shouldSyncSession(data)); + Instabug.init({ token: 'deb1910a7342814af4e4c9210c786f35', invocationEvents: [InvocationEvent.floatingButton], From 2b01c9d51992848318f0cc64b084b4a7b89df993 Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 28 Aug 2024 17:41:35 +0300 Subject: [PATCH 04/57] ci: fix tests --- examples/default/src/App.tsx | 2 +- src/modules/SessionReplay.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/default/src/App.tsx b/examples/default/src/App.tsx index fa31d67f0a..dadd26452e 100644 --- a/examples/default/src/App.tsx +++ b/examples/default/src/App.tsx @@ -30,7 +30,7 @@ export const App: React.FC = () => { if (data.sessionDurationInSeconds > 20) { return true; } - if (data.OS == 'OS Level 34') { + if (data.OS === 'OS Level 34') { return true; } return false; diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index 70a296915c..b5acd1d18a 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -78,7 +78,7 @@ export const getSessionReplayLink = async (): Promise => { /** * Set a callback for weather this session should sync - * + * * @param handler * @example @@ -101,7 +101,7 @@ export const setSyncCallback = async ( }) => boolean, ): Promise => { emitter.addListener(NativeEvents.SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION, (payload) => { - if (typeof handler(payload) != 'boolean') { + if (typeof handler(payload) !== 'boolean') { console.warn('setSyncCallback expects boolean value'); } From 61d6e5217f668b5bacb33d86205a47929562dd06 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 2 Sep 2024 17:29:02 +0300 Subject: [PATCH 05/57] fix: export session data type --- src/index.ts | 3 ++- src/modules/SessionReplay.ts | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index a6c425fcd0..3e0358cc29 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,7 @@ import * as Replies from './modules/Replies'; import type { Survey } from './modules/Surveys'; import * as Surveys from './modules/Surveys'; import * as SessionReplay from './modules/SessionReplay'; +import type { sessionData } from './modules/SessionReplay'; export * from './utils/Enums'; export { @@ -28,6 +29,6 @@ export { Replies, Surveys, }; -export type { InstabugConfig, Survey, NetworkData, NetworkDataObfuscationHandler }; +export type { InstabugConfig, Survey, NetworkData, NetworkDataObfuscationHandler, sessionData }; export default Instabug; diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index b5acd1d18a..139b2d2113 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -1,5 +1,11 @@ import { NativeSessionReplay, NativeEvents, emitter } from '../native/NativeSessionReplay'; +export interface sessionData { + appVersion: string; + OS: string; + device: string; + sessionDurationInSeconds: number; +} /** * Enables or disables Session Replay for your Instabug integration. * @@ -93,16 +99,16 @@ export const getSessionReplayLink = async (): Promise => { * ``` */ export const setSyncCallback = async ( - handler: (payload: { - appVersion: string; - OS: string; - device: string; - sessionDurationInSeconds: number; - }) => boolean, + handler: (payload: sessionData) => boolean, ): Promise => { emitter.addListener(NativeEvents.SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION, (payload) => { - if (typeof handler(payload) !== 'boolean') { - console.warn('setSyncCallback expects boolean value'); + const result = handler(payload); + const shouldSync = Boolean(result); + + if (typeof result !== 'boolean') { + console.warn( + `IBG-RN: The callback passed to SessionReplay.setSyncCallback was expected to return a boolean but returned "${result}". The value has been cast to boolean, proceeding with ${shouldSync}.`, + ); } NativeSessionReplay.evaluateSync(Boolean(handler(payload))); From 849648a635ff48928dbdf6f03054cd77289002f4 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 2 Sep 2024 17:29:54 +0300 Subject: [PATCH 06/57] fix(example): use session data type --- examples/default/src/App.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/default/src/App.tsx b/examples/default/src/App.tsx index dadd26452e..46e05baa42 100644 --- a/examples/default/src/App.tsx +++ b/examples/default/src/App.tsx @@ -10,6 +10,7 @@ import Instabug, { ReproStepsMode, SessionReplay, } from 'instabug-reactnative'; +import type { sessionData } from 'instabug-reactnative'; import { NativeBaseProvider } from 'native-base'; import { RootTabNavigator } from './navigation/RootTab'; @@ -21,12 +22,7 @@ import { QueryClient, QueryClientProvider } from 'react-query'; const queryClient = new QueryClient(); export const App: React.FC = () => { - const shouldSyncSession = (data: { - appVersion: string; - OS: string; - device: string; - sessionDurationInSeconds: number; - }) => { + const shouldSyncSession = (data: sessionData) => { if (data.sessionDurationInSeconds > 20) { return true; } From 02c621c6e898eb24938294c304b4a6b06d8c1c5b Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 2 Sep 2024 17:32:05 +0300 Subject: [PATCH 07/57] fix(android):remove data modifier --- .../instabug/reactlibrary/RNInstabugSessionReplayModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index 0d836832ca..59a4768b5f 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -116,7 +116,7 @@ public void onSessionReplayLinkReady(@Nullable String link) { } - volatile boolean shouldSync = false; + boolean shouldSync = false; CountDownLatch latch; @ReactMethod public void setSyncCallback() { From 0d9c7f1bf2037951547a0de6385021ffc7a060a0 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 2 Sep 2024 21:24:29 +0300 Subject: [PATCH 08/57] fix(android): add property modifiers --- .../instabug/reactlibrary/RNInstabugSessionReplayModule.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index 59a4768b5f..bc24c26f2a 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -115,9 +115,8 @@ public void onSessionReplayLinkReady(@Nullable String link) { } - - boolean shouldSync = false; - CountDownLatch latch; + private boolean shouldSync = false; + private CountDownLatch latch; @ReactMethod public void setSyncCallback() { MainThreadHandler.runOnMainThread(new Runnable() { From 261aa764c7174ce7c00bcaeeefd421288fb537f0 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 2 Sep 2024 21:25:16 +0300 Subject: [PATCH 09/57] fix(android): update test case --- .../RNInstabugSessionReplayModuleTest.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java index cf3928e295..270be36282 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java @@ -4,6 +4,7 @@ import static junit.framework.TestCase.assertTrue; import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.spy; @@ -34,6 +35,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; public class RNInstabugSessionReplayModuleTest { @@ -141,8 +143,8 @@ public void testSetSyncCallback() throws Exception { MockedStatic mockArgument = mockStatic(Arguments.class); RNInstabugSessionReplayModule SRModule = spy(new RNInstabugSessionReplayModule(mock(ReactApplicationContext.class))); - CountDownLatch latch =new CountDownLatch(1); - SRModule.latch=latch; + AtomicBoolean result = new AtomicBoolean(false); + boolean shouldSync=true; when(Arguments.createMap()).thenReturn(new JavaOnlyMap()); @@ -150,32 +152,35 @@ public void testSetSyncCallback() throws Exception { .thenAnswer(new Answer() { @Override public Void answer(InvocationOnMock invocation) { - ((SessionSyncListener) invocation.getArguments()[0]).onSessionReadyToSync(new SessionMetadata("device","android","1.0",20)); + SessionSyncListener listener = (SessionSyncListener) invocation.getArguments()[0]; + SessionMetadata metadata = new SessionMetadata("device", "android", "1.0", 20); + boolean shouldSync=listener.onSessionReadyToSync(metadata); + result.set(shouldSync); return null; } }); + WritableMap params = Arguments.createMap(); + params.putString("appVersion","1.0"); + params.putString("OS","android"); + params.putString("device","device"); + params.putDouble("sessionDurationInSeconds",20); + Thread thread= new Thread (() ->{ try { Thread.sleep(500); } catch (InterruptedException e) { throw new RuntimeException(e); } - SRModule.evaluateSync(true); + + SRModule.evaluateSync(shouldSync); }); + thread.start(); SRModule.setSyncCallback(); - WritableMap params = Arguments.createMap(); - params.putString("appVersion","1.0"); - params.putString("OS","android"); - params.putString("device","device"); - params.putDouble("sessionDurationInSeconds",20); - - assertEquals(SRModule.shouldSync,true); - assertTrue("Latch should be zero after evaluateSync is called", SRModule.latch.getCount() == 0); - + assertEquals(shouldSync,result.get()); verify(SRModule).sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION, params); mockSessionReplay.verify(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))); From 5056f5840a720cfc534f869efdd93f51c16744f3 Mon Sep 17 00:00:00 2001 From: kholood Date: Thu, 5 Sep 2024 10:48:51 +0300 Subject: [PATCH 10/57] fix: enhance test case --- .../RNInstabugSessionReplayModuleTest.java | 63 +++++++++---------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java index 270be36282..43c87d8e45 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java @@ -3,9 +3,11 @@ import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertTrue; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockConstruction; import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -27,6 +29,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.mockito.MockedConstruction; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -138,53 +141,43 @@ public void testSetUserStepsEnabled() { } @Test - public void testSetSyncCallback() throws Exception { - MockedStatic mockArgument = mockStatic(Arguments.class); - RNInstabugSessionReplayModule SRModule = spy(new RNInstabugSessionReplayModule(mock(ReactApplicationContext.class))); + MockedStatic mockArguments = mockStatic(Arguments.class); + MockedConstruction mockCountDownLatch = mockConstruction(CountDownLatch.class); + RNInstabugSessionReplayModule SRModule = spy(new RNInstabugSessionReplayModule(mock(ReactApplicationContext.class))); - AtomicBoolean result = new AtomicBoolean(false); - boolean shouldSync=true; + final boolean shouldSync = true; + final AtomicBoolean actual = new AtomicBoolean(); - when(Arguments.createMap()).thenReturn(new JavaOnlyMap()); + mockArguments.when(Arguments::createMap).thenReturn(new JavaOnlyMap()); - mockSessionReplay.when(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))) - .thenAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocation) { + mockSessionReplay.when(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))) + .thenAnswer((invocation) -> { SessionSyncListener listener = (SessionSyncListener) invocation.getArguments()[0]; SessionMetadata metadata = new SessionMetadata("device", "android", "1.0", 20); - boolean shouldSync=listener.onSessionReadyToSync(metadata); - result.set(shouldSync); + actual.set(listener.onSessionReadyToSync(metadata)); return null; - } - }); + }); - WritableMap params = Arguments.createMap(); - params.putString("appVersion","1.0"); - params.putString("OS","android"); - params.putString("device","device"); - params.putDouble("sessionDurationInSeconds",20); - - Thread thread= new Thread (() ->{ - try { - Thread.sleep(500); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } + doAnswer((invocation) -> { + SRModule.evaluateSync(shouldSync); + return null; + }).when(SRModule).sendEvent(eq(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION), any()); - SRModule.evaluateSync(shouldSync); - }); - - thread.start(); + WritableMap params = Arguments.createMap(); + params.putString("appVersion","1.0"); + params.putString("OS","android"); + params.putString("device","device"); + params.putDouble("sessionDurationInSeconds",20); - SRModule.setSyncCallback(); + SRModule.setSyncCallback(); - assertEquals(shouldSync,result.get()); - verify(SRModule).sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION, params); - mockSessionReplay.verify(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))); + assertEquals(shouldSync, actual.get()); + verify(SRModule).sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION, params); + mockSessionReplay.verify(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))); - mockArgument.close(); + mockArguments.close(); + mockCountDownLatch.close(); } } From 8d9036e2020be91147670eb20a4cd98e4bda0a02 Mon Sep 17 00:00:00 2001 From: kholood Date: Sun, 8 Sep 2024 16:51:57 +0300 Subject: [PATCH 11/57] fix(ios): update network log signature --- examples/default/ios/InstabugTests/InstabugSampleTests.m | 7 ++----- ios/RNInstabug/InstabugReactBridge.h | 4 +--- ios/RNInstabug/InstabugReactBridge.m | 6 ++---- ios/RNInstabug/Util/IBGNetworkLogger+CP.h | 3 +-- src/native/NativeInstabug.ts | 1 - src/utils/InstabugUtils.ts | 1 - 6 files changed, 6 insertions(+), 16 deletions(-) diff --git a/examples/default/ios/InstabugTests/InstabugSampleTests.m b/examples/default/ios/InstabugTests/InstabugSampleTests.m index 70ef410258..742c2d77c5 100644 --- a/examples/default/ios/InstabugTests/InstabugSampleTests.m +++ b/examples/default/ios/InstabugTests/InstabugSampleTests.m @@ -331,7 +331,6 @@ - (void)testNetworkLogIOS { double startTime = 1719847101199; double duration = 150; NSString *gqlQueryName = nil; - NSString *serverErrorMessage = nil; [self.instabugBridge networkLogIOS:url method:method @@ -347,8 +346,7 @@ - (void)testNetworkLogIOS { errorCode:errorCode startTime:startTime duration:duration - gqlQueryName:gqlQueryName - serverErrorMessage:serverErrorMessage]; + gqlQueryName:gqlQueryName]; OCMVerify([mIBGNetworkLogger addNetworkLogWithUrl:url method:method @@ -364,8 +362,7 @@ - (void)testNetworkLogIOS { errorCode:errorCode startTime:startTime * 1000 duration:duration * 1000 - gqlQueryName:gqlQueryName - serverErrorMessage:serverErrorMessage]); + gqlQueryName:gqlQueryName]); } - (void)testSetFileAttachment { diff --git a/ios/RNInstabug/InstabugReactBridge.h b/ios/RNInstabug/InstabugReactBridge.h index a3cfc21c13..a9f92fde44 100644 --- a/ios/RNInstabug/InstabugReactBridge.h +++ b/ios/RNInstabug/InstabugReactBridge.h @@ -120,9 +120,7 @@ errorCode:(double)errorCode startTime:(double)startTime duration:(double)duration - gqlQueryName:(NSString * _Nullable)gqlQueryName - serverErrorMessage:(NSString * _Nullable)serverErrorMessage; - + gqlQueryName:(NSString * _Nullable)gqlQueryName; /* +------------------------------------------------------------------------+ | Experiments | diff --git a/ios/RNInstabug/InstabugReactBridge.m b/ios/RNInstabug/InstabugReactBridge.m index dd18513163..abe1a6e453 100644 --- a/ios/RNInstabug/InstabugReactBridge.m +++ b/ios/RNInstabug/InstabugReactBridge.m @@ -297,8 +297,7 @@ - (dispatch_queue_t)methodQueue { errorCode:(double)errorCode startTime:(double)startTime duration:(double)duration - gqlQueryName:(NSString * _Nullable)gqlQueryName - serverErrorMessage:(NSString * _Nullable)serverErrorMessage) { + gqlQueryName:(NSString * _Nullable)gqlQueryName) { [IBGNetworkLogger addNetworkLogWithUrl:url method:method requestBody:requestBody @@ -313,8 +312,7 @@ - (dispatch_queue_t)methodQueue { errorCode:errorCode startTime:startTime * 1000 duration:duration * 1000 - gqlQueryName:gqlQueryName - serverErrorMessage:serverErrorMessage]; + gqlQueryName:gqlQueryName]; } RCT_EXPORT_METHOD(addPrivateView: (nonnull NSNumber *)reactTag) { diff --git a/ios/RNInstabug/Util/IBGNetworkLogger+CP.h b/ios/RNInstabug/Util/IBGNetworkLogger+CP.h index 5ae464785f..771417cfbd 100644 --- a/ios/RNInstabug/Util/IBGNetworkLogger+CP.h +++ b/ios/RNInstabug/Util/IBGNetworkLogger+CP.h @@ -19,8 +19,7 @@ NS_ASSUME_NONNULL_BEGIN errorCode:(int32_t)errorCode startTime:(int64_t)startTime duration:(int64_t) duration - gqlQueryName:(NSString * _Nullable)gqlQueryName - serverErrorMessage:(NSString * _Nullable)serverErrorMessage; + gqlQueryName:(NSString * _Nullable)gqlQueryName; @end diff --git a/src/native/NativeInstabug.ts b/src/native/NativeInstabug.ts index 3b72f5951f..223aec83d0 100644 --- a/src/native/NativeInstabug.ts +++ b/src/native/NativeInstabug.ts @@ -66,7 +66,6 @@ export interface InstabugNativeModule extends NativeModule { startTime: number, duration: number, gqlQueryName: string | undefined, - serverErrorMessage: string | undefined, ): void; setNetworkLoggingEnabled(isEnabled: boolean): void; diff --git a/src/utils/InstabugUtils.ts b/src/utils/InstabugUtils.ts index d4238f14f0..80f632a0d5 100644 --- a/src/utils/InstabugUtils.ts +++ b/src/utils/InstabugUtils.ts @@ -191,7 +191,6 @@ export function reportNetworkLog(network: NetworkData) { network.startTime, network.duration, network.gqlQueryName, - network.serverErrorMessage, ); } } From 1ce3f360b0a43d7e4564823990a67d6c7e0bfde2 Mon Sep 17 00:00:00 2001 From: kholood Date: Sun, 8 Sep 2024 16:52:45 +0300 Subject: [PATCH 12/57] chore(ios): integrate dynamic sampling snapshot --- RNInstabug.podspec | 2 +- examples/default/ios/Podfile | 4 ++-- examples/default/ios/Podfile.lock | 20 +++++++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/RNInstabug.podspec b/RNInstabug.podspec index 40c480f4cb..21ae5fc720 100644 --- a/RNInstabug.podspec +++ b/RNInstabug.podspec @@ -16,5 +16,5 @@ Pod::Spec.new do |s| s.source_files = "ios/**/*.{h,m,mm}" s.dependency 'React-Core' - use_instabug!(s) + s.dependency 'Instabug' end diff --git a/examples/default/ios/Podfile b/examples/default/ios/Podfile index 3d0c8ceedb..683b5bda63 100644 --- a/examples/default/ios/Podfile +++ b/examples/default/ios/Podfile @@ -32,8 +32,8 @@ target 'InstabugExample' do target 'InstabugTests' do inherit! :complete pod 'OCMock' - # Pods for testing - end + pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-base/13.4.0/Instabug.podspec' + end post_install do |installer| react_native_post_install( diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index 1da6e558ee..858e643eaa 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -38,12 +38,12 @@ PODS: - hermes-engine (0.72.3): - hermes-engine/Pre-built (= 0.72.3) - hermes-engine/Pre-built (0.72.3) - - Instabug (13.3.0) + - Instabug (13.4.0) - instabug-reactnative-ndk (0.1.0): - RCT-Folly (= 2021.07.22.00) - React-Core - libevent (2.1.12) - - OCMock (3.9.3) + - OCMock (3.9.4) - RCT-Folly (2021.07.22.00): - boost - DoubleConversion @@ -476,7 +476,7 @@ PODS: - RCT-Folly (= 2021.07.22.00) - React-Core - RNInstabug (13.3.0): - - Instabug (= 13.3.0) + - Instabug - React-Core - RNReanimated (3.5.4): - DoubleConversion @@ -524,6 +524,7 @@ DEPENDENCIES: - FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) + - Instabug (from `https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-base/13.4.0/Instabug.podspec`) - instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`) - libevent (~> 2.1.12) - OCMock @@ -580,7 +581,6 @@ SPEC REPOS: - fmt - Google-Maps-iOS-Utils - GoogleMaps - - Instabug - libevent - OCMock - SocketRocket @@ -599,6 +599,8 @@ EXTERNAL SOURCES: hermes-engine: :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" :tag: hermes-2023-03-20-RNv0.72.0-49794cfc7c81fb8f69fd60c3bbf85a7480cc5a77 + Instabug: + :podspec: https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-base/13.4.0/Instabug.podspec instabug-reactnative-ndk: :path: "../node_modules/instabug-reactnative-ndk" RCT-Folly: @@ -704,10 +706,10 @@ SPEC CHECKSUMS: Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac hermes-engine: 10fbd3f62405c41ea07e71973ea61e1878d07322 - Instabug: 4f26295103a330ec0236918359eef7ccaa74e2fa + Instabug: ba4486333cb9c71b8d31f88d7050084402095ac4 instabug-reactnative-ndk: 960119a69380cf4cbe47ccd007c453f757927d17 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - OCMock: 300b1b1b9155cb6378660b981c2557448830bdc6 + OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74 RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1 RCTRequired: a2faf4bad4e438ca37b2040cb8f7799baa065c18 RCTTypeSafety: cb09f3e4747b6d18331a15eb05271de7441ca0b3 @@ -748,7 +750,7 @@ SPEC CHECKSUMS: ReactCommon: 3ccb8fb14e6b3277e38c73b0ff5e4a1b8db017a9 RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495 RNGestureHandler: 6e46dde1f87e5f018a54fe5d40cd0e0b942b49ee - RNInstabug: a4ac0bd09123f6be7d58be541dc220acbaff8dc3 + RNInstabug: 80b369d623a473c31ff3b8b8ea1d17daaca44132 RNReanimated: ab2e96c6d5591c3dfbb38a464f54c8d17fb34a87 RNScreens: b21dc57dfa2b710c30ec600786a3fc223b1b92e7 RNSVG: 80584470ff1ffc7994923ea135a3e5ad825546b9 @@ -756,6 +758,6 @@ SPEC CHECKSUMS: SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Yoga: 8796b55dba14d7004f980b54bcc9833ee45b28ce -PODFILE CHECKSUM: 281036e04bd4b9e7c2cc03a503b3245d3f1dd0dd +PODFILE CHECKSUM: c28ad505f781a0343ae3059f23cdc273a0cbe64b -COCOAPODS: 1.12.0 +COCOAPODS: 1.15.2 From 043f3df01f9ed4ac889a7f7fc8f652518498138a Mon Sep 17 00:00:00 2001 From: kholood Date: Sun, 8 Sep 2024 17:24:57 +0300 Subject: [PATCH 13/57] fix:update IOS network log unit test --- test/utils/InstabugUtils.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/utils/InstabugUtils.spec.ts b/test/utils/InstabugUtils.spec.ts index becfccc0e9..3ac83be274 100644 --- a/test/utils/InstabugUtils.spec.ts +++ b/test/utils/InstabugUtils.spec.ts @@ -323,7 +323,6 @@ describe('reportNetworkLog', () => { network.startTime, network.duration, network.gqlQueryName, - network.serverErrorMessage, ); }); }); From 8a0c9cc315234a9237256115ff84ef5b48a4210b Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 9 Sep 2024 14:59:17 +0300 Subject: [PATCH 14/57] fix: update session metadata --- src/modules/SessionReplay.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index 139b2d2113..46bf43ff71 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -1,10 +1,19 @@ import { NativeSessionReplay, NativeEvents, emitter } from '../native/NativeSessionReplay'; +import type { NetworkData } from '../modules/NetworkLogger'; + export interface sessionData { appVersion: string; OS: string; device: string; sessionDurationInSeconds: number; + bugsCount: number; + fatalCrashCount: number; + oomCrashCount: number; + networkLogs: Array; + launchType: string; + hasLinkToAppReview: boolean; + launchDuration: number; } /** * Enables or disables Session Replay for your Instabug integration. From 65cd1922a0fc16b5f03dfbac34561475d6a6b94a Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 9 Sep 2024 15:08:27 +0300 Subject: [PATCH 15/57] feat(ios): add setSyncCallback --- .../InstabugSessionReplayTests.m | 33 +++++++++++++++++-- ios/RNInstabug/InstabugSessionReplayBridge.h | 7 ++++ ios/RNInstabug/InstabugSessionReplayBridge.m | 33 ++++++++++++++++++- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m b/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m index a2030df9ae..3312af428a 100644 --- a/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m +++ b/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m @@ -16,8 +16,8 @@ @implementation InstabugSessionReplayTests - (void)setUp { - self.mSessionReplay = OCMClassMock([IBGSessionReplay class]); - self.bridge = [[InstabugSessionReplayBridge alloc] init]; + self.mSessionReplay = OCMClassMock([IBGSessionReplay class]); + self.bridge = [[InstabugSessionReplayBridge alloc] init]; } - (void)testSetEnabled { @@ -67,7 +67,34 @@ - (void)testGetSessionReplayLink { [self.bridge getSessionReplayLink:resolve :reject]; OCMVerify([self.mSessionReplay sessionReplayLink]); [self waitForExpectations:@[expectation] timeout:5.0]; - } +- (void)testSetSyncCallback { + BOOL expectedValue = YES; + + XCTestExpectation *completionExpectation = [self expectationWithDescription:@"Completion block should be called with the expected value"]; + + __block BOOL actualValue = NO; + + OCMExpect([self.mSessionReplay setSyncCallbackWithHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + + void (^completionBlock)(BOOL) = ^(BOOL boolean) { + actualValue = boolean; + [completionExpectation fulfill]; + XCTAssertEqual(actualValue, expectedValue); + }; + + self.bridge.sessionEvaluationCompletion = completionBlock; + + return YES; + }]]); + + [self.bridge setSyncCallback]; + [self.bridge evaluateSync:expectedValue]; + + [self waitForExpectationsWithTimeout:1 handler:nil]; + OCMVerifyAll(self.mSessionReplay); + } + + @end diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.h b/ios/RNInstabug/InstabugSessionReplayBridge.h index 1f247ab26e..68aacecb23 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.h +++ b/ios/RNInstabug/InstabugSessionReplayBridge.h @@ -2,6 +2,7 @@ #import #import #import +#import @interface InstabugSessionReplayBridge : RCTEventEmitter /* @@ -20,6 +21,12 @@ - (void)getSessionReplayLink:(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject; +- (void)setSyncCallback; + +- (void)evaluateSync:(BOOL)result; + +@property (nonatomic, copy) SessionEvaluationCompletion sessionEvaluationCompletion; + @end diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.m b/ios/RNInstabug/InstabugSessionReplayBridge.m index bbaf7ffd6d..2103864545 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.m +++ b/ios/RNInstabug/InstabugSessionReplayBridge.m @@ -18,7 +18,9 @@ + (BOOL)requiresMainQueueSetup } - (NSArray *)supportedEvents { - return @[]; + return @[ + @"IBGSessionReplayOnSyncCallback", + ]; } RCT_EXPORT_MODULE(IBGSessionReplay) @@ -45,6 +47,35 @@ + (BOOL)requiresMainQueueSetup resolve(link); } +RCT_EXPORT_METHOD(setSyncCallback) +{ + [IBGSessionReplay setSyncCallbackWithHandler:^(IBGSessionMetadata * _Nonnull metadataObject, SessionEvaluationCompletion _Nonnull completion) { + [self sendEventWithName:@"IBGSessionReplayOnSyncCallback" + body:@{ @"appVersion":metadataObject.appVersion, + @"OS": metadataObject.os, + @"device": metadataObject.device, + @"sessionDurationInSeconds":@(metadataObject.sessionDuration), + @"hasLinkToAppReview":@(metadataObject.hasLinkToAppReview), + @"launchType":@(metadataObject.launchType), + @"launchDuration":@(metadataObject.launchDuration), + @"bugsCount":@(metadataObject.bugsCount), + @"fatalCrashCount":@(metadataObject.fatalCrashCount), + @"oomCrashCount":@(metadataObject.oomCrashCount), + @"networkLogs":metadataObject.networkLogs + + }]; + + self.sessionEvaluationCompletion = completion;}]; +} + +RCT_EXPORT_METHOD(evaluateSync:(BOOL)result) +{ + if (self.sessionEvaluationCompletion) { + self.sessionEvaluationCompletion(result); + } +} + + @synthesize description; @synthesize hash; From 36ca2adb2a43063f40078a74d2e444ea27f2d278 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 9 Sep 2024 15:21:25 +0300 Subject: [PATCH 16/57] fix: pod.lock file --- examples/default/ios/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index 858e643eaa..51136f4d94 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -760,4 +760,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: c28ad505f781a0343ae3059f23cdc273a0cbe64b -COCOAPODS: 1.15.2 +COCOAPODS: 1.12.0 From 2ff447f78b94c4f63d7ab714f76036b1f10ba1d0 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 9 Sep 2024 15:24:46 +0300 Subject: [PATCH 17/57] fix: update session data type --- src/modules/SessionReplay.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index 139b2d2113..46bf43ff71 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -1,10 +1,19 @@ import { NativeSessionReplay, NativeEvents, emitter } from '../native/NativeSessionReplay'; +import type { NetworkData } from '../modules/NetworkLogger'; + export interface sessionData { appVersion: string; OS: string; device: string; sessionDurationInSeconds: number; + bugsCount: number; + fatalCrashCount: number; + oomCrashCount: number; + networkLogs: Array; + launchType: string; + hasLinkToAppReview: boolean; + launchDuration: number; } /** * Enables or disables Session Replay for your Instabug integration. From 131a79530a8f9332c5bc3bf98a4a81cb89682748 Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 10 Sep 2024 16:21:28 +0300 Subject: [PATCH 18/57] fix: add more session metadata to setSyncCallback --- .../RNInstabugSessionReplayModule.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index bc24c26f2a..3b0cabd4e2 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -8,6 +8,7 @@ import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; import com.instabug.library.OnSessionReplayLinkReady; import com.instabug.library.SessionSyncListener; @@ -15,6 +16,8 @@ import com.instabug.library.sessionreplay.model.SessionMetadata; import com.instabug.reactlibrary.utils.EventEmitterModule; import com.instabug.reactlibrary.utils.MainThreadHandler; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CountDownLatch; import javax.annotation.Nonnull; @@ -95,7 +98,7 @@ public void run() { e.printStackTrace(); } } - }); + }); } @ReactMethod @@ -113,8 +116,25 @@ public void onSessionReplayLinkReady(@Nullable String link) { } }); + } + + public WritableArray getNetworkLogsArray(List networkLogList ){ + List networkLogArrayList = networkLogList; + + WritableArray networkLogs = Arguments.createArray(); + + for (SessionMetadata.NetworkLog log : networkLogArrayList) { + WritableMap networkLog = Arguments.createMap(); + networkLog.putString("url", log.getUrl()); + networkLog.putDouble("duration", log.getDuration()); + networkLog.putInt("statusCode", log.getStatusCode()); + + networkLogs.pushMap(networkLog); + } + return networkLogs; } + private boolean shouldSync = false; private CountDownLatch latch; @ReactMethod @@ -131,6 +151,15 @@ public boolean onSessionReadyToSync(@NonNull SessionMetadata sessionMetadata) { params.putString("OS",sessionMetadata.getOs()); params.putString("device",sessionMetadata.getDevice()); params.putDouble("sessionDurationInSeconds",(double)sessionMetadata.getSessionDurationInSeconds()); + params.putBoolean("hasLinkToAppReview",sessionMetadata.getLinkedToReview()); + params.putDouble("launchType", sessionMetadata.getLaunchType()); + params.putDouble("launchDuration", sessionMetadata.getLaunchDuration()); + params.putArray("networkLogs",getNetworkLogsArray(sessionMetadata.getNetworkLogs())); + +// TODO:Add rest of sessionMetadata +// params.putDouble("bugsCount", ??); +// params.putDouble("fatalCrashCount",??); +// params.putDouble("oomCrashCount",??); sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION,params); From 2b53766fb54ba83edd52d47493d4dc0318c5151d Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 10 Sep 2024 19:19:28 +0300 Subject: [PATCH 19/57] fix: update syncCallback test --- .../reactlibrary/RNInstabugSessionReplayModuleTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java index 43c87d8e45..1af5e6da08 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java @@ -154,7 +154,7 @@ public void testSetSyncCallback() throws Exception { mockSessionReplay.when(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))) .thenAnswer((invocation) -> { SessionSyncListener listener = (SessionSyncListener) invocation.getArguments()[0]; - SessionMetadata metadata = new SessionMetadata("device", "android", "1.0", 20); + SessionMetadata metadata = mock(SessionMetadata.class); actual.set(listener.onSessionReadyToSync(metadata)); return null; }); @@ -165,10 +165,6 @@ public void testSetSyncCallback() throws Exception { }).when(SRModule).sendEvent(eq(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION), any()); WritableMap params = Arguments.createMap(); - params.putString("appVersion","1.0"); - params.putString("OS","android"); - params.putString("device","device"); - params.putDouble("sessionDurationInSeconds",20); SRModule.setSyncCallback(); From 41e6b52a78af496385ddacee9d848e8d1c236eb8 Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 11 Sep 2024 18:09:49 +0300 Subject: [PATCH 20/57] feat: add launchType to session metadata for setSyncCallback --- android/native.gradle | 2 +- .../instabug/reactlibrary/ArgsRegistry.java | 16 ++++++++++++++++ .../RNInstabugSessionReplayModule.java | 4 ++-- examples/default/src/App.tsx | 4 ++++ src/modules/SessionReplay.ts | 18 +++++++++++------- src/native/NativeConstants.ts | 9 ++++++++- src/utils/Enums.ts | 9 +++++++++ 7 files changed, 51 insertions(+), 11 deletions(-) diff --git a/android/native.gradle b/android/native.gradle index 0e86a4edff..93ff054427 100644 --- a/android/native.gradle +++ b/android/native.gradle @@ -1,5 +1,5 @@ project.ext.instabug = [ - version: '13.3.0' + version: '13.3.0.6212131-SNAPSHOT', ] dependencies { diff --git a/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java b/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java index 37f730cbe9..39311ceb41 100644 --- a/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java +++ b/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java @@ -15,6 +15,7 @@ import com.instabug.library.invocation.InstabugInvocationEvent; import com.instabug.library.invocation.util.InstabugFloatingButtonEdge; import com.instabug.library.invocation.util.InstabugVideoRecordingButtonPosition; +import com.instabug.library.sessionreplay.model.SessionMetadata; import com.instabug.library.ui.onboarding.WelcomeMessage; import java.util.ArrayList; @@ -58,6 +59,7 @@ static Map getAll() { putAll(nonFatalExceptionLevel); putAll(locales); putAll(placeholders); + putAll(launchType); }}; } @@ -238,4 +240,18 @@ static Map getAll() { put("team", Key.CHATS_TEAM_STRING_NAME); put("insufficientContentMessage", Key.COMMENT_FIELD_INSUFFICIENT_CONTENT); }}; + + public static ArgsMap launchType = new ArgsMap() {{ + put("cold", SessionMetadata.LaunchType.COLD); + put("hot",SessionMetadata.LaunchType.HOT ); + put("warm",SessionMetadata.LaunchType.WARM ); + }}; + +// Temporary workaround to be removed in future release + public static HashMap launchTypeReversed = new HashMap() {{ + put(SessionMetadata.LaunchType.COLD,"cold"); + put(SessionMetadata.LaunchType.HOT,"hot" ); + put(SessionMetadata.LaunchType.WARM,"warm" ); + }}; + } diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index 3b0cabd4e2..0d5411803b 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -152,10 +152,10 @@ public boolean onSessionReadyToSync(@NonNull SessionMetadata sessionMetadata) { params.putString("device",sessionMetadata.getDevice()); params.putDouble("sessionDurationInSeconds",(double)sessionMetadata.getSessionDurationInSeconds()); params.putBoolean("hasLinkToAppReview",sessionMetadata.getLinkedToReview()); - params.putDouble("launchType", sessionMetadata.getLaunchType()); + params.putString("launchType",ArgsRegistry.launchTypeReversed.get(sessionMetadata.getLaunchType()) ); params.putDouble("launchDuration", sessionMetadata.getLaunchDuration()); params.putArray("networkLogs",getNetworkLogsArray(sessionMetadata.getNetworkLogs())); - + // TODO:Add rest of sessionMetadata // params.putDouble("bugsCount", ??); // params.putDouble("fatalCrashCount",??); diff --git a/examples/default/src/App.tsx b/examples/default/src/App.tsx index 46e05baa42..1052e930a9 100644 --- a/examples/default/src/App.tsx +++ b/examples/default/src/App.tsx @@ -9,6 +9,7 @@ import Instabug, { LogLevel, ReproStepsMode, SessionReplay, + LaunchType, } from 'instabug-reactnative'; import type { sessionData } from 'instabug-reactnative'; import { NativeBaseProvider } from 'native-base'; @@ -23,6 +24,9 @@ const queryClient = new QueryClient(); export const App: React.FC = () => { const shouldSyncSession = (data: sessionData) => { + if (data.launchType === LaunchType.cold) { + return true; + } if (data.sessionDurationInSeconds > 20) { return true; } diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index 46bf43ff71..cf9d5de256 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -1,19 +1,23 @@ import { NativeSessionReplay, NativeEvents, emitter } from '../native/NativeSessionReplay'; - -import type { NetworkData } from '../modules/NetworkLogger'; +import { LaunchType } from '../utils/Enums'; +export interface networkLog { + url: string; + duration: number; + statusCode: number; +} export interface sessionData { appVersion: string; OS: string; device: string; sessionDurationInSeconds: number; - bugsCount: number; - fatalCrashCount: number; - oomCrashCount: number; - networkLogs: Array; - launchType: string; + networkLogs: Array; + launchType: LaunchType; hasLinkToAppReview: boolean; launchDuration: number; + bugsCount?: number; + fatalCrashCount?: number; + oomCrashCount?: number; } /** * Enables or disables Session Replay for your Instabug integration. diff --git a/src/native/NativeConstants.ts b/src/native/NativeConstants.ts index 5317e963ef..271f179b8d 100644 --- a/src/native/NativeConstants.ts +++ b/src/native/NativeConstants.ts @@ -12,7 +12,8 @@ export type NativeConstants = NativeSdkDebugLogsLevel & NativeReproStepsMode & NativeLocale & NativeNonFatalErrorLevel & - NativeStringKey; + NativeStringKey & + NativeLaunchType; interface NativeSdkDebugLogsLevel { sdkDebugLogsLevelVerbose: any; @@ -188,3 +189,9 @@ interface NativeStringKey { welcomeMessageLiveWelcomeStepContent: any; welcomeMessageLiveWelcomeStepTitle: any; } + +interface NativeLaunchType { + hot: any; + cold: any; + warm: any; +} diff --git a/src/utils/Enums.ts b/src/utils/Enums.ts index 57cb54ca15..39577bac89 100644 --- a/src/utils/Enums.ts +++ b/src/utils/Enums.ts @@ -232,3 +232,12 @@ export enum StringKey { welcomeMessageLiveWelcomeStepContent = constants.welcomeMessageLiveWelcomeStepContent, welcomeMessageLiveWelcomeStepTitle = constants.welcomeMessageLiveWelcomeStepTitle, } + +export enum LaunchType { + hot = constants.hot, + cold = constants.cold, + /** + * android only + */ + warm = constants.warm, +} From c6b9173fd7503e615efabb82e4c8c9f33c677d26 Mon Sep 17 00:00:00 2001 From: kholood Date: Thu, 12 Sep 2024 12:17:42 +0300 Subject: [PATCH 21/57] fix: import type --- src/modules/SessionReplay.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index cf9d5de256..bc3fe734ad 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -1,5 +1,5 @@ import { NativeSessionReplay, NativeEvents, emitter } from '../native/NativeSessionReplay'; -import { LaunchType } from '../utils/Enums'; +import type { LaunchType } from '../utils/Enums'; export interface networkLog { url: string; duration: number; From 5e237a0630a138a27b83bef575edfe22e5414914 Mon Sep 17 00:00:00 2001 From: kholood Date: Thu, 5 Sep 2024 10:48:51 +0300 Subject: [PATCH 22/57] fix: enhance test case --- .../RNInstabugSessionReplayModuleTest.java | 63 +++++++++---------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java index 270be36282..43c87d8e45 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java @@ -3,9 +3,11 @@ import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertTrue; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockConstruction; import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -27,6 +29,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.mockito.MockedConstruction; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -138,53 +141,43 @@ public void testSetUserStepsEnabled() { } @Test - public void testSetSyncCallback() throws Exception { - MockedStatic mockArgument = mockStatic(Arguments.class); - RNInstabugSessionReplayModule SRModule = spy(new RNInstabugSessionReplayModule(mock(ReactApplicationContext.class))); + MockedStatic mockArguments = mockStatic(Arguments.class); + MockedConstruction mockCountDownLatch = mockConstruction(CountDownLatch.class); + RNInstabugSessionReplayModule SRModule = spy(new RNInstabugSessionReplayModule(mock(ReactApplicationContext.class))); - AtomicBoolean result = new AtomicBoolean(false); - boolean shouldSync=true; + final boolean shouldSync = true; + final AtomicBoolean actual = new AtomicBoolean(); - when(Arguments.createMap()).thenReturn(new JavaOnlyMap()); + mockArguments.when(Arguments::createMap).thenReturn(new JavaOnlyMap()); - mockSessionReplay.when(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))) - .thenAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocation) { + mockSessionReplay.when(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))) + .thenAnswer((invocation) -> { SessionSyncListener listener = (SessionSyncListener) invocation.getArguments()[0]; SessionMetadata metadata = new SessionMetadata("device", "android", "1.0", 20); - boolean shouldSync=listener.onSessionReadyToSync(metadata); - result.set(shouldSync); + actual.set(listener.onSessionReadyToSync(metadata)); return null; - } - }); + }); - WritableMap params = Arguments.createMap(); - params.putString("appVersion","1.0"); - params.putString("OS","android"); - params.putString("device","device"); - params.putDouble("sessionDurationInSeconds",20); - - Thread thread= new Thread (() ->{ - try { - Thread.sleep(500); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } + doAnswer((invocation) -> { + SRModule.evaluateSync(shouldSync); + return null; + }).when(SRModule).sendEvent(eq(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION), any()); - SRModule.evaluateSync(shouldSync); - }); - - thread.start(); + WritableMap params = Arguments.createMap(); + params.putString("appVersion","1.0"); + params.putString("OS","android"); + params.putString("device","device"); + params.putDouble("sessionDurationInSeconds",20); - SRModule.setSyncCallback(); + SRModule.setSyncCallback(); - assertEquals(shouldSync,result.get()); - verify(SRModule).sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION, params); - mockSessionReplay.verify(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))); + assertEquals(shouldSync, actual.get()); + verify(SRModule).sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION, params); + mockSessionReplay.verify(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))); - mockArgument.close(); + mockArguments.close(); + mockCountDownLatch.close(); } } From 44901df16fed3126f6a73f026f73fa2353d14bdc Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 10 Sep 2024 16:21:28 +0300 Subject: [PATCH 23/57] fix: add more session metadata to setSyncCallback --- .../RNInstabugSessionReplayModule.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index bc24c26f2a..3b0cabd4e2 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -8,6 +8,7 @@ import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; import com.instabug.library.OnSessionReplayLinkReady; import com.instabug.library.SessionSyncListener; @@ -15,6 +16,8 @@ import com.instabug.library.sessionreplay.model.SessionMetadata; import com.instabug.reactlibrary.utils.EventEmitterModule; import com.instabug.reactlibrary.utils.MainThreadHandler; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CountDownLatch; import javax.annotation.Nonnull; @@ -95,7 +98,7 @@ public void run() { e.printStackTrace(); } } - }); + }); } @ReactMethod @@ -113,8 +116,25 @@ public void onSessionReplayLinkReady(@Nullable String link) { } }); + } + + public WritableArray getNetworkLogsArray(List networkLogList ){ + List networkLogArrayList = networkLogList; + + WritableArray networkLogs = Arguments.createArray(); + + for (SessionMetadata.NetworkLog log : networkLogArrayList) { + WritableMap networkLog = Arguments.createMap(); + networkLog.putString("url", log.getUrl()); + networkLog.putDouble("duration", log.getDuration()); + networkLog.putInt("statusCode", log.getStatusCode()); + + networkLogs.pushMap(networkLog); + } + return networkLogs; } + private boolean shouldSync = false; private CountDownLatch latch; @ReactMethod @@ -131,6 +151,15 @@ public boolean onSessionReadyToSync(@NonNull SessionMetadata sessionMetadata) { params.putString("OS",sessionMetadata.getOs()); params.putString("device",sessionMetadata.getDevice()); params.putDouble("sessionDurationInSeconds",(double)sessionMetadata.getSessionDurationInSeconds()); + params.putBoolean("hasLinkToAppReview",sessionMetadata.getLinkedToReview()); + params.putDouble("launchType", sessionMetadata.getLaunchType()); + params.putDouble("launchDuration", sessionMetadata.getLaunchDuration()); + params.putArray("networkLogs",getNetworkLogsArray(sessionMetadata.getNetworkLogs())); + +// TODO:Add rest of sessionMetadata +// params.putDouble("bugsCount", ??); +// params.putDouble("fatalCrashCount",??); +// params.putDouble("oomCrashCount",??); sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION,params); From 4b492dc0fc38a6c2c92df96d9ce0bf80714b8200 Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 10 Sep 2024 19:19:28 +0300 Subject: [PATCH 24/57] fix: update syncCallback test --- .../reactlibrary/RNInstabugSessionReplayModuleTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java index 43c87d8e45..1af5e6da08 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java @@ -154,7 +154,7 @@ public void testSetSyncCallback() throws Exception { mockSessionReplay.when(() -> SessionReplay.setSyncCallback(any(SessionSyncListener.class))) .thenAnswer((invocation) -> { SessionSyncListener listener = (SessionSyncListener) invocation.getArguments()[0]; - SessionMetadata metadata = new SessionMetadata("device", "android", "1.0", 20); + SessionMetadata metadata = mock(SessionMetadata.class); actual.set(listener.onSessionReadyToSync(metadata)); return null; }); @@ -165,10 +165,6 @@ public void testSetSyncCallback() throws Exception { }).when(SRModule).sendEvent(eq(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION), any()); WritableMap params = Arguments.createMap(); - params.putString("appVersion","1.0"); - params.putString("OS","android"); - params.putString("device","device"); - params.putDouble("sessionDurationInSeconds",20); SRModule.setSyncCallback(); From c76ef3bca0ee5d07888d32da5195a0b8b2f3941c Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 11 Sep 2024 18:09:49 +0300 Subject: [PATCH 25/57] feat: add launchType to session metadata for setSyncCallback --- android/native.gradle | 2 +- .../instabug/reactlibrary/ArgsRegistry.java | 16 ++++++++++++++++ .../RNInstabugSessionReplayModule.java | 4 ++-- examples/default/src/App.tsx | 4 ++++ src/modules/SessionReplay.ts | 18 +++++++++++------- src/native/NativeConstants.ts | 9 ++++++++- src/utils/Enums.ts | 9 +++++++++ 7 files changed, 51 insertions(+), 11 deletions(-) diff --git a/android/native.gradle b/android/native.gradle index 0e86a4edff..93ff054427 100644 --- a/android/native.gradle +++ b/android/native.gradle @@ -1,5 +1,5 @@ project.ext.instabug = [ - version: '13.3.0' + version: '13.3.0.6212131-SNAPSHOT', ] dependencies { diff --git a/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java b/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java index 37f730cbe9..39311ceb41 100644 --- a/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java +++ b/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java @@ -15,6 +15,7 @@ import com.instabug.library.invocation.InstabugInvocationEvent; import com.instabug.library.invocation.util.InstabugFloatingButtonEdge; import com.instabug.library.invocation.util.InstabugVideoRecordingButtonPosition; +import com.instabug.library.sessionreplay.model.SessionMetadata; import com.instabug.library.ui.onboarding.WelcomeMessage; import java.util.ArrayList; @@ -58,6 +59,7 @@ static Map getAll() { putAll(nonFatalExceptionLevel); putAll(locales); putAll(placeholders); + putAll(launchType); }}; } @@ -238,4 +240,18 @@ static Map getAll() { put("team", Key.CHATS_TEAM_STRING_NAME); put("insufficientContentMessage", Key.COMMENT_FIELD_INSUFFICIENT_CONTENT); }}; + + public static ArgsMap launchType = new ArgsMap() {{ + put("cold", SessionMetadata.LaunchType.COLD); + put("hot",SessionMetadata.LaunchType.HOT ); + put("warm",SessionMetadata.LaunchType.WARM ); + }}; + +// Temporary workaround to be removed in future release + public static HashMap launchTypeReversed = new HashMap() {{ + put(SessionMetadata.LaunchType.COLD,"cold"); + put(SessionMetadata.LaunchType.HOT,"hot" ); + put(SessionMetadata.LaunchType.WARM,"warm" ); + }}; + } diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index 3b0cabd4e2..0d5411803b 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -152,10 +152,10 @@ public boolean onSessionReadyToSync(@NonNull SessionMetadata sessionMetadata) { params.putString("device",sessionMetadata.getDevice()); params.putDouble("sessionDurationInSeconds",(double)sessionMetadata.getSessionDurationInSeconds()); params.putBoolean("hasLinkToAppReview",sessionMetadata.getLinkedToReview()); - params.putDouble("launchType", sessionMetadata.getLaunchType()); + params.putString("launchType",ArgsRegistry.launchTypeReversed.get(sessionMetadata.getLaunchType()) ); params.putDouble("launchDuration", sessionMetadata.getLaunchDuration()); params.putArray("networkLogs",getNetworkLogsArray(sessionMetadata.getNetworkLogs())); - + // TODO:Add rest of sessionMetadata // params.putDouble("bugsCount", ??); // params.putDouble("fatalCrashCount",??); diff --git a/examples/default/src/App.tsx b/examples/default/src/App.tsx index 46e05baa42..1052e930a9 100644 --- a/examples/default/src/App.tsx +++ b/examples/default/src/App.tsx @@ -9,6 +9,7 @@ import Instabug, { LogLevel, ReproStepsMode, SessionReplay, + LaunchType, } from 'instabug-reactnative'; import type { sessionData } from 'instabug-reactnative'; import { NativeBaseProvider } from 'native-base'; @@ -23,6 +24,9 @@ const queryClient = new QueryClient(); export const App: React.FC = () => { const shouldSyncSession = (data: sessionData) => { + if (data.launchType === LaunchType.cold) { + return true; + } if (data.sessionDurationInSeconds > 20) { return true; } diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index 46bf43ff71..cf9d5de256 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -1,19 +1,23 @@ import { NativeSessionReplay, NativeEvents, emitter } from '../native/NativeSessionReplay'; - -import type { NetworkData } from '../modules/NetworkLogger'; +import { LaunchType } from '../utils/Enums'; +export interface networkLog { + url: string; + duration: number; + statusCode: number; +} export interface sessionData { appVersion: string; OS: string; device: string; sessionDurationInSeconds: number; - bugsCount: number; - fatalCrashCount: number; - oomCrashCount: number; - networkLogs: Array; - launchType: string; + networkLogs: Array; + launchType: LaunchType; hasLinkToAppReview: boolean; launchDuration: number; + bugsCount?: number; + fatalCrashCount?: number; + oomCrashCount?: number; } /** * Enables or disables Session Replay for your Instabug integration. diff --git a/src/native/NativeConstants.ts b/src/native/NativeConstants.ts index 5317e963ef..271f179b8d 100644 --- a/src/native/NativeConstants.ts +++ b/src/native/NativeConstants.ts @@ -12,7 +12,8 @@ export type NativeConstants = NativeSdkDebugLogsLevel & NativeReproStepsMode & NativeLocale & NativeNonFatalErrorLevel & - NativeStringKey; + NativeStringKey & + NativeLaunchType; interface NativeSdkDebugLogsLevel { sdkDebugLogsLevelVerbose: any; @@ -188,3 +189,9 @@ interface NativeStringKey { welcomeMessageLiveWelcomeStepContent: any; welcomeMessageLiveWelcomeStepTitle: any; } + +interface NativeLaunchType { + hot: any; + cold: any; + warm: any; +} diff --git a/src/utils/Enums.ts b/src/utils/Enums.ts index 57cb54ca15..39577bac89 100644 --- a/src/utils/Enums.ts +++ b/src/utils/Enums.ts @@ -232,3 +232,12 @@ export enum StringKey { welcomeMessageLiveWelcomeStepContent = constants.welcomeMessageLiveWelcomeStepContent, welcomeMessageLiveWelcomeStepTitle = constants.welcomeMessageLiveWelcomeStepTitle, } + +export enum LaunchType { + hot = constants.hot, + cold = constants.cold, + /** + * android only + */ + warm = constants.warm, +} From 0c0031c9c35f7fc56760ebd84d90a9cdc9e8af4e Mon Sep 17 00:00:00 2001 From: kholood Date: Thu, 12 Sep 2024 12:24:09 +0300 Subject: [PATCH 26/57] fix: import type --- src/modules/SessionReplay.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index cf9d5de256..bc3fe734ad 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -1,5 +1,5 @@ import { NativeSessionReplay, NativeEvents, emitter } from '../native/NativeSessionReplay'; -import { LaunchType } from '../utils/Enums'; +import type { LaunchType } from '../utils/Enums'; export interface networkLog { url: string; duration: number; From 5c75de11204c9e51dffb3d60967c5e79f034f69f Mon Sep 17 00:00:00 2001 From: kholood Date: Thu, 12 Sep 2024 14:12:54 +0300 Subject: [PATCH 27/57] feat(ios): add launchType metadata to session syncCallback --- ios/RNInstabug/ArgsRegistry.h | 1 + ios/RNInstabug/ArgsRegistry.m | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/ios/RNInstabug/ArgsRegistry.h b/ios/RNInstabug/ArgsRegistry.h index 09c8ac91c5..c7720e38fb 100644 --- a/ios/RNInstabug/ArgsRegistry.h +++ b/ios/RNInstabug/ArgsRegistry.h @@ -22,6 +22,7 @@ typedef NSDictionary ArgsDictionary; + (ArgsDictionary *) reproStates; + (ArgsDictionary *) locales; + (ArgsDictionary *)nonFatalExceptionLevel; ++ (ArgsDictionary *) launchType; + (NSDictionary *) placeholders; diff --git a/ios/RNInstabug/ArgsRegistry.m b/ios/RNInstabug/ArgsRegistry.m index 7099f4976c..777a857070 100644 --- a/ios/RNInstabug/ArgsRegistry.m +++ b/ios/RNInstabug/ArgsRegistry.m @@ -20,6 +20,7 @@ + (NSMutableDictionary *) getAll { [all addEntriesFromDictionary:ArgsRegistry.locales]; [all addEntriesFromDictionary:ArgsRegistry.nonFatalExceptionLevel]; [all addEntriesFromDictionary:ArgsRegistry.placeholders]; + [all addEntriesFromDictionary:ArgsRegistry.launchType]; return all; } @@ -241,4 +242,11 @@ + (ArgsDictionary *)nonFatalExceptionLevel { }; } ++ (ArgsDictionary *) launchType { + return @{ + @"hot": @(LaunchTypeHot), + @"cold": @(LaunchTypeCold), + }; +} + @end From 71b55850ce403576ba0f54c4134df95f74d1f1ad Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 10:13:55 +0300 Subject: [PATCH 28/57] fix: add unknown type to launch types --- ios/RNInstabug/ArgsRegistry.m | 1 + src/native/NativeConstants.ts | 1 + src/utils/Enums.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/ios/RNInstabug/ArgsRegistry.m b/ios/RNInstabug/ArgsRegistry.m index 777a857070..1015be75c9 100644 --- a/ios/RNInstabug/ArgsRegistry.m +++ b/ios/RNInstabug/ArgsRegistry.m @@ -246,6 +246,7 @@ + (ArgsDictionary *) launchType { return @{ @"hot": @(LaunchTypeHot), @"cold": @(LaunchTypeCold), + @"unKnown":@(LaunchTypeUnknown) }; } diff --git a/src/native/NativeConstants.ts b/src/native/NativeConstants.ts index 271f179b8d..984d82009c 100644 --- a/src/native/NativeConstants.ts +++ b/src/native/NativeConstants.ts @@ -194,4 +194,5 @@ interface NativeLaunchType { hot: any; cold: any; warm: any; + unKnown: any; } diff --git a/src/utils/Enums.ts b/src/utils/Enums.ts index 39577bac89..ba401eae40 100644 --- a/src/utils/Enums.ts +++ b/src/utils/Enums.ts @@ -240,4 +240,5 @@ export enum LaunchType { * android only */ warm = constants.warm, + unKnown = constants.unKnown, } From 3b1c37bc95cc287adfe16a908d7de7dad8fc97c7 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 10:36:08 +0300 Subject: [PATCH 29/57] fix: assert evaluate sync returns correct value --- test/modules/SessionReplay.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/modules/SessionReplay.spec.ts b/test/modules/SessionReplay.spec.ts index b42b7fa646..66e672ec59 100644 --- a/test/modules/SessionReplay.spec.ts +++ b/test/modules/SessionReplay.spec.ts @@ -38,7 +38,8 @@ describe('Session Replay Module', () => { }); it('should call the native method setSyncCallback', () => { - const callback = jest.fn().mockReturnValue(true); + const shouldSync = true; + const callback = jest.fn().mockReturnValue(shouldSync); SessionReplay.setSyncCallback(callback); emitter.emit(NativeEvents.SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION); @@ -46,5 +47,6 @@ describe('Session Replay Module', () => { expect(NativeSessionReplay.setSyncCallback).toBeCalledTimes(1); expect(emitter.listenerCount(NativeEvents.SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION)).toBe(1); expect(NativeSessionReplay.evaluateSync).toBeCalledTimes(1); + expect(NativeSessionReplay.evaluateSync).toBeCalledWith(shouldSync); }); }); From 446e9e42d573fdcf2e86ff34bf15fb25d34966ab Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 10:39:33 +0300 Subject: [PATCH 30/57] fix: import type --- src/native/NativeSessionReplay.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/native/NativeSessionReplay.ts b/src/native/NativeSessionReplay.ts index 2d0637e3d1..3139ef44a5 100644 --- a/src/native/NativeSessionReplay.ts +++ b/src/native/NativeSessionReplay.ts @@ -1,4 +1,5 @@ -import { NativeEventEmitter, type NativeModule } from 'react-native'; +import { NativeEventEmitter } from 'react-native'; +import type { NativeModule } from 'react-native'; import { NativeModules } from './NativePackage'; From 8187f60f932340ceda44b17310ddf4002f782bb6 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 10:41:58 +0300 Subject: [PATCH 31/57] fix: cleanup --- src/modules/SessionReplay.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index bc3fe734ad..7930cc45f2 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -124,7 +124,7 @@ export const setSyncCallback = async ( ); } - NativeSessionReplay.evaluateSync(Boolean(handler(payload))); + NativeSessionReplay.evaluateSync(shouldSync); }); return NativeSessionReplay.setSyncCallback(); From d0e972c990e067d2509b6cd77b5cf48076701365 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 10:46:02 +0300 Subject: [PATCH 32/57] chore: update js doc --- src/modules/SessionReplay.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index 7930cc45f2..5f4429d1b0 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -102,12 +102,11 @@ export const getSessionReplayLink = async (): Promise => { * @example * ```ts - * SessionReplay.setSyncCallback((payload)=>{ - * if(payload.device == "Xiaomi M2007J3SY" && - * payload.os == "OS Level 33" && - * payload.appVersion == "3.1.4 (4)" || - * payload.sessionDurationInSeconds > 20 ) - * {return true} + * SessionReplay.setSyncCallback((metadata) => { + * return metadata.device == "Xiaomi M2007J3SY" && + * metadata.os == "OS Level 33" && + * metadata.appVersion == "3.1.4 (4)" || + * metadata.sessionDurationInSeconds > 20; * }); * ``` */ From c700600964ae1086386172821dea33c588e03bfb Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 10:47:11 +0300 Subject: [PATCH 33/57] fix: typo --- src/modules/SessionReplay.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index 5f4429d1b0..c2a6ab0e85 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -96,7 +96,7 @@ export const getSessionReplayLink = async (): Promise => { }; /** - * Set a callback for weather this session should sync + * Set a callback for whether this session should sync * * @param handler From 38bf28f52c1ad5fd81c24ed2584891fa2565a1b9 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 10:51:39 +0300 Subject: [PATCH 34/57] fix: follow interface naming convention --- examples/default/src/App.tsx | 4 ++-- src/index.ts | 4 ++-- src/modules/SessionReplay.ts | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/default/src/App.tsx b/examples/default/src/App.tsx index 1052e930a9..abdab11111 100644 --- a/examples/default/src/App.tsx +++ b/examples/default/src/App.tsx @@ -11,7 +11,7 @@ import Instabug, { SessionReplay, LaunchType, } from 'instabug-reactnative'; -import type { sessionData } from 'instabug-reactnative'; +import type { SessionMetadata } from 'instabug-reactnative'; import { NativeBaseProvider } from 'native-base'; import { RootTabNavigator } from './navigation/RootTab'; @@ -23,7 +23,7 @@ import { QueryClient, QueryClientProvider } from 'react-query'; const queryClient = new QueryClient(); export const App: React.FC = () => { - const shouldSyncSession = (data: sessionData) => { + const shouldSyncSession = (data: SessionMetadata) => { if (data.launchType === LaunchType.cold) { return true; } diff --git a/src/index.ts b/src/index.ts index 3e0358cc29..eeef3555e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ import * as Replies from './modules/Replies'; import type { Survey } from './modules/Surveys'; import * as Surveys from './modules/Surveys'; import * as SessionReplay from './modules/SessionReplay'; -import type { sessionData } from './modules/SessionReplay'; +import type { SessionMetadata } from './modules/SessionReplay'; export * from './utils/Enums'; export { @@ -29,6 +29,6 @@ export { Replies, Surveys, }; -export type { InstabugConfig, Survey, NetworkData, NetworkDataObfuscationHandler, sessionData }; +export type { InstabugConfig, Survey, NetworkData, NetworkDataObfuscationHandler, SessionMetadata }; export default Instabug; diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index c2a6ab0e85..6d143e2df0 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -1,17 +1,17 @@ import { NativeSessionReplay, NativeEvents, emitter } from '../native/NativeSessionReplay'; import type { LaunchType } from '../utils/Enums'; -export interface networkLog { +export interface NetworkLog { url: string; duration: number; statusCode: number; } -export interface sessionData { +export interface SessionMetadata { appVersion: string; OS: string; device: string; sessionDurationInSeconds: number; - networkLogs: Array; + networkLogs: Array; launchType: LaunchType; hasLinkToAppReview: boolean; launchDuration: number; @@ -111,7 +111,7 @@ export const getSessionReplayLink = async (): Promise => { * ``` */ export const setSyncCallback = async ( - handler: (payload: sessionData) => boolean, + handler: (payload: SessionMetadata) => boolean, ): Promise => { emitter.addListener(NativeEvents.SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION, (payload) => { const result = handler(payload); From 8cef372419617f8bd2ae8a36f2c53aa8fc050484 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 10:53:53 +0300 Subject: [PATCH 35/57] fix: update type --- src/modules/SessionReplay.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index 6d143e2df0..ef08e5db58 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -11,7 +11,7 @@ export interface SessionMetadata { OS: string; device: string; sessionDurationInSeconds: number; - networkLogs: Array; + networkLogs: NetworkLog[]; launchType: LaunchType; hasLinkToAppReview: boolean; launchDuration: number; From 40556ec88db7b527a6793762a72cadc0ad33fa47 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 11:18:42 +0300 Subject: [PATCH 36/57] fix: refactor syncCallback --- .../RNInstabugSessionReplayModule.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index 0d5411803b..1dd0131bf0 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -118,12 +118,28 @@ public void onSessionReplayLinkReady(@Nullable String link) { } + public WritableMap getSessionMetadataMap(SessionMetadata sessionMetadata){ + WritableMap params = Arguments.createMap(); + params.putString("appVersion",sessionMetadata.getAppVersion()); + params.putString("OS",sessionMetadata.getOs()); + params.putString("device",sessionMetadata.getDevice()); + params.putDouble("sessionDurationInSeconds",(double)sessionMetadata.getSessionDurationInSeconds()); + params.putBoolean("hasLinkToAppReview",sessionMetadata.getLinkedToReview()); + params.putString("launchType",ArgsRegistry.launchTypeReversed.get(sessionMetadata.getLaunchType()) ); + params.putDouble("launchDuration", sessionMetadata.getLaunchDuration()); + params.putArray("networkLogs",getNetworkLogsArray(sessionMetadata.getNetworkLogs())); + +// TODO:Add rest of sessionMetadata +// params.putDouble("bugsCount", ??); +// params.putDouble("fatalCrashCount",??); +// params.putDouble("oomCrashCount",??); + return params; + } + public WritableArray getNetworkLogsArray(List networkLogList ){ - List networkLogArrayList = networkLogList; - WritableArray networkLogs = Arguments.createArray(); - for (SessionMetadata.NetworkLog log : networkLogArrayList) { + for (SessionMetadata.NetworkLog log : networkLogList) { WritableMap networkLog = Arguments.createMap(); networkLog.putString("url", log.getUrl()); networkLog.putDouble("duration", log.getDuration()); @@ -146,22 +162,8 @@ public void run() { SessionReplay.setSyncCallback(new SessionSyncListener() { @Override public boolean onSessionReadyToSync(@NonNull SessionMetadata sessionMetadata) { - WritableMap params = Arguments.createMap(); - params.putString("appVersion",sessionMetadata.getAppVersion()); - params.putString("OS",sessionMetadata.getOs()); - params.putString("device",sessionMetadata.getDevice()); - params.putDouble("sessionDurationInSeconds",(double)sessionMetadata.getSessionDurationInSeconds()); - params.putBoolean("hasLinkToAppReview",sessionMetadata.getLinkedToReview()); - params.putString("launchType",ArgsRegistry.launchTypeReversed.get(sessionMetadata.getLaunchType()) ); - params.putDouble("launchDuration", sessionMetadata.getLaunchDuration()); - params.putArray("networkLogs",getNetworkLogsArray(sessionMetadata.getNetworkLogs())); - -// TODO:Add rest of sessionMetadata -// params.putDouble("bugsCount", ??); -// params.putDouble("fatalCrashCount",??); -// params.putDouble("oomCrashCount",??); - sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION,params); + sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION,getSessionMetadataMap(sessionMetadata)); latch = new CountDownLatch(1); From bc4f699625875fa53eb5e968c374080eb8b805b4 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 11:20:01 +0300 Subject: [PATCH 37/57] fix: default syncing session to true --- .../instabug/reactlibrary/RNInstabugSessionReplayModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index 1dd0131bf0..b53ca5fb05 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -151,7 +151,7 @@ public WritableArray getNetworkLogsArray(List networ return networkLogs; } - private boolean shouldSync = false; + private boolean shouldSync = true; private CountDownLatch latch; @ReactMethod public void setSyncCallback() { From 6eec19f39370e8d408ac0ddc0fd73283ebf7a6aa Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 11:55:58 +0300 Subject: [PATCH 38/57] fix: convert network logs to readable array --- .../instabug/reactlibrary/RNInstabugSessionReplayModule.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index b53ca5fb05..8e64afe35a 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -8,6 +8,7 @@ import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; import com.instabug.library.OnSessionReplayLinkReady; @@ -136,7 +137,7 @@ public WritableMap getSessionMetadataMap(SessionMetadata sessionMetadata){ return params; } - public WritableArray getNetworkLogsArray(List networkLogList ){ + public ReadableArray getNetworkLogsArray(List networkLogList ){ WritableArray networkLogs = Arguments.createArray(); for (SessionMetadata.NetworkLog log : networkLogList) { From b3c0a31469f72a26af2ef33d5d8525233cafcf22 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 16 Sep 2024 12:04:07 +0300 Subject: [PATCH 39/57] chore: add discriptive comment --- .../src/main/java/com/instabug/reactlibrary/ArgsRegistry.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java b/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java index 39311ceb41..f1a4c1fa94 100644 --- a/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java +++ b/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java @@ -248,6 +248,7 @@ static Map getAll() { }}; // Temporary workaround to be removed in future release +// This is used for mapping native `LaunchType` values into React Native enum values. public static HashMap launchTypeReversed = new HashMap() {{ put(SessionMetadata.LaunchType.COLD,"cold"); put(SessionMetadata.LaunchType.HOT,"hot" ); From e50fbefef821888cceace1c8a75d54c5c988827e Mon Sep 17 00:00:00 2001 From: Ahmed Elrefaey <68241710+a7medev@users.noreply.github.com> Date: Mon, 16 Sep 2024 13:58:32 +0300 Subject: [PATCH 40/57] chore: use readable map for session metadata --- .../instabug/reactlibrary/RNInstabugSessionReplayModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index 8e64afe35a..3050d6bd71 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -119,7 +119,7 @@ public void onSessionReplayLinkReady(@Nullable String link) { } - public WritableMap getSessionMetadataMap(SessionMetadata sessionMetadata){ + public ReadableMap getSessionMetadataMap(SessionMetadata sessionMetadata){ WritableMap params = Arguments.createMap(); params.putString("appVersion",sessionMetadata.getAppVersion()); params.putString("OS",sessionMetadata.getOs()); From d08d84c83c4dd3dab4a55be304005e5b17cb865e Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 18 Sep 2024 12:53:18 +0300 Subject: [PATCH 41/57] fix: setSyncCallback should sync in case of exception --- .../com/instabug/reactlibrary/RNInstabugSessionReplayModule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java index 3050d6bd71..d4973894a8 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java @@ -172,6 +172,7 @@ public boolean onSessionReadyToSync(@NonNull SessionMetadata sessionMetadata) { latch.await(); } catch (InterruptedException e) { e.printStackTrace(); + return true; } return shouldSync; From 6ee32a89d742b2dfe09c46e4211c8d7e8fde6145 Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 18 Sep 2024 13:12:49 +0300 Subject: [PATCH 42/57] fix: move SessionMetadata to models --- src/models/SessionMetadata.ts | 57 +++++++++++++++++++++++++++++++++++ src/modules/SessionReplay.ts | 21 +------------ 2 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 src/models/SessionMetadata.ts diff --git a/src/models/SessionMetadata.ts b/src/models/SessionMetadata.ts new file mode 100644 index 0000000000..f95c1cba52 --- /dev/null +++ b/src/models/SessionMetadata.ts @@ -0,0 +1,57 @@ +import type { LaunchType } from '../utils/Enums'; + +/** + * network log item + */ +export interface NetworkLog { + url: string; + duration: number; + statusCode: number; +} + +export interface SessionMetadata { + /** + * app version of the session + */ + appVersion: string; + /** + * operating system of the session + */ + OS: string; + /** + * mobile device model of the session + */ + device: string; + /** + * session duration in seconds + */ + sessionDurationInSeconds: number; + /** + * list of netwrok requests occurred during the session + */ + networkLogs: NetworkLog[]; + /** + * launch type of the session + */ + launchType: LaunchType; + /** + * is an in-app review occurred in the previous session. + */ + hasLinkToAppReview: boolean; + /** + * app launch duration + */ + launchDuration: number; + /** + * number of bugs in the session + */ + bugsCount?: number; + /** + * number of fetal crashes in the session + */ + fatalCrashCount?: number; + /** + * number of out of memory crashes in the session + */ + oomCrashCount?: number; +} diff --git a/src/modules/SessionReplay.ts b/src/modules/SessionReplay.ts index ef08e5db58..a0abcd3d76 100644 --- a/src/modules/SessionReplay.ts +++ b/src/modules/SessionReplay.ts @@ -1,24 +1,5 @@ import { NativeSessionReplay, NativeEvents, emitter } from '../native/NativeSessionReplay'; -import type { LaunchType } from '../utils/Enums'; -export interface NetworkLog { - url: string; - duration: number; - statusCode: number; -} - -export interface SessionMetadata { - appVersion: string; - OS: string; - device: string; - sessionDurationInSeconds: number; - networkLogs: NetworkLog[]; - launchType: LaunchType; - hasLinkToAppReview: boolean; - launchDuration: number; - bugsCount?: number; - fatalCrashCount?: number; - oomCrashCount?: number; -} +import type { SessionMetadata } from '../models/SessionMetadata'; /** * Enables or disables Session Replay for your Instabug integration. * From 6bf9f32e2e9d0dd9442a4653945f0e3fba32ea88 Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 18 Sep 2024 13:19:07 +0300 Subject: [PATCH 43/57] fix: update SessionMetadata type import --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index eeef3555e1..6e7de02846 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ import * as Replies from './modules/Replies'; import type { Survey } from './modules/Surveys'; import * as Surveys from './modules/Surveys'; import * as SessionReplay from './modules/SessionReplay'; -import type { SessionMetadata } from './modules/SessionReplay'; +import type { SessionMetadata } from './models/SessionMetadata'; export * from './utils/Enums'; export { From df896653a07d5f54392b3c0ff094db1e5bd421be Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 18 Sep 2024 13:33:01 +0300 Subject: [PATCH 44/57] fix: report bug e2e test --- examples/default/e2e/reportBug.e2e.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/default/e2e/reportBug.e2e.ts b/examples/default/e2e/reportBug.e2e.ts index 08757b7884..e4ba1e2f9e 100644 --- a/examples/default/e2e/reportBug.e2e.ts +++ b/examples/default/e2e/reportBug.e2e.ts @@ -14,7 +14,9 @@ it('reports a bug', async () => { await waitFor(floatingButton).toBeVisible().withTimeout(30000); await floatingButton.tap(); - await getElement('reportBugMenuItem').tap(); + const reportBugMenuItemButton = getElement('reportBugMenuItem'); + await waitFor(reportBugMenuItemButton).toBeVisible().withTimeout(30000); + await reportBugMenuItemButton.tap(); await getElement('emailField').typeText(mockData.email); await getElement('commentField').typeText(mockData.bugComment); From 23276be4f9cba491620d63abe131d6203ff3e5fd Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 18 Sep 2024 17:21:31 +0300 Subject: [PATCH 45/57] chore (ios): update snapshot --- examples/default/ios/Podfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/default/ios/Podfile b/examples/default/ios/Podfile index 683b5bda63..131ea74989 100644 --- a/examples/default/ios/Podfile +++ b/examples/default/ios/Podfile @@ -32,7 +32,7 @@ target 'InstabugExample' do target 'InstabugTests' do inherit! :complete pod 'OCMock' - pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-base/13.4.0/Instabug.podspec' + pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec' end post_install do |installer| From 3a58433bb3dd6f8b32a3b82023d977fd50a02eca Mon Sep 17 00:00:00 2001 From: kholood Date: Wed, 18 Sep 2024 17:22:37 +0300 Subject: [PATCH 46/57] chore (ios): refactor callback --- ios/RNInstabug/InstabugSessionReplayBridge.m | 31 ++++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.m b/ios/RNInstabug/InstabugSessionReplayBridge.m index 2103864545..9789a96e5c 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.m +++ b/ios/RNInstabug/InstabugSessionReplayBridge.m @@ -47,23 +47,28 @@ + (BOOL)requiresMainQueueSetup resolve(link); } +- (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject +{ + return @{ + @"appVersion": metadataObject.appVersion, + @"OS": metadataObject.os, + @"device": metadataObject.device, + @"sessionDurationInSeconds": @(metadataObject.sessionDuration), + @"hasLinkToAppReview": @(metadataObject.hasLinkToAppReview), + @"launchType": @(metadataObject.launchType), + @"launchDuration": @(metadataObject.launchDuration), + @"bugsCount": @(metadataObject.bugsCount), + @"fatalCrashCount": @(metadataObject.fatalCrashCount), + @"oomCrashCount": @(metadataObject.oomCrashCount), + @"networkLogs": metadataObject.networkLogs + }; +} + RCT_EXPORT_METHOD(setSyncCallback) { [IBGSessionReplay setSyncCallbackWithHandler:^(IBGSessionMetadata * _Nonnull metadataObject, SessionEvaluationCompletion _Nonnull completion) { [self sendEventWithName:@"IBGSessionReplayOnSyncCallback" - body:@{ @"appVersion":metadataObject.appVersion, - @"OS": metadataObject.os, - @"device": metadataObject.device, - @"sessionDurationInSeconds":@(metadataObject.sessionDuration), - @"hasLinkToAppReview":@(metadataObject.hasLinkToAppReview), - @"launchType":@(metadataObject.launchType), - @"launchDuration":@(metadataObject.launchDuration), - @"bugsCount":@(metadataObject.bugsCount), - @"fatalCrashCount":@(metadataObject.fatalCrashCount), - @"oomCrashCount":@(metadataObject.oomCrashCount), - @"networkLogs":metadataObject.networkLogs - - }]; + body:[self getMetadataObjectMap:metadataObject]]; self.sessionEvaluationCompletion = completion;}]; } From fc3337cc4396fcd145523f9ec4a370abdc722ee0 Mon Sep 17 00:00:00 2001 From: kholood Date: Thu, 19 Sep 2024 11:48:53 +0300 Subject: [PATCH 47/57] fix: return network logs --- ios/RNInstabug/InstabugSessionReplayBridge.m | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.m b/ios/RNInstabug/InstabugSessionReplayBridge.m index 9789a96e5c..d9498a09df 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.m +++ b/ios/RNInstabug/InstabugSessionReplayBridge.m @@ -47,8 +47,17 @@ + (BOOL)requiresMainQueueSetup resolve(link); } -- (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject -{ +- (NSArray *)getNetworkLogsArray:(NSArray*) networkLogs { + NSMutableArray *networkLogsArray = [NSMutableArray array]; + + for (IBGSessionMetadataNetworkLogs* log in networkLogs) { + NSDictionary *nLog = @{@"url": log.url, @"statusCode": @(log.statusCode), @"duration": @(log.duration)}; + [networkLogsArray addObject:nLog]; + } + return [networkLogsArray copy]; +} + +- (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject{ return @{ @"appVersion": metadataObject.appVersion, @"OS": metadataObject.os, @@ -60,21 +69,19 @@ - (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject @"bugsCount": @(metadataObject.bugsCount), @"fatalCrashCount": @(metadataObject.fatalCrashCount), @"oomCrashCount": @(metadataObject.oomCrashCount), - @"networkLogs": metadataObject.networkLogs + @"networkLogs":[self getNetworkLogsArray:metadataObject.networkLogs] }; } -RCT_EXPORT_METHOD(setSyncCallback) -{ +RCT_EXPORT_METHOD(setSyncCallback) { [IBGSessionReplay setSyncCallbackWithHandler:^(IBGSessionMetadata * _Nonnull metadataObject, SessionEvaluationCompletion _Nonnull completion) { [self sendEventWithName:@"IBGSessionReplayOnSyncCallback" - body:[self getMetadataObjectMap:metadataObject]]; + body:[self getMetadataObjectMap:metadataObject]]; self.sessionEvaluationCompletion = completion;}]; } -RCT_EXPORT_METHOD(evaluateSync:(BOOL)result) -{ +RCT_EXPORT_METHOD(evaluateSync:(BOOL)result) { if (self.sessionEvaluationCompletion) { self.sessionEvaluationCompletion(result); } From bae6d687371eed814296db03780823150ff419c1 Mon Sep 17 00:00:00 2001 From: kholood Date: Thu, 19 Sep 2024 11:49:15 +0300 Subject: [PATCH 48/57] chore: update podfile.lock --- examples/default/ios/Podfile.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index 51136f4d94..833bb8fead 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -524,7 +524,7 @@ DEPENDENCIES: - FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) - - Instabug (from `https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-base/13.4.0/Instabug.podspec`) + - Instabug (from `https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec`) - instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`) - libevent (~> 2.1.12) - OCMock @@ -600,7 +600,7 @@ EXTERNAL SOURCES: :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" :tag: hermes-2023-03-20-RNv0.72.0-49794cfc7c81fb8f69fd60c3bbf85a7480cc5a77 Instabug: - :podspec: https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-base/13.4.0/Instabug.podspec + :podspec: https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec instabug-reactnative-ndk: :path: "../node_modules/instabug-reactnative-ndk" RCT-Folly: @@ -706,7 +706,7 @@ SPEC CHECKSUMS: Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac hermes-engine: 10fbd3f62405c41ea07e71973ea61e1878d07322 - Instabug: ba4486333cb9c71b8d31f88d7050084402095ac4 + Instabug: 16e4c013f2ae57ddca4966ea90736e48bbcdd2d5 instabug-reactnative-ndk: 960119a69380cf4cbe47ccd007c453f757927d17 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74 @@ -758,6 +758,6 @@ SPEC CHECKSUMS: SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Yoga: 8796b55dba14d7004f980b54bcc9833ee45b28ce -PODFILE CHECKSUM: c28ad505f781a0343ae3059f23cdc273a0cbe64b +PODFILE CHECKSUM: f16fc6271767fab2dc19a52068caa1ca15e29e62 -COCOAPODS: 1.12.0 +COCOAPODS: 1.15.2 From 8fff79bfaf027f32327cef79f371f174baef22a8 Mon Sep 17 00:00:00 2001 From: kholood Date: Thu, 19 Sep 2024 11:57:15 +0300 Subject: [PATCH 49/57] chore: fix formatting --- ios/RNInstabug/InstabugSessionReplayBridge.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.m b/ios/RNInstabug/InstabugSessionReplayBridge.m index d9498a09df..bf75a9f81c 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.m +++ b/ios/RNInstabug/InstabugSessionReplayBridge.m @@ -47,7 +47,8 @@ + (BOOL)requiresMainQueueSetup resolve(link); } -- (NSArray *)getNetworkLogsArray:(NSArray*) networkLogs { +- (NSArray *)getNetworkLogsArray: + (NSArray*) networkLogs { NSMutableArray *networkLogsArray = [NSMutableArray array]; for (IBGSessionMetadataNetworkLogs* log in networkLogs) { @@ -57,7 +58,7 @@ + (BOOL)requiresMainQueueSetup return [networkLogsArray copy]; } -- (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject{ +- (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject { return @{ @"appVersion": metadataObject.appVersion, @"OS": metadataObject.os, From 9e69dd8b52590db9288794d28e0bfe398a99ba9e Mon Sep 17 00:00:00 2001 From: kholood Date: Thu, 19 Sep 2024 16:40:03 +0300 Subject: [PATCH 50/57] chore: revert Podfile.lock --- examples/default/ios/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index 833bb8fead..ac00d32758 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -760,4 +760,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: f16fc6271767fab2dc19a52068caa1ca15e29e62 -COCOAPODS: 1.15.2 +COCOAPODS: 1.12.2 From 5ea6e352b111a190d60121f7d2ad96655d813614 Mon Sep 17 00:00:00 2001 From: kholood Date: Thu, 19 Sep 2024 16:44:41 +0300 Subject: [PATCH 51/57] chore: fix ci --- examples/default/ios/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index ac00d32758..b90c3a0da2 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -760,4 +760,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: f16fc6271767fab2dc19a52068caa1ca15e29e62 -COCOAPODS: 1.12.2 +COCOAPODS: 1.12.0 From 4729287ffe22b3095d48a70f22951c2ce17a06d2 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 23 Sep 2024 12:42:33 +0300 Subject: [PATCH 52/57] fix: launchType typo --- ios/RNInstabug/ArgsRegistry.m | 2 +- ios/RNInstabug/InstabugSessionReplayBridge.m | 1 + src/native/NativeConstants.ts | 2 +- src/utils/Enums.ts | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ios/RNInstabug/ArgsRegistry.m b/ios/RNInstabug/ArgsRegistry.m index 1015be75c9..707fdc9932 100644 --- a/ios/RNInstabug/ArgsRegistry.m +++ b/ios/RNInstabug/ArgsRegistry.m @@ -246,7 +246,7 @@ + (ArgsDictionary *) launchType { return @{ @"hot": @(LaunchTypeHot), @"cold": @(LaunchTypeCold), - @"unKnown":@(LaunchTypeUnknown) + @"unknown":@(LaunchTypeUnknown) }; } diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.m b/ios/RNInstabug/InstabugSessionReplayBridge.m index bf75a9f81c..f348d28ddc 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.m +++ b/ios/RNInstabug/InstabugSessionReplayBridge.m @@ -85,6 +85,7 @@ - (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject { RCT_EXPORT_METHOD(evaluateSync:(BOOL)result) { if (self.sessionEvaluationCompletion) { self.sessionEvaluationCompletion(result); + self.sessionEvaluationCompletion = nil; } } diff --git a/src/native/NativeConstants.ts b/src/native/NativeConstants.ts index 984d82009c..cec8840055 100644 --- a/src/native/NativeConstants.ts +++ b/src/native/NativeConstants.ts @@ -194,5 +194,5 @@ interface NativeLaunchType { hot: any; cold: any; warm: any; - unKnown: any; + unknown: any; } diff --git a/src/utils/Enums.ts b/src/utils/Enums.ts index 6fcb561e7e..c80b46f54f 100644 --- a/src/utils/Enums.ts +++ b/src/utils/Enums.ts @@ -236,7 +236,7 @@ export enum StringKey { export enum LaunchType { hot = constants.hot, cold = constants.cold, - unKnown = constants.unKnown, + unknown = constants.unknown, /** * android only */ From de5c6cef742b6cef8d58e6de86f940026e210cd8 Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 23 Sep 2024 18:46:43 +0300 Subject: [PATCH 53/57] fix: update class sessionEvaluationCompletion atomicity --- ios/RNInstabug/InstabugSessionReplayBridge.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.h b/ios/RNInstabug/InstabugSessionReplayBridge.h index 68aacecb23..259ea1c146 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.h +++ b/ios/RNInstabug/InstabugSessionReplayBridge.h @@ -25,7 +25,7 @@ - (void)evaluateSync:(BOOL)result; -@property (nonatomic, copy) SessionEvaluationCompletion sessionEvaluationCompletion; +@property (atomic, copy) SessionEvaluationCompletion sessionEvaluationCompletion; @end From 4d9a18654450f99d97e10d63c56b0484b7cf13dd Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 23 Sep 2024 18:47:59 +0300 Subject: [PATCH 54/57] chore: enhance syncCallback formatting --- ios/RNInstabug/InstabugSessionReplayBridge.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.m b/ios/RNInstabug/InstabugSessionReplayBridge.m index f348d28ddc..7021fa8ecc 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.m +++ b/ios/RNInstabug/InstabugSessionReplayBridge.m @@ -76,10 +76,12 @@ - (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject { RCT_EXPORT_METHOD(setSyncCallback) { [IBGSessionReplay setSyncCallbackWithHandler:^(IBGSessionMetadata * _Nonnull metadataObject, SessionEvaluationCompletion _Nonnull completion) { + [self sendEventWithName:@"IBGSessionReplayOnSyncCallback" - body:[self getMetadataObjectMap:metadataObject]]; + body:[self getMetadataObjectMap:metadataObject]]; - self.sessionEvaluationCompletion = completion;}]; + self.sessionEvaluationCompletion = completion; + }]; } RCT_EXPORT_METHOD(evaluateSync:(BOOL)result) { From 6677b17f740f83e176d707a6fbe668d39ff68f1d Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 23 Sep 2024 19:00:18 +0300 Subject: [PATCH 55/57] chore: update evaluateSync formatting --- ios/RNInstabug/InstabugSessionReplayBridge.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.m b/ios/RNInstabug/InstabugSessionReplayBridge.m index 7021fa8ecc..f9bddbdcb2 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.m +++ b/ios/RNInstabug/InstabugSessionReplayBridge.m @@ -85,9 +85,13 @@ - (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject { } RCT_EXPORT_METHOD(evaluateSync:(BOOL)result) { + if (self.sessionEvaluationCompletion) { + self.sessionEvaluationCompletion(result); + self.sessionEvaluationCompletion = nil; + } } From 1afe9d3534df56cd1d35f5ec7bb017c84d6f8a87 Mon Sep 17 00:00:00 2001 From: kholood Date: Thu, 26 Sep 2024 20:09:47 +0300 Subject: [PATCH 56/57] fix: fix test SetSyncCallback --- .../InstabugSessionReplayTests.m | 68 ++++++++++++------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m b/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m index 3312af428a..7ee1871ea9 100644 --- a/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m +++ b/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m @@ -70,30 +70,50 @@ - (void)testGetSessionReplayLink { } - (void)testSetSyncCallback { - BOOL expectedValue = YES; - - XCTestExpectation *completionExpectation = [self expectationWithDescription:@"Completion block should be called with the expected value"]; - - __block BOOL actualValue = NO; - - OCMExpect([self.mSessionReplay setSyncCallbackWithHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - - void (^completionBlock)(BOOL) = ^(BOOL boolean) { - actualValue = boolean; - [completionExpectation fulfill]; - XCTAssertEqual(actualValue, expectedValue); - }; - - self.bridge.sessionEvaluationCompletion = completionBlock; - - return YES; - }]]); - - [self.bridge setSyncCallback]; - [self.bridge evaluateSync:expectedValue]; - - [self waitForExpectationsWithTimeout:1 handler:nil]; - OCMVerifyAll(self.mSessionReplay); + id mockMetadata = OCMClassMock([IBGSessionMetadata class]); + id mockNetworkLog = OCMClassMock([IBGSessionMetadataNetworkLogs class]); + id partialMock = OCMPartialMock(self.bridge); + + XCTestExpectation *completionExpectation = [self expectationWithDescription:@"Completion block should be called with the expected value"]; + + BOOL expectedValue = YES; + __block BOOL actualValue = NO; + + OCMStub([mockNetworkLog url]).andReturn(@"http://example.com"); + OCMStub([mockNetworkLog statusCode]).andReturn(200); + + OCMStub([mockMetadata device]).andReturn(@"ipohne"); + OCMStub([mockMetadata os]).andReturn(@"ios"); + OCMStub([mockMetadata appVersion]).andReturn(@"13.4.1"); + OCMStub([mockMetadata sessionDuration]).andReturn(20); + OCMStub([mockMetadata hasLinkToAppReview]).andReturn(NO); + OCMStub([mockMetadata launchType]).andReturn(LaunchTypeCold); + OCMStub([mockMetadata launchDuration]).andReturn(20); + OCMStub([mockMetadata bugsCount]).andReturn(10); + OCMStub([mockMetadata fatalCrashCount]).andReturn(10); + OCMStub([mockMetadata oomCrashCount]).andReturn(10); + OCMStub([mockMetadata networkLogs]).andReturn(@[mockNetworkLog]); + + SessionEvaluationCompletion sessionEvaluationCompletion = ^(BOOL shouldSync) { + actualValue = shouldSync; + [completionExpectation fulfill]; + }; + + OCMStub([partialMock sendEventWithName:@"IBGSessionReplayOnSyncCallback" body:OCMArg.any]).andDo(^(NSInvocation *invocation) { + [self.bridge evaluateSync:expectedValue]; + }); + + OCMStub([self.mSessionReplay setSyncCallbackWithHandler:[OCMArg checkWithBlock: ^BOOL(void(^handler)(IBGSessionMetadata *metadataObject, SessionEvaluationCompletion completion)) { + handler(mockMetadata, sessionEvaluationCompletion); + return YES; + }]]); + + [self.bridge setSyncCallback]; + [self waitForExpectationsWithTimeout:1 handler:nil]; + + OCMVerify([partialMock sendEventWithName:@"IBGSessionReplayOnSyncCallback" body:OCMArg.any]); + OCMVerifyAll(self.mSessionReplay); + XCTAssertEqual(actualValue, expectedValue); } From 250cb946f16ff553587a984a88d38ec859b915db Mon Sep 17 00:00:00 2001 From: kholood Date: Mon, 30 Sep 2024 13:04:28 +0300 Subject: [PATCH 57/57] fix: update getNetworkLogsArray return value --- ios/RNInstabug/InstabugSessionReplayBridge.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.m b/ios/RNInstabug/InstabugSessionReplayBridge.m index f9bddbdcb2..2c865ecb5f 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.m +++ b/ios/RNInstabug/InstabugSessionReplayBridge.m @@ -55,7 +55,7 @@ + (BOOL)requiresMainQueueSetup NSDictionary *nLog = @{@"url": log.url, @"statusCode": @(log.statusCode), @"duration": @(log.duration)}; [networkLogsArray addObject:nLog]; } - return [networkLogsArray copy]; + return networkLogsArray; } - (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject {