-
Notifications
You must be signed in to change notification settings - Fork 102
feat(android): add session sync callback #1281
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
Changes from 15 commits
77b8993
e6b816f
bad72d6
2b01c9d
61d6e52
849648a
02c621c
0d9c7f1
261aa76
5056f58
2ff447f
131a795
2b53766
41e6b52
c6b9173
3b1c37b
446e9e4
8187f60
d0e972c
c700600
38bf28f
8cef372
40556ec
bc4f699
6eec19f
b3c0a31
e50fbef
d08d84c
6ee32a8
6bf9f32
df89665
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
project.ext.instabug = [ | ||
version: '13.3.0' | ||
version: '13.3.0.6212131-SNAPSHOT', | ||
] | ||
|
||
dependencies { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,43 @@ | ||
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.WritableArray; | ||
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.ArrayList; | ||
import java.util.List; | ||
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() { | ||
|
@@ -79,7 +98,7 @@ public void run() { | |
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
@ReactMethod | ||
|
@@ -97,6 +116,82 @@ public void onSessionReplayLinkReady(@Nullable String link) { | |
} | ||
}); | ||
|
||
} | ||
|
||
public WritableArray getNetworkLogsArray(List<SessionMetadata.NetworkLog> networkLogList ){ | ||
kholood-ea marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
List<SessionMetadata.NetworkLog> networkLogArrayList = networkLogList; | ||
kholood-ea marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
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 | ||
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()); | ||
kholood-ea marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
params.putBoolean("hasLinkToAppReview",sessionMetadata.getLinkedToReview()); | ||
params.putString("launchType",ArgsRegistry.launchTypeReversed.get(sessionMetadata.getLaunchType()) ); | ||
params.putDouble("launchDuration", sessionMetadata.getLaunchDuration()); | ||
params.putArray("networkLogs",getNetworkLogsArray(sessionMetadata.getNetworkLogs())); | ||
kholood-ea marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
// TODO:Add rest of sessionMetadata | ||
kholood-ea marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// params.putDouble("bugsCount", ??); | ||
// params.putDouble("fatalCrashCount",??); | ||
// params.putDouble("oomCrashCount",??); | ||
|
||
sendEvent(Constants.IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION,params); | ||
|
||
latch = new CountDownLatch(1); | ||
|
||
try { | ||
latch.await(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return shouldSync; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's default to returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kholood-ea We need to resolve this one before we merge the PR to avoid unintentional return values from the sync callback. |
||
} | ||
}); | ||
} | ||
catch(Exception e){ | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
}); | ||
} | ||
|
||
@ReactMethod | ||
public void evaluateSync(boolean result) { | ||
shouldSync = result; | ||
|
||
if (latch != null) { | ||
latch.countDown(); | ||
} | ||
} | ||
|
||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has the callback been released in
v13.4.0
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it hasn't been just yet.