This repository has been archived by the owner on Oct 17, 2023. It is now read-only.
forked from Instabug/Instabug-React-Native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1089 lines (995 loc) · 34.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import {
NativeModules,
Platform,
findNodeHandle,
processColor
} from 'react-native';
let { Instabug } = NativeModules;
import IBGEventEmitter from './utils/IBGEventEmitter';
import InstabugUtils from './utils/InstabugUtils';
import InstabugConstants from './utils/InstabugConstants';
import Report from './models/Report';
import BugReporting from './modules/BugReporting';
import Surveys from './modules/Surveys';
import FeatureRequests from './modules/FeatureRequests';
import Chats from './modules/Chats';
import Replies from './modules/Replies';
import CrashReporting from './modules/CrashReporting';
import NetworkLogger from './modules/NetworkLogger';
InstabugUtils.captureJsErrors();
NetworkLogger.setEnabled(true);
var _currentScreen = null;
var _lastScreen = null;
var _isFirstScreen = false;
const firstScreen = "Initial Screen";
/**
* Instabug
* @exports Instabug
*/
const InstabugModule = {
/* istanbul ignore next */
/**
* @deprecated use {@link Instabug.start}
* Starts the SDK.
* This is the main SDK method that does all the magic. This is the only
* method that SHOULD be called.
* Should be called in constructor of the app registery component
* @param {string} token The token that identifies the app, you can find
* it on your dashboard.
* @param {invocationEvent} invocationEvent The event that invokes
* the SDK's UI.
*/
startWithToken(token, invocationEvent) {
this.start(token, invocationEvent);
},
/**
* Starts the SDK.
* This is the main SDK method that does all the magic. This is the only
* method that SHOULD be called.
* Should be called in constructor of the app registery component
* @param {string} token The token that identifies the app, you can find
* it on your dashboard.
* @param {invocationEvent} invocationEvent The event that invokes
* the SDK's UI.
*/
start: function (token, invocationEvent) {
if (Platform.OS === 'ios') {
Instabug.startWithToken(token, invocationEvent);
}
_isFirstScreen = true;
_currentScreen = firstScreen;
setTimeout(function () {
if (_currentScreen == firstScreen) {
Instabug.reportScreenChange(firstScreen);
_currentScreen = null;
}
}, 1000);
},
/**
* Attaches user data to each report being sent.
* Each call to this method overrides the user data to be attached.
* Maximum size of the string is 1,000 characters.
* @param {string} userData A string to be attached to each report, with a
* maximum size of 1,000 characters.
*/
setUserData(userData) {
Instabug.setUserData(userData);
},
/* istanbul ignore next */
/**
* @deprecated use {@link BugReporting.setAutoScreenRecordingEnabled}
* Enable/Disable screen recording
* @param {boolean} autoScreenRecordingEnabled boolean for enable/disable
* screen recording on crash feature
*/
setAutoScreenRecordingEnabled(autoScreenRecordingEnabled) {
Instabug.setAutoScreenRecordingEnabled(autoScreenRecordingEnabled);
},
/* istanbul ignore next */
/**
* @deprecated use {@link BugReporting.setAutoScreenRecordingMaxDuration}
* Sets auto screen recording maximum duration
*
* @param autoScreenRecordingMaxDuration maximum duration of the screen recording video
* in seconds
* The maximum duration is 30 seconds
*/
setAutoScreenRecordingMaxDuration(autoScreenRecordingMaxDuration) {
Instabug.setAutoScreenRecordingMaxDuration(autoScreenRecordingMaxDuration);
},
/**
* Sets whether the SDK is tracking user steps or not.
* Enabling user steps would give you an insight on the scenario a user has
* performed before encountering a bug or a crash. User steps are attached
* with each report being sent.
* @param {boolean} isUserStepsEnabled A boolean to set user steps tracking
* to being enabled or disabled.
*/
setTrackUserSteps(isEnabled) {
if (Platform.OS === 'ios') Instabug.setTrackUserSteps(isEnabled);
},
/**
* Sets whether IBGLog should also print to Xcode's console log or not.
* @param {boolean} printsToConsole A boolean to set whether printing to
* Xcode's console is enabled or not.
*/
setIBGLogPrintsToConsole(printsToConsole) {
if (Platform.OS === 'ios')
Instabug.setIBGLogPrintsToConsole(printsToConsole);
},
/* istanbul ignore next */
/**
* @deprecated use {@link CrashReporting.setEnabled}
* Report un-caught exceptions to Instabug dashboard
* We don't send exceptions from __DEV__, since it's way too noisy!
*/
setCrashReportingEnabled(enableCrashReporter) {
Instabug.setCrashReportingEnabled(enableCrashReporter);
},
/* istanbul ignore next */
/**
* @deprecated use {@link BugReporting.setDidSelectPromptOptionHandler}
* Sets a block of code to be executed when a prompt option is selected.
* @param {function} didSelectPromptOptionHandler - A block of code that
* gets executed when a prompt option is selected.
*/
setDidSelectPromptOptionHandler(didSelectPromptOptionHandler) {
BugReporting.setDidSelectPromptOptionHandler(didSelectPromptOptionHandler);
},
/**
* The session profiler is enabled by default and it attaches to the bug and
* crash reports the following information during the last 60 seconds before the report is sent.
* @param {boolean} sessionProfilerEnabled - A boolean parameter to enable or disable the feature.
*
*/
setSessionProfilerEnabled(sessionProfilerEnabled) {
Instabug.setSessionProfilerEnabled(sessionProfilerEnabled);
},
/**
* This API sets the verbosity level of logs used to debug The SDK. The defualt value in debug
* mode is sdkDebugLogsLevelVerbose and in production is sdkDebugLogsLevelError.
* @param {sdkDebugLogsLevel} sdkDebugLogsLevel - The verbosity level of logs.
*
*/
setSdkDebugLogsLevel(sdkDebugLogsLevel) {
if (Platform.OS === 'ios') {
Instabug.setSdkDebugLogsLevel(sdkDebugLogsLevel);
}
},
/* istanbul ignore next */
/**
* @deprecated use {@link Replies.getUnreadRepliesCount}
* Returns the number of unread messages the user currently has.
* Use this method to get the number of unread messages the user
* has, then possibly notify them about it with your own UI.
* @param {messageCountCallback} messageCountCallback callback with argument
* Notifications count, or -1 in case the SDK has not been initialized.
*/
getUnreadMessagesCount(messageCountCallback) {
Instabug.getUnreadMessagesCount(messageCountCallback);
},
/**
* @deprecated use {@link Replies.setPushNotificationsEnabled}
* Enables/disables the use of push notifications in the SDK.
* Defaults to YES.
* @param {boolean} isPushNotificationEnabled A boolean to indicate whether push
* notifications are enabled or disabled.
*/
setPushNotificationsEnabled(isPushNotificationEnabled) {
Replies.setPushNotificationsEnabled(isPushNotificationEnabled);
},
/* istanbul ignore next */
/**
* @deprecated use {@link BugReporting.setInvocationOptions}
* Sets whether users are required to enter an email address or not when
* sending reports.
* Defaults to YES.
* @param {boolean} isEmailFieldRequired A boolean to indicate whether email
* field is required or not.
* @param {actionTypes} actionTypes An enum that indicates which action
* types will have the isEmailFieldRequired
*/
setEmailFieldRequiredForActions(isEmailFieldRequired, actionTypes) {
Instabug.setEmailFieldRequiredForActions(isEmailFieldRequired, actionTypes);
},
/**
* @deprecated use {@link BugReporting.setFloatingButtonEdge}
* Sets the default edge and offset from the top at which the floating button
* will be shown. Different orientations are already handled.
* Default for `floatingButtonEdge` is `rectEdge.maxX`.
* Default for `floatingButtonOffsetFromTop` is 50
* @param {rectEdge} floatingButtonEdge `maxX` to show on the right,
* or `minX` to show on the left.
* @param {number} offsetFromTop floatingButtonOffsetFromTop Top offset for
* floating button.
*/
setFloatingButtonEdge(floatingButtonEdge, offsetFromTop) {
BugReporting.setFloatingButtonEdge(floatingButtonEdge, offsetFromTop);
},
/**
* Sets the SDK's locale.
* Use to change the SDK's UI to different language.
* Defaults to the device's current locale.
* @param {locale} locale A locale to set the SDK to.
*/
setLocale(locale) {
Instabug.setLocale(locale);
},
/**
* Sets the color theme of the SDK's whole UI.
* the SDK's UI to.
* @param colorTheme
*/
setColorTheme(colorTheme) {
Instabug.setColorTheme(colorTheme);
},
/**
* Sets the primary color of the SDK's UI.
* Sets the color of UI elements indicating interactivity or call to action.
* To use, import processColor and pass to it with argument the color hex
* as argument.
* @param {color} primaryColor A color to set the UI elements of the SDK to.
*/
setPrimaryColor(primaryColor) {
Instabug.setPrimaryColor(processColor(primaryColor));
},
/**
* Appends a set of tags to previously added tags of reported feedback,
* bug or crash.
* @param {string[]} tags An array of tags to append to current tags.
*/
appendTags(tags) {
Instabug.appendTags(tags);
},
/**
* Manually removes all tags of reported feedback, bug or crash.
*/
resetTags() {
Instabug.resetTags();
},
/**
* Gets all tags of reported feedback, bug or crash.
* @param {tagsCallback} tagsCallback callback with argument tags of reported feedback, bug or crash.
*/
getTags(tagsCallback) {
Instabug.getTags(tagsCallback);
},
/* istanbul ignore next */
/**
* @deprecated use {@link Instabug.setString}
* Overrides any of the strings shown in the SDK with custom ones.
* Allows you to customize any of the strings shown to users in the SDK.
* @param {string} string String value to override the default one.
* @param {strings} key Key of string to override.
*/
setStringToKey(string, key) {
this.setString(key, string);
},
/**
* Overrides any of the strings shown in the SDK with custom ones.
* Allows you to customize any of the strings shown to users in the SDK.
* @param {string} string String value to override the default one.
* @param {strings} key Key of string to override.
*/
setString(key, string) {
Instabug.setString(string, key);
},
/**
* @deprecated use {@link BugReporting.setEnabledAttachmentTypes}
* Sets whether attachments in bug reporting and in-app messaging are enabled or not.
* @param {boolean} screenshot A boolean to enable or disable screenshot attachments.
* @param {boolean} extraScreenshot A boolean to enable or disable extra
* screenshot attachments.
* @param {boolean} galleryImage A boolean to enable or disable gallery image
* attachments. In iOS 10+,NSPhotoLibraryUsageDescription should be set in
* info.plist to enable gallery image attachments.
* @param {boolean} screenRecording A boolean to enable or disable screen recording attachments.
*/
setEnabledAttachmentTypes(
screenshot,
extraScreenshot,
galleryImage,
screenRecording
) {
BugReporting.setEnabledAttachmentTypes(
screenshot,
extraScreenshot,
galleryImage,
screenRecording
);
},
/* istanbul ignore next */
/**
* @deprecated use {@link Instabug.identifyUser}
* Sets the default value of the user's email and hides the email field from the reporting UI
* and set the user's name to be included with all reports.
* It also reset the chats on device to that email and removes user attributes,
* user data and completed surveys.
* @param {string} email Email address to be set as the user's email.
* @param {string} name Name of the user to be set.
*/
identifyUserWithEmail(email, name) {
this.identifyUser(email, name);
},
/**
* Sets the default value of the user's email and hides the email field from the reporting UI
* and set the user's name to be included with all reports.
* It also reset the chats on device to that email and removes user attributes,
* user data and completed surveys.
* @param {string} email Email address to be set as the user's email.
* @param {string} name Name of the user to be set.
*/
identifyUser(email, name) {
Instabug.identifyUserWithEmail(email, name);
},
/**
* Sets the default value of the user's email to nil and show email field and remove user name
* from all reports
* It also reset the chats on device and removes user attributes, user data and completed surveys.
*/
logOut() {
Instabug.logOut();
},
/* istanbul ignore next */
/**
* @deprecated use {@link Instabug.logUserEvent}
* Logs a user event that happens through the lifecycle of the application.
* Logged user events are going to be sent with each report, as well as at the end of a session.
* @param {string} name Event name.
*/
logUserEventWithName(name) {
this.logUserEvent(name);
},
/**
* Logs a user event that happens through the lifecycle of the application.
* Logged user events are going to be sent with each report, as well as at the end of a session.
* @param {string} name Event name.
*/
logUserEvent(name) {
Instabug.logUserEventWithName(name);
},
/**
* Appends a log message to Instabug internal log
* <p>
* These logs are then sent along the next uploaded report.
* All log messages are timestamped <br/>
* Logs aren't cleared per single application run.
* If you wish to reset the logs,
* use {@link #clearLogs()} ()}
* </p>
* Note: logs passed to this method are <b>NOT</b> printed to Logcat
*
* @param message the message
*/
logVerbose(message) {
if (!message) return;
Instabug.logVerbose(message);
},
/**
* Appends a log message to Instabug internal log
* <p>
* These logs are then sent along the next uploaded report.
* All log messages are timestamped <br/>
* Logs aren't cleared per single application run.
* If you wish to reset the logs,
* use {@link #clearLogs()} ()}
* </p>
* Note: logs passed to this method are <b>NOT</b> printed to Logcat
*
* @param message the message
*/
logInfo(message) {
if (!message) return;
Instabug.logInfo(message);
},
/**
* Appends a log message to Instabug internal log
* <p>
* These logs are then sent along the next uploaded report.
* All log messages are timestamped <br/>
* Logs aren't cleared per single application run.
* If you wish to reset the logs,
* use {@link #clearLogs()} ()}
* </p>
* Note: logs passed to this method are <b>NOT</b> printed to Logcat
*
* @param message the message
*/
logDebug(message) {
if (!message) return;
Instabug.logDebug(message);
},
/**
* Appends a log message to Instabug internal log
* <p>
* These logs are then sent along the next uploaded report.
* All log messages are timestamped <br/>
* Logs aren't cleared per single application run.
* If you wish to reset the logs,
* use {@link #clearLogs()} ()}
* </p>
* Note: logs passed to this method are <b>NOT</b> printed to Logcat
*
* @param message the message
*/
logError(message) {
if (!message) return;
Instabug.logError(message);
},
/**
* Appends a log message to Instabug internal log
* <p>
* These logs are then sent along the next uploaded report.
* All log messages are timestamped <br/>
* Logs aren't cleared per single application run.
* If you wish to reset the logs,
* use {@link #clearLogs()} ()}
* </p>
* Note: logs passed to this method are <b>NOT</b> printed to Logcat
*
* @param message the message
*/
logWarn(message) {
if (!message) return;
Instabug.logWarn(message);
},
/**
* Clear all Instabug logs, console logs, network logs and user steps.
*/
clearLogs() {
Instabug.clearLogs();
},
/**
* Sets whether user steps tracking is visual, non visual or disabled.
* User Steps tracking is enabled by default if it's available
* in your current plan.
*
* @param {reproStepsMode} reproStepsMode An enum to set user steps tracking
* to be enabled, non visual or disabled.
*/
setReproStepsMode(reproStepsMode) {
Instabug.setReproStepsMode(reproStepsMode);
},
/**
* Sets user attribute to overwrite it's value or create a new one if it doesn't exist.
*
* @param key the attribute
* @param value the value
*/
setUserAttribute(key, value) {
if (!key || typeof key !== 'string' || typeof value !== 'string')
throw new TypeError('Invalid param, Expected String');
Instabug.setUserAttribute(key, value);
},
/**
* Returns the user attribute associated with a given key.
aKey
* @param {string} key The attribute key as string
* @param {function} userAttributeCallback callback with argument as the desired user attribute value
*/
getUserAttribute(key, userAttributeCallback) {
Instabug.getUserAttribute(key, userAttributeCallback);
},
/**
* Removes user attribute if exists.
*
* @param key the attribute key as string
* @see #setUserAttribute(String, String)
*/
removeUserAttribute(key) {
if (!key || typeof key !== 'string')
throw new TypeError('Invalid param, Expected String');
Instabug.removeUserAttribute(key);
},
/**
* @summary Returns all user attributes.
* @param {function} userAttributesCallback callback with argument A new dictionary containing
* all the currently set user attributes, or an empty dictionary if no user attributes have been set.
*/
getAllUserAttributes(userAttributesCallback) {
Instabug.getAllUserAttributes(userAttributesCallback);
},
/**
* Clears all user attributes if exists.
*/
clearAllUserAttributes() {
Instabug.clearAllUserAttributes();
},
/* istanbul ignore next */
/**
* @deprecated use {@link Replies.setInAppNotificationsEnabled}
* Enables/disables showing in-app notifications when the user receives a
* new message.
* @param {boolean} isChatNotificationEnabled A boolean to set whether
* notifications are enabled or disabled.
*/
setChatNotificationEnabled(isChatNotificationEnabled) {
Instabug.setChatNotificationEnabled(isChatNotificationEnabled);
},
/* istanbul ignore next */
/**
* @deprecated use {@link Replies.setOnNewReplyReceivedCallback}
* Sets a block of code that gets executed when a new message is received.
* @param {function} onNewMessageHandler - A callback that gets
* executed when a new message is received.
*/
setOnNewMessageHandler(onNewMessageHandler) {
Replies.setOnNewReplyReceivedHandler(onNewMessageHandler);
},
/* istanbul ignore next */
/**
* @deprecated use {@link BugReporting.setViewHierarchyEnabled}
* @summary Enables/disables inspect view hierarchy when reporting a bug/feedback.
* @param {boolean} viewHierarchyEnabled A boolean to set whether view hierarchy are enabled
* or disabled.
*/
setViewHierarchyEnabled(viewHierarchyEnabled) {
Instabug.setViewHierarchyEnabled(viewHierarchyEnabled);
},
/* istanbul ignore next */
/**
* @deprecated use {@link Surveys.setEnabled}
* @summary Sets whether surveys are enabled or not.
* If you disable surveys on the SDK but still have active surveys on your Instabug dashboard,
* those surveys are still going to be sent to the device, but are not going to be
* shown automatically.
* To manually display any available surveys, call `Instabug.showSurveyIfAvailable()`.
* Defaults to `true`.
* @param {boolean} surveysEnabled A boolean to set whether Instabug Surveys is enabled or disabled.
*/
setSurveysEnabled(surveysEnabled) {
Instabug.setSurveysEnabled(surveysEnabled);
},
/**
* Enable/Disable debug logs from Instabug SDK
* Default state: disabled
*
* @param isDebugEnabled whether debug logs should be printed or not into LogCat
*/
setDebugEnabled(isDebugEnabled) {
if (Platform.OS === 'android') {
Instabug.setDebugEnabled(isDebugEnabled);
}
},
/**
* Enables all Instabug functionality
* It works on android only
*/
enable() {
if (Platform.OS === 'android') {
Instabug.enable();
}
},
/**
* Disables all Instabug functionality
* It works on android only
*/
disable() {
if (Platform.OS === 'android') {
Instabug.disable();
}
},
/* istanbul ignore next */
/**
* @deprecated use {@link Replies.setInAppNotificationSound}
* Set whether new in app notification received will play a small sound notification
* or not (Default is {@code false})
*
* @param shouldPlaySound desired state of conversation sounds
* @since 4.1.0
*/
setEnableInAppNotificationSound(shouldPlaySound) {
if (Platform.OS === 'android') {
Instabug.setEnableInAppNotificationSound(shouldPlaySound);
}
},
/* istanbul ignore next */
/**
* @deprecated use {@link CrashReporting.reportJSException}
* Send handled JS error object
*
* @param errorObject Error object to be sent to Instabug's servers
*/
reportJSException(errorObject) {
CrashReporting.reportJSException(errorObject);
},
/**
* @summary Checks whether app is development/Beta testing OR live
* Note: This API is iOS only
* It returns in the callback false if in development or beta testing on Test Flight, and
* true if app is live on the app store.
* @param {function} runningLiveCallBack callback with argument as return value 'isLive'
*/
isRunningLive(runningLiveCallBack) {
if (Platform.OS === 'ios') {
Instabug.isRunningLive(runningLiveCallBack);
}
},
/**
* Sets the default position at which the Instabug screen recording button will be shown.
* Different orientations are already handled.
* (Default for `position` is `bottomRight`)
*
* @param position is of type IBGPosition `topLeft` to show on the top left of screen,
* or `bottomRight` to show on the bottom right of scrren.
*/
setVideoRecordingFloatingButtonPosition(position) {
Instabug.setVideoRecordingFloatingButtonPosition(position);
},
/* istanbul ignore next */
/**
* @deprecated use {@link Surveys.setShouldShowWelcomeScreen}
* Setting an option for all the surveys to show a welcome screen before
* the user starts taking the survey.
* @param shouldShowWelcomeScreen A boolean for setting whether the
* welcome screen should show.
*
*/
setShouldShowSurveysWelcomeScreen(shouldShowWelcomeScreen) {
Instabug.setShouldShowSurveysWelcomeScreen(shouldShowWelcomeScreen);
},
/**
* Shows the welcome message in a specific mode.
* @param welcomeMessageMode An enum to set the welcome message mode to
* live, or beta.
*
*/
showWelcomeMessage(welcomeMessageMode) {
Instabug.showWelcomeMessageWithMode(welcomeMessageMode);
},
/**
* Sets the welcome message mode to live, beta or disabled.
* @param welcomeMessageMode An enum to set the welcome message mode to
* live, beta or disabled.
*
*/
setWelcomeMessageMode(welcomeMessageMode) {
Instabug.setWelcomeMessageMode(welcomeMessageMode);
},
/**
* Add file to be attached to the bug report.
* @param {string} filePath
* @param {string} fileName
*/
addFileAttachment(filePath, fileName) {
if (Platform.OS === 'android') {
Instabug.setFileAttachment(filePath, fileName);
} else {
Instabug.setFileAttachment(filePath);
}
},
/**
* Hides component from screenshots, screen recordings and view hierarchy.
* @param {Object} viewRef the ref of the component to hide
*/
setPrivateView(viewRef) {
const nativeTag = findNodeHandle(viewRef);
if (Platform.OS === 'ios') {
Instabug.hideView(nativeTag);
} else {
Instabug.hideView([nativeTag]);
}
},
/**
* Shows default Instabug prompt.
*/
show() {
Instabug.show();
},
onReportSubmitHandler(preSendingHandler) {
if (preSendingHandler) {
InstabugUtils.setOnReportHandler(true);
} else {
InstabugUtils.setOnReportHandler(false);
}
// send bug report
IBGEventEmitter.addListener(Instabug, InstabugConstants.PRESENDING_HANDLER, (report) => {
const { tags, consoleLogs, instabugLogs, userAttributes, fileAttachments } = report;
const reportObj = new Report(tags, consoleLogs, instabugLogs, userAttributes, fileAttachments);
preSendingHandler(reportObj);
});
// handled js crash
if (Platform.OS === 'android') {
IBGEventEmitter.addListener(Instabug, InstabugConstants.SEND_HANDLED_CRASH, async jsonObject => {
try {
let report = await Instabug.getReport();
const { tags, consoleLogs, instabugLogs, userAttributes, fileAttachments } = report;
const reportObj = new Report(tags, consoleLogs, instabugLogs, userAttributes, fileAttachments);
preSendingHandler(reportObj);
Instabug.sendHandledJSCrash(JSON.stringify(jsonObject));
} catch (e) {
console.error(e);
}
});
}
if (Platform.OS === 'android') {
IBGEventEmitter.addListener(Instabug, InstabugConstants.SEND_UNHANDLED_CRASH, async (jsonObject) => {
let report = await Instabug.getReport();
const { tags, consoleLogs, instabugLogs, userAttributes, fileAttachments } = report;
const reportObj = new Report(tags, consoleLogs, instabugLogs, userAttributes, fileAttachments);
preSendingHandler(reportObj);
Instabug.sendJSCrash(JSON.stringify(jsonObject));
});
}
Instabug.setPreSendingHandler(preSendingHandler);
},
callPrivateApi(apiName, param) {
Instabug.callPrivateApi(apiName, param);
},
onNavigationStateChange(prevState, currentState, action) {
const currentScreen = InstabugUtils.getActiveRouteName(currentState);
const prevScreen = InstabugUtils.getActiveRouteName(prevState);
if (prevScreen !== currentScreen) {
if (_currentScreen != null && _currentScreen != firstScreen) {
Instabug.reportScreenChange(_currentScreen);
_currentScreen = null;
}
_currentScreen = currentScreen;
setTimeout(function () {
if (_currentScreen == currentScreen) {
Instabug.reportScreenChange(currentScreen);
_currentScreen = null;
}
}, 1000);
}
},
onStateChange(state) {
const currentScreen = InstabugUtils.getFullRoute(state);
if (_currentScreen != null && _currentScreen != firstScreen) {
Instabug.reportScreenChange(_currentScreen);
_currentScreen = null;
}
_currentScreen = currentScreen;
setTimeout(function () {
if (_currentScreen == currentScreen) {
Instabug.reportScreenChange(currentScreen);
_currentScreen = null;
}
}, 1000);
},
reportScreenChange(screenName) {
Instabug.reportScreenChange(screenName);
},
componentDidAppearListener({ componentId, componentName, passProps }) {
if (_isFirstScreen) {
_lastScreen = componentName;
_isFirstScreen = false;
return;
}
if (_lastScreen != componentName) {
Instabug.reportScreenChange(componentName);
_lastScreen = componentName;
}
},
/**
* The event used to invoke the feedback form
* @readonly
* @enum {number}
*/
invocationEvent: {
none: Instabug.invocationEventNone,
shake: Instabug.invocationEventShake,
screenshot: Instabug.invocationEventScreenshot,
twoFingersSwipe: Instabug.invocationEventTwoFingersSwipeLeft,
floatingButton: Instabug.invocationEventFloatingButton
},
/**
* The user steps option.
* @readonly
* @enum {number}
*/
reproStepsMode: {
enabled: Instabug.reproStepsEnabled,
disabled: Instabug.reproStepsDisabled,
enabledWithNoScreenshots: Instabug.reproStepsEnabledWithNoScreenshots
},
/**
* Type of SDK dismiss
* @readonly
* @enum {number}
*/
dismissType: {
submit: Instabug.dismissTypeSubmit,
cancel: Instabug.dismissTypeCancel,
addAttachment: Instabug.dismissTypeAddAttachment
},
/**
* The options used upon invocating the SDK
* @readonly
* @enum {number}
*/
invocationOptions: {
invocationOptionsEmailFieldHidden: Instabug.emailFieldHidden,
invocationOptionsEmailFieldOptional: Instabug.emailFieldOptional,
invocationOptionsCommentFieldRequired: Instabug.commentFieldRequired,
invocationOptionsDisablePostSendingDialog: Instabug.disablePostSendingDialog
},
/**
* Verbosity level of the SDK debug logs. This has nothing to do with IBGLog,
* and only affect the logs used to debug the SDK itself.
* @readonly
* @enum {number}
*/
sdkDebugLogsLevel: {
sdkDebugLogsLevelVerbose: Instabug.sdkDebugLogsLevelVerbose,
sdkDebugLogsLevelDebug: Instabug.sdkDebugLogsLevelDebug,
sdkDebugLogsLevelError: Instabug.sdkDebugLogsLevelError,
sdkDebugLogsLevelNone: Instabug.sdkDebugLogsLevelNone,
},
/**
* The extended bug report mode
* @readonly
* @enum {number}
*/
extendedBugReportMode: {
enabledWithRequiredFields: Instabug.enabledWithRequiredFields,
enabledWithOptionalFields: Instabug.enabledWithOptionalFields,
disabled: Instabug.disabled
},
/**
* The supported locales
* @readonly
* @enum {number}
*/
locale: {
arabic: Instabug.localeArabic,
azerbaijani: Instabug.localeAzerbaijani,
chineseSimplified: Instabug.localeChineseSimplified,
chineseTraditional: Instabug.localeChineseTraditional,
czech: Instabug.localeCzech,
danish: Instabug.localeDanish,
dutch: Instabug.localeDutch,
english: Instabug.localeEnglish,
french: Instabug.localeFrench,
german: Instabug.localeGerman,
italian: Instabug.localeItalian,
japanese: Instabug.localeJapanese,
polish: Instabug.localePolish,
portugueseBrazil: Instabug.localePortugueseBrazil,
russian: Instabug.localeRussian,
spanish: Instabug.localeSpanish,
swedish: Instabug.localeSwedish,
turkish: Instabug.localeTurkish,
korean: Instabug.localeKorean
},
/**
* The color theme of the different UI elements
* @readonly
* @enum {number}
*/
colorTheme: {
light: Instabug.colorThemeLight,
dark: Instabug.colorThemeDark
},
/**
* Rectangle edges
* @readonly
* @enum {number}
*/
floatingButtonEdge: {
left: Instabug.rectMinXEdge,
right: Instabug.rectMaxXEdge
},
/**
* Instabug floating buttons positions.
* @readonly
* @enum {number}
*/
IBGPosition: {
bottomRight: Instabug.bottomRight,
topRight: Instabug.topRight,
bottomLeft: Instabug.bottomLeft,
topLeft: Instabug.topLeft
},
/**
* The welcome message mode.
* @readonly
* @enum {number}
*/
welcomeMessageMode: {
live: Instabug.welcomeMessageModeLive,
beta: Instabug.welcomeMessageModeBeta,
disabled: Instabug.welcomeMessageModeDisabled
},
/**
* Instabug action types.
* @readonly
* @enum {number}
*/
actionTypes: {
allActions: Instabug.allActions,
reportBug: Instabug.reportBugAction,
requestNewFeature: Instabug.requestNewFeature,
addCommentToFeature: Instabug.addCommentToFeature
},
/**
* Instabug strings
* @readonly
* @enum {number}
*/