Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add get session replay link API #1142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Adds symbol files upload script ([#1137](https://github.com/Instabug/Instabug-React-Native/pull/1137))
- Support enabling NDK crash capturing on Android ([#1132](https://github.com/Instabug/Instabug-React-Native/pull/1132)).
- Add `SessionReplay.getSessionReplayLink` API which retrieves the current session's replay link ([#1142](https://github.com/Instabug/Instabug-React-Native/pull/1142)).
- Support setting the Code Push version after SDK initialization ([#1143](https://github.com/Instabug/Instabug-React-Native/pull/1143)).

## [12.7.1](https://github.com/Instabug/Instabug-React-Native/compare/v12.7.0...v12.7.1) (February 15, 2024)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.instabug.reactlibrary;

import androidx.annotation.Nullable;

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.instabug.library.OnSessionReplayLinkReady;
import com.instabug.library.sessionreplay.SessionReplay;
import com.instabug.reactlibrary.utils.MainThreadHandler;

Expand Down Expand Up @@ -76,4 +81,22 @@ public void run() {
}
});
}

@ReactMethod
public void getSessionReplayLink(Promise promise) {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
SessionReplay.getSessionReplayLink(new OnSessionReplayLinkReady() {
@Override
public void onSessionReplayLinkReady(@Nullable String link) {

promise.resolve(link);
}
});
}
});


}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package com.instabug.reactlibrary;

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.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.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.instabug.library.OnSessionReplayLinkReady;
import com.instabug.library.sessionreplay.SessionReplay;
import com.instabug.reactlibrary.utils.MainThreadHandler;

Expand Down Expand Up @@ -96,6 +104,29 @@ public void testSetInstabugLogsEnabled() {
mockSessionReplay.verifyNoMoreInteractions();
}

@Test
public void testGetSessionReplayLink() {
Promise promise = mock(Promise.class);
String link="instabug link";

mockSessionReplay.when(() -> SessionReplay.getSessionReplayLink(any())).thenAnswer(
invocation -> {
OnSessionReplayLinkReady callback = (OnSessionReplayLinkReady) invocation.getArguments()[0];
callback.onSessionReplayLinkReady(link);
return callback;
});
sessionReplayModule.getSessionReplayLink(promise);


mockSessionReplay.verify(() -> SessionReplay.getSessionReplayLink(any()));
mockSessionReplay.verifyNoMoreInteractions();


verify(promise).resolve(link);


}

@Test
public void testSetUserStepsEnabled() {

Expand Down
17 changes: 17 additions & 0 deletions examples/default/ios/InstabugTests/InstabugSessionReplayTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,22 @@ - (void)testSetUserStepsEnabled {
OCMVerify([self.mSessionReplay setUserStepsEnabled:enabled]);
}

- (void)testGetSessionReplayLink {
NSString *link = @"link";
XCTestExpectation *expectation = [self expectationWithDescription:@"Call completion handler"];

RCTPromiseResolveBlock resolve = ^(NSString *result) {
[expectation fulfill];
XCTAssertEqualObjects(result, link);
};

RCTPromiseRejectBlock reject = ^(NSString *code, NSString *message, NSError *error) {
};
OCMStub([self.mSessionReplay sessionReplayLink]).andReturn(link);
[self.bridge getSessionReplayLink:resolve :reject];
OCMVerify([self.mSessionReplay sessionReplayLink]);
[self waitForExpectations:@[expectation] timeout:5.0];

}

@end
8 changes: 8 additions & 0 deletions examples/default/src/navigation/HomeStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { FlatListScreen } from '../screens/user-steps/FlatListScreen';
import { ComplexViewsScreen } from '../screens/user-steps/ComplexViewsScreen';
import { SectionListScreen } from '../screens/user-steps/SectionListScreen';
import { GesturesScreen } from '../screens/user-steps/GesturesScreen';
import { SessionReplayScreen } from '../screens/SessionReplayScreen';

export type HomeStackParamList = {
Home: undefined;
Expand All @@ -30,6 +31,7 @@ export type HomeStackParamList = {
ComplexViews: undefined;
SectionList: undefined;
Gestures: undefined;
SessionReplay: undefined;
};

const HomeStack = createNativeStackNavigator<HomeStackParamList>();
Expand All @@ -55,6 +57,12 @@ export const HomeStackNavigator: React.FC = () => {
/>
<HomeStack.Screen name="Replies" component={RepliesScreen} />
<HomeStack.Screen name="Surveys" component={SurveysScreen} />
<HomeStack.Screen
name="SessionReplay"
component={SessionReplayScreen}
options={{ title: 'Session Replay' }}
/>

<HomeStack.Screen
name="UserSteps"
component={UserStepsScreen}
Expand Down
1 change: 1 addition & 0 deletions examples/default/src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const HomeScreen: React.FC<NativeStackScreenProps<HomeStackParamList, 'Ho
<ListTile title="Replies" onPress={() => navigation.navigate('Replies')} />
<ListTile title="Surveys" onPress={() => navigation.navigate('Surveys')} />
<ListTile title="User Steps" onPress={() => navigation.navigate('UserSteps')} />
<ListTile title="Session Replay" onPress={() => navigation.navigate('SessionReplay')} />
</Screen>
);
};
30 changes: 30 additions & 0 deletions examples/default/src/screens/SessionReplayScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';

import { SessionReplay } from 'instabug-reactnative';
import { useToast } from 'native-base';

import { ListTile } from '../components/ListTile';
import { Screen } from '../components/Screen';

export const SessionReplayScreen: React.FC = () => {
const toast = useToast();
return (
<Screen>
<ListTile
title="Show Current Session link"
onPress={async () => {
const link = await SessionReplay.getSessionReplayLink();
if (link === null) {
toast.show({
description: 'link not found',
});
} else {
toast.show({
description: link,
});
}
}}
/>
</Screen>
);
};
1 change: 1 addition & 0 deletions ios/RNInstabug/InstabugSessionReplayBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

- (void)setUserStepsEnabled:(BOOL)isEnabled;

- (void)getSessionReplayLink:(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject;

@end

Expand Down
6 changes: 6 additions & 0 deletions ios/RNInstabug/InstabugSessionReplayBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ + (BOOL)requiresMainQueueSetup
IBGSessionReplay.userStepsEnabled = isEnabled;
}

RCT_EXPORT_METHOD(getSessionReplayLink:
(RCTPromiseResolveBlock) resolve :(RCTPromiseRejectBlock)reject) {
NSString *link = IBGSessionReplay.sessionReplayLink;
resolve(link);
}

@synthesize description;

@synthesize hash;
Expand Down
12 changes: 12 additions & 0 deletions src/modules/SessionReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,15 @@ export const setInstabugLogsEnabled = (isEnabled: boolean) => {
export const setUserStepsEnabled = (isEnabled: boolean) => {
NativeSessionReplay.setUserStepsEnabled(isEnabled);
};

/**
* Retrieves current session's replay link.
*
* @example
* ```ts
* SessionReplay.getSessionReplayLink();
* ```
*/
export const getSessionReplayLink = async (): Promise<string> => {
return NativeSessionReplay.getSessionReplayLink();
};
1 change: 1 addition & 0 deletions src/native/NativeSessionReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface SessionReplayNativeModule extends NativeModule {
setNetworkLogsEnabled(isEnabled: boolean): void;
setInstabugLogsEnabled(isEnabled: boolean): void;
setUserStepsEnabled(isEnabled: boolean): void;
getSessionReplayLink(): Promise<string>;
}

export const NativeSessionReplay = NativeModules.IBGSessionReplay;
1 change: 1 addition & 0 deletions test/mocks/mockSessionReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const mockSessionReplay: SessionReplayNativeModule = {
setNetworkLogsEnabled: jest.fn(),
setInstabugLogsEnabled: jest.fn(),
setUserStepsEnabled: jest.fn(),
getSessionReplayLink: jest.fn().mockReturnValue('link'),
};

export default mockSessionReplay;
7 changes: 7 additions & 0 deletions test/modules/SessionReplay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ describe('Session Replay Module', () => {
expect(NativeSessionReplay.setUserStepsEnabled).toBeCalledTimes(1);
expect(NativeSessionReplay.setUserStepsEnabled).toBeCalledWith(true);
});

it('should call the native method getSessionReplayLink', () => {
SessionReplay.getSessionReplayLink();

expect(NativeSessionReplay.getSessionReplayLink).toBeCalledTimes(1);
expect(NativeSessionReplay.getSessionReplayLink).toReturnWith('link');
});
});