Skip to content

Commit 5a190d5

Browse files
Merge branch 'dev' into feat/map_custom_app_rating_api
2 parents 33bee16 + ae1f238 commit 5a190d5

File tree

10 files changed

+126
-18
lines changed

10 files changed

+126
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
### Added
66

77
- Adds custom app rating api ([#453](https://github.com/Instabug/Instabug-Flutter/pull/453))
8-
8+
- Add `SessionReplay.getSessionReplayLink` API which retrieves the current session's replay link ([#445](hhttps://github.com/Instabug/Instabug-Flutter/pull/445)).
99

1010
## [12.7.0](https://github.com/Instabug/Instabug-Flutter/compare/v12.5.0...v12.7.0) (February 15, 2024)
1111

android/src/main/java/com/instabug/flutter/modules/SessionReplayApi.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.instabug.flutter.modules;
22

33
import androidx.annotation.NonNull;
4+
import androidx.annotation.Nullable;
45

56
import com.instabug.flutter.generated.SessionReplayPigeon;
7+
import com.instabug.library.OnSessionReplayLinkReady;
68
import com.instabug.library.sessionreplay.SessionReplay;
79

810
import io.flutter.plugin.common.BinaryMessenger;
@@ -33,4 +35,11 @@ public void setInstabugLogsEnabled(@NonNull Boolean isEnabled) {
3335
public void setUserStepsEnabled(@NonNull Boolean isEnabled) {
3436
SessionReplay.setUserStepsEnabled(isEnabled);
3537
}
38+
39+
@Override
40+
public void getSessionReplayLink(@NonNull SessionReplayPigeon.Result<String> result) {
41+
SessionReplay.getSessionReplayLink(result::success);
42+
}
43+
44+
3645
}

android/src/test/java/com/instabug/flutter/SessionReplayApiTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
import static org.mockito.ArgumentMatchers.eq;
55
import static org.mockito.Mockito.mock;
66
import static org.mockito.Mockito.mockStatic;
7+
import static org.mockito.Mockito.timeout;
8+
import static org.mockito.Mockito.verify;
79

810
import com.instabug.flutter.generated.SessionReplayPigeon;
911
import com.instabug.flutter.modules.SessionReplayApi;
1012
import com.instabug.flutter.util.GlobalMocks;
13+
import com.instabug.library.OnSessionReplayLinkReady;
1114
import com.instabug.library.sessionreplay.SessionReplay;
1215

1316
import org.junit.After;
@@ -81,6 +84,28 @@ public void testSetUserStepsEnabled() {
8184

8285
mSessionReplay.verify(() -> SessionReplay.setUserStepsEnabled(true));
8386
}
87+
@Test
88+
public void testGetSessionReplayLink() {
89+
SessionReplayPigeon.Result<String> result = mock(SessionReplayPigeon.Result.class);
90+
String link="instabug link";
91+
92+
mSessionReplay.when(() -> SessionReplay.getSessionReplayLink(any())).thenAnswer(
93+
invocation -> {
94+
OnSessionReplayLinkReady callback = (OnSessionReplayLinkReady) invocation.getArguments()[0];
95+
callback.onSessionReplayLinkReady(link);
96+
return callback;
97+
});
98+
api.getSessionReplayLink(result);
99+
100+
101+
mSessionReplay.verify(() -> SessionReplay.getSessionReplayLink(any()));
102+
mSessionReplay.verifyNoMoreInteractions();
103+
104+
105+
verify(result, timeout(1000)).success(link);
106+
107+
108+
}
84109

85110
}
86111

example/ios/InstabugTests/SessionReplayApiTests.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#import <XCTest/XCTest.h>
2+
#import <instabug_flutter/InstabugFlutterPlugin.h>
3+
#import <instabug_flutter/SessionReplayApi.h>
24
#import "OCMock/OCMock.h"
35
#import "SessionReplayApi.h"
46
#import "Instabug/IBGSessionReplay.h"
@@ -54,4 +56,17 @@ - (void)testSetUserStepsEnabled {
5456
OCMVerify([self.mSessionReplay setUserStepsEnabled:YES]);
5557
}
5658

59+
- (void)testGetSessionReplayLink {
60+
NSString *link = @"link";
61+
id result = ^(NSString * result, FlutterError * error) {
62+
XCTAssertEqualObjects(result, link);
63+
};
64+
65+
OCMStub([self.mSessionReplay sessionReplayLink]).andReturn(link);
66+
[self.api getSessionReplayLinkWithCompletion:result];
67+
OCMVerify([self.mSessionReplay sessionReplayLink]);
68+
69+
}
70+
71+
5772
@end

example/lib/main.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ class _MyHomePageState extends State<MyHomePage> {
170170
Surveys.showSurvey('PMqUZXqarkOR2yGKiENB4w');
171171
}
172172

173+
final _scaffoldKey=GlobalKey<ScaffoldState>();
174+
175+
void getCurrentSessionReplaylink() async {
176+
final result=await SessionReplay.getSessionReplayLink();
177+
if(result==null){
178+
const snackBar = SnackBar(
179+
content: Text('No Link Found'),
180+
);
181+
ScaffoldMessenger.of(_scaffoldKey.currentContext!).showSnackBar(snackBar);
182+
}else{
183+
var snackBar = SnackBar(
184+
content: Text(result),
185+
);
186+
ScaffoldMessenger.of(_scaffoldKey.currentContext!).showSnackBar(snackBar);
187+
}
188+
}
189+
173190
void showFeatureRequests() {
174191
FeatureRequests.show();
175192
}
@@ -204,6 +221,7 @@ class _MyHomePageState extends State<MyHomePage> {
204221
@override
205222
Widget build(BuildContext context) {
206223
return Scaffold(
224+
key: _scaffoldKey,
207225
appBar: AppBar(title: Text(widget.title)),
208226
body: SingleChildScrollView(
209227
physics: ClampingScrollPhysics(),
@@ -362,6 +380,13 @@ class _MyHomePageState extends State<MyHomePage> {
362380
),
363381
child: const Text('Dark'),
364382
),
383+
384+
385+
SectionTitle('Sessions Replay'),
386+
InstabugButton(
387+
onPressed: getCurrentSessionReplaylink,
388+
text: 'Get current session replay link',
389+
),
365390
],
366391
),
367392
],

example/pubspec.lock

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ packages:
3737
dependency: transitive
3838
description:
3939
name: collection
40-
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
40+
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
4141
url: "https://pub.dev"
4242
source: hosted
43-
version: "1.17.2"
43+
version: "1.18.0"
4444
espresso:
4545
dependency: "direct dev"
4646
description:
@@ -112,10 +112,10 @@ packages:
112112
dependency: transitive
113113
description:
114114
name: meta
115-
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
115+
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
116116
url: "https://pub.dev"
117117
source: hosted
118-
version: "1.9.1"
118+
version: "1.10.0"
119119
path:
120120
dependency: transitive
121121
description:
@@ -128,10 +128,10 @@ packages:
128128
dependency: transitive
129129
description:
130130
name: platform
131-
sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76"
131+
sha256: ae68c7bfcd7383af3629daafb32fb4e8681c7154428da4febcff06200585f102
132132
url: "https://pub.dev"
133133
source: hosted
134-
version: "3.1.0"
134+
version: "3.1.2"
135135
process:
136136
dependency: transitive
137137
description:
@@ -157,18 +157,18 @@ packages:
157157
dependency: transitive
158158
description:
159159
name: stack_trace
160-
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
160+
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
161161
url: "https://pub.dev"
162162
source: hosted
163-
version: "1.11.0"
163+
version: "1.11.1"
164164
stream_channel:
165165
dependency: transitive
166166
description:
167167
name: stream_channel
168-
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
168+
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
169169
url: "https://pub.dev"
170170
source: hosted
171-
version: "2.1.1"
171+
version: "2.1.2"
172172
string_scanner:
173173
dependency: transitive
174174
description:
@@ -197,10 +197,10 @@ packages:
197197
dependency: transitive
198198
description:
199199
name: test_api
200-
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
200+
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
201201
url: "https://pub.dev"
202202
source: hosted
203-
version: "0.6.0"
203+
version: "0.6.1"
204204
vector_math:
205205
dependency: transitive
206206
description:
@@ -213,18 +213,18 @@ packages:
213213
dependency: transitive
214214
description:
215215
name: vm_service
216-
sha256: c620a6f783fa22436da68e42db7ebbf18b8c44b9a46ab911f666ff09ffd9153f
216+
sha256: c538be99af830f478718b51630ec1b6bee5e74e52c8a802d328d9e71d35d2583
217217
url: "https://pub.dev"
218218
source: hosted
219-
version: "11.7.1"
219+
version: "11.10.0"
220220
web:
221221
dependency: transitive
222222
description:
223223
name: web
224-
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
224+
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
225225
url: "https://pub.dev"
226226
source: hosted
227-
version: "0.1.4-beta"
227+
version: "0.3.0"
228228
webdriver:
229229
dependency: transitive
230230
description:
@@ -234,5 +234,5 @@ packages:
234234
source: hosted
235235
version: "3.0.2"
236236
sdks:
237-
dart: ">=3.1.0-185.0.dev <4.0.0"
237+
dart: ">=3.2.0-194.0.dev <4.0.0"
238238
flutter: ">=2.10.0"

ios/Classes/Modules/SessionReplayApi.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,11 @@ - (void)setUserStepsEnabledIsEnabled:(nonnull NSNumber *)isEnabled error:(Flutte
2727
IBGSessionReplay.userStepsEnabled = [isEnabled boolValue];
2828
}
2929

30+
- (void)getSessionReplayLinkWithCompletion:(void (^)(NSString *, FlutterError *))completion {
31+
NSString * link= IBGSessionReplay.sessionReplayLink;
32+
completion(link,nil);
33+
34+
}
35+
36+
3037
@end

lib/src/modules/session_replay.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,15 @@ class SessionReplay {
6363
static Future<void> setUserStepsEnabled(bool isEnabled) async {
6464
return _host.setUserStepsEnabled(isEnabled);
6565
}
66+
67+
/// Retrieves current session's replay link.
68+
///
69+
/// Example:
70+
///
71+
/// ```dart
72+
/// await SessionReplay.getSessionReplayLink();
73+
/// ```
74+
static Future<String> getSessionReplayLink() async {
75+
return _host.getSessionReplayLink();
76+
}
6677
}

pigeons/session_replay.api.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ abstract class SessionReplayHostApi {
66
void setNetworkLogsEnabled(bool isEnabled);
77
void setInstabugLogsEnabled(bool isEnabled);
88
void setUserStepsEnabled(bool isEnabled);
9+
@async
10+
String getSessionReplayLink();
11+
12+
913
}

test/session_replay_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void main() {
4747
).called(1);
4848
});
4949

50+
5051
test('[setUserStepsEnabled] should call host method', () async {
5152
const isEnabled = true;
5253
await SessionReplay.setUserStepsEnabled(isEnabled);
@@ -55,4 +56,15 @@ void main() {
5556
mHost.setUserStepsEnabled(isEnabled),
5657
).called(1);
5758
});
59+
60+
test('[getSessionReplayLink] should call host method', () async {
61+
const link = 'link';
62+
when(mHost.getSessionReplayLink()).thenAnswer((_) async => link);
63+
64+
final result= await SessionReplay.getSessionReplayLink();
65+
expect(result, link);
66+
verify(
67+
mHost.getSessionReplayLink(),
68+
).called(1);
69+
});
5870
}

0 commit comments

Comments
 (0)