cuoral-ionic 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build/.transforms/bb54161301273cf9b5b94a21c0fb3f23/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$1.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$2.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$3.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$4.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$5.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$6.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$InitiateCallback.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$UploadCallback.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/desugar_graph.bin +0 -0
- package/android/build/intermediates/compile_library_classes_jar/debug/classes.jar +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$1.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$2.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$3.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$4.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$5.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$6.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$InitiateCallback.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$UploadCallback.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$2.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$3.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$4.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$5.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$6.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$InitiateCallback.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$UploadCallback.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin.class +0 -0
- package/android/build/intermediates/runtime_library_classes_jar/debug/classes.jar +0 -0
- package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/cuoral/ionic/CuoralPlugin.java +205 -5
- package/dist/cuoral.d.ts +15 -1
- package/dist/cuoral.d.ts.map +1 -1
- package/dist/cuoral.js +113 -9
- package/dist/index.esm.js +159 -19
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +159 -19
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +4 -0
- package/dist/intelligence.d.ts.map +1 -1
- package/dist/intelligence.js +19 -0
- package/dist/plugin.d.ts +15 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +23 -10
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -0
- package/ios/Plugin/CuoralPlugin.swift +249 -13
- package/package.json +1 -1
- package/src/cuoral.ts +128 -11
- package/src/intelligence.ts +23 -0
- package/src/plugin.ts +39 -11
- package/src/types.ts +4 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$1.class
CHANGED
|
Binary file
|
package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$2.class
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/android/build.gradle
CHANGED
|
@@ -55,6 +55,7 @@ dependencies {
|
|
|
55
55
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
56
56
|
implementation project(':capacitor-android')
|
|
57
57
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
58
|
+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
|
|
58
59
|
testImplementation "junit:junit:$junitVersion"
|
|
59
60
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
60
61
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
@@ -32,10 +32,20 @@ import java.io.File;
|
|
|
32
32
|
import java.io.IOException;
|
|
33
33
|
import java.io.PrintWriter;
|
|
34
34
|
import java.io.StringWriter;
|
|
35
|
+
import java.nio.file.Files;
|
|
35
36
|
|
|
36
37
|
import org.json.JSONObject;
|
|
37
38
|
import org.json.JSONException;
|
|
38
39
|
|
|
40
|
+
import okhttp3.Call;
|
|
41
|
+
import okhttp3.Callback;
|
|
42
|
+
import okhttp3.MediaType;
|
|
43
|
+
import okhttp3.MultipartBody;
|
|
44
|
+
import okhttp3.OkHttpClient;
|
|
45
|
+
import okhttp3.Request;
|
|
46
|
+
import okhttp3.RequestBody;
|
|
47
|
+
import okhttp3.Response;
|
|
48
|
+
|
|
39
49
|
@CapacitorPlugin(name = "CuoralPlugin", permissions = {
|
|
40
50
|
@Permission(strings = { Manifest.permission.RECORD_AUDIO }, alias = "audio"),
|
|
41
51
|
@Permission(strings = { Manifest.permission.WRITE_EXTERNAL_STORAGE }, alias = "storage")
|
|
@@ -364,6 +374,12 @@ public class CuoralPlugin extends Plugin {
|
|
|
364
374
|
return;
|
|
365
375
|
}
|
|
366
376
|
|
|
377
|
+
// Get upload options
|
|
378
|
+
boolean autoUpload = call.getBoolean("autoUpload", false);
|
|
379
|
+
String sessionId = call.getString("sessionId", "");
|
|
380
|
+
String publicKey = call.getString("publicKey", "");
|
|
381
|
+
String customerId = call.getString("customerId", "");
|
|
382
|
+
|
|
367
383
|
try {
|
|
368
384
|
mediaRecorder.stop();
|
|
369
385
|
mediaRecorder.reset();
|
|
@@ -389,11 +405,42 @@ public class CuoralPlugin extends Plugin {
|
|
|
389
405
|
isRecording = false;
|
|
390
406
|
long duration = (System.currentTimeMillis() - recordingStartTime) / 1000;
|
|
391
407
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
408
|
+
// If autoUpload is enabled, upload the video
|
|
409
|
+
if (autoUpload && !sessionId.isEmpty() && !publicKey.isEmpty()) {
|
|
410
|
+
final String filePath = videoFilePath;
|
|
411
|
+
final long finalDuration = duration;
|
|
412
|
+
|
|
413
|
+
uploadRecording(filePath, sessionId, publicKey, customerId, (int) finalDuration, new UploadCallback() {
|
|
414
|
+
@Override
|
|
415
|
+
public void onSuccess() {
|
|
416
|
+
JSObject ret = new JSObject();
|
|
417
|
+
ret.put("success", true);
|
|
418
|
+
ret.put("filePath", filePath);
|
|
419
|
+
ret.put("duration", finalDuration);
|
|
420
|
+
ret.put("uploaded", true);
|
|
421
|
+
call.resolve(ret);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
@Override
|
|
425
|
+
public void onFailure(String error) {
|
|
426
|
+
JSObject ret = new JSObject();
|
|
427
|
+
ret.put("success", true);
|
|
428
|
+
ret.put("filePath", filePath);
|
|
429
|
+
ret.put("duration", finalDuration);
|
|
430
|
+
ret.put("uploaded", false);
|
|
431
|
+
ret.put("uploadError", error);
|
|
432
|
+
call.resolve(ret);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
} else {
|
|
436
|
+
// No upload, just return file path
|
|
437
|
+
JSObject ret = new JSObject();
|
|
438
|
+
ret.put("success", true);
|
|
439
|
+
ret.put("filePath", videoFilePath);
|
|
440
|
+
ret.put("duration", duration);
|
|
441
|
+
ret.put("uploaded", false);
|
|
442
|
+
call.resolve(ret);
|
|
443
|
+
}
|
|
397
444
|
|
|
398
445
|
// Notify listeners
|
|
399
446
|
JSObject eventData = new JSObject();
|
|
@@ -545,4 +592,157 @@ public class CuoralPlugin extends Plugin {
|
|
|
545
592
|
ret.put("error", message);
|
|
546
593
|
return ret;
|
|
547
594
|
}
|
|
595
|
+
|
|
596
|
+
// Upload callback interface
|
|
597
|
+
private interface UploadCallback {
|
|
598
|
+
void onSuccess();
|
|
599
|
+
void onFailure(String error);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Upload recording to Cuoral backend
|
|
604
|
+
*/
|
|
605
|
+
private void uploadRecording(String filePath, String sessionId, String publicKey,
|
|
606
|
+
String customerId, int duration, UploadCallback callback) {
|
|
607
|
+
File videoFile = new File(filePath);
|
|
608
|
+
if (!videoFile.exists()) {
|
|
609
|
+
callback.onFailure("File not found");
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// Step 1: Initiate recording to get record_id
|
|
614
|
+
initiateRecording(sessionId, customerId, publicKey, new InitiateCallback() {
|
|
615
|
+
@Override
|
|
616
|
+
public void onSuccess(String recordId) {
|
|
617
|
+
// Step 2: Upload video with the record_id
|
|
618
|
+
uploadVideo(videoFile, recordId, publicKey, customerId, duration, callback);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
@Override
|
|
622
|
+
public void onFailure(String error) {
|
|
623
|
+
callback.onFailure("Failed to initiate recording: " + error);
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
private interface InitiateCallback {
|
|
629
|
+
void onSuccess(String recordId);
|
|
630
|
+
void onFailure(String error);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Step 1: Initiate recording session
|
|
635
|
+
*/
|
|
636
|
+
private void initiateRecording(String sessionId, String customerId, String publicKey,
|
|
637
|
+
InitiateCallback callback) {
|
|
638
|
+
OkHttpClient client = new OkHttpClient();
|
|
639
|
+
|
|
640
|
+
try {
|
|
641
|
+
JSONObject json = new JSONObject();
|
|
642
|
+
json.put("session_id", sessionId);
|
|
643
|
+
json.put("customer_id", customerId);
|
|
644
|
+
|
|
645
|
+
RequestBody body = RequestBody.create(
|
|
646
|
+
json.toString(),
|
|
647
|
+
MediaType.parse("application/json")
|
|
648
|
+
);
|
|
649
|
+
|
|
650
|
+
Request request = new Request.Builder()
|
|
651
|
+
.url("https://api.cuoral.com/customer-intelligence/initiate/record")
|
|
652
|
+
.post(body)
|
|
653
|
+
.addHeader("Content-Type", "application/json")
|
|
654
|
+
.addHeader("Accept", "*/*")
|
|
655
|
+
.addHeader("x-org-id", publicKey)
|
|
656
|
+
.build();
|
|
657
|
+
|
|
658
|
+
client.newCall(request).enqueue(new Callback() {
|
|
659
|
+
@Override
|
|
660
|
+
public void onFailure(Call call, IOException e) {
|
|
661
|
+
callback.onFailure(e.getMessage());
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
@Override
|
|
665
|
+
public void onResponse(Call call, Response response) throws IOException {
|
|
666
|
+
if (!response.isSuccessful()) {
|
|
667
|
+
callback.onFailure("Failed with status " + response.code());
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
try {
|
|
672
|
+
String responseBody = response.body().string();
|
|
673
|
+
JSONObject json = new JSONObject(responseBody);
|
|
674
|
+
String status = json.getString("status");
|
|
675
|
+
|
|
676
|
+
if ("success".equals(status)) {
|
|
677
|
+
String recordId = json.getString("record_id");
|
|
678
|
+
callback.onSuccess(recordId);
|
|
679
|
+
} else {
|
|
680
|
+
callback.onFailure("Invalid response format");
|
|
681
|
+
}
|
|
682
|
+
} catch (JSONException e) {
|
|
683
|
+
callback.onFailure("Failed to parse response: " + e.getMessage());
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
} catch (JSONException e) {
|
|
688
|
+
callback.onFailure("Failed to create request: " + e.getMessage());
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Step 2: Upload video to the initiated recording
|
|
694
|
+
*/
|
|
695
|
+
private void uploadVideo(File videoFile, String recordId, String publicKey,
|
|
696
|
+
String customerId, int duration, UploadCallback callback) {
|
|
697
|
+
OkHttpClient client = new OkHttpClient.Builder()
|
|
698
|
+
.connectTimeout(60, java.util.concurrent.TimeUnit.SECONDS)
|
|
699
|
+
.writeTimeout(60, java.util.concurrent.TimeUnit.SECONDS)
|
|
700
|
+
.readTimeout(60, java.util.concurrent.TimeUnit.SECONDS)
|
|
701
|
+
.build();
|
|
702
|
+
|
|
703
|
+
RequestBody requestBody = new MultipartBody.Builder()
|
|
704
|
+
.setType(MultipartBody.FORM)
|
|
705
|
+
.addFormDataPart("record_id", recordId)
|
|
706
|
+
.addFormDataPart("console_error", "[]")
|
|
707
|
+
.addFormDataPart("api_response_log", "[]")
|
|
708
|
+
.addFormDataPart("page_view", "[]")
|
|
709
|
+
.addFormDataPart("record_media", "recording.mp4",
|
|
710
|
+
RequestBody.create(videoFile, MediaType.parse("video/mp4")))
|
|
711
|
+
.build();
|
|
712
|
+
|
|
713
|
+
Request request = new Request.Builder()
|
|
714
|
+
.url("https://api.cuoral.com/customer-intelligence/update/record")
|
|
715
|
+
.post(requestBody)
|
|
716
|
+
.addHeader("Accept", "*/*")
|
|
717
|
+
.build();
|
|
718
|
+
|
|
719
|
+
client.newCall(request).enqueue(new Callback() {
|
|
720
|
+
@Override
|
|
721
|
+
public void onFailure(Call call, IOException e) {
|
|
722
|
+
callback.onFailure(e.getMessage());
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
@Override
|
|
726
|
+
public void onResponse(Call call, Response response) throws IOException {
|
|
727
|
+
if (!response.isSuccessful()) {
|
|
728
|
+
callback.onFailure("Upload failed with status " + response.code());
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
try {
|
|
733
|
+
String responseBody = response.body().string();
|
|
734
|
+
JSONObject json = new JSONObject(responseBody);
|
|
735
|
+
String status = json.getString("status");
|
|
736
|
+
|
|
737
|
+
if ("success".equals(status)) {
|
|
738
|
+
callback.onSuccess();
|
|
739
|
+
} else {
|
|
740
|
+
callback.onFailure("Upload failed");
|
|
741
|
+
}
|
|
742
|
+
} catch (JSONException e) {
|
|
743
|
+
callback.onFailure("Failed to parse response: " + e.getMessage());
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
}
|
|
548
748
|
}
|
package/dist/cuoral.d.ts
CHANGED
|
@@ -40,6 +40,13 @@ export declare class Cuoral {
|
|
|
40
40
|
* Track an error manually
|
|
41
41
|
*/
|
|
42
42
|
trackError(message: string, stackTrace?: string, metadata?: any): void;
|
|
43
|
+
/**
|
|
44
|
+
* Update user profile for the current session
|
|
45
|
+
* Call this after user logs in to update the intelligence session with their profile
|
|
46
|
+
* @param email - User's email address
|
|
47
|
+
* @param name - User's full name
|
|
48
|
+
*/
|
|
49
|
+
updateUserProfile(email: string, name: string): Promise<boolean>;
|
|
43
50
|
/**
|
|
44
51
|
* Start native screen recording programmatically
|
|
45
52
|
* @returns Promise<boolean> - true if recording started successfully
|
|
@@ -47,11 +54,13 @@ export declare class Cuoral {
|
|
|
47
54
|
startRecording(): Promise<boolean>;
|
|
48
55
|
/**
|
|
49
56
|
* Stop native screen recording programmatically
|
|
50
|
-
*
|
|
57
|
+
* Recording will be automatically uploaded to the portal
|
|
58
|
+
* @returns Promise<{filePath?: string; duration?: number; uploaded?: boolean} | null> - Recording result or null if failed
|
|
51
59
|
*/
|
|
52
60
|
stopRecording(): Promise<{
|
|
53
61
|
filePath?: string;
|
|
54
62
|
duration?: number;
|
|
63
|
+
uploaded?: boolean;
|
|
55
64
|
} | null>;
|
|
56
65
|
/**
|
|
57
66
|
* Open the widget modal
|
|
@@ -73,6 +82,11 @@ export declare class Cuoral {
|
|
|
73
82
|
* Clear and end the current session (call before logout)
|
|
74
83
|
*/
|
|
75
84
|
clearSession(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Setup localStorage listener for session changes
|
|
87
|
+
* Widget updates localStorage when creating new session, SDK detects and syncs
|
|
88
|
+
*/
|
|
89
|
+
private setupStorageListener;
|
|
76
90
|
/**
|
|
77
91
|
* Clean up resources
|
|
78
92
|
*/
|
package/dist/cuoral.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cuoral.d.ts","sourceRoot":"","sources":["../src/cuoral.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAeD;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,KAAK,CAAC,CAAc;IAC5B,OAAO,CAAC,YAAY,CAAC,CAAqB;IAC1C,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAAuC;IACpF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAwB;gBAElD,OAAO,EAAE,aAAa;
|
|
1
|
+
{"version":3,"file":"cuoral.d.ts","sourceRoot":"","sources":["../src/cuoral.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAeD;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,KAAK,CAAC,CAAc;IAC5B,OAAO,CAAC,YAAY,CAAC,CAAqB;IAC1C,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAAuC;IACpF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAwB;gBAElD,OAAO,EAAE,aAAa;IAiDlC;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAyBxC;;OAEG;YACW,sBAAsB;IA2CpC;;OAEG;YACW,yBAAyB;IAoCvC;;OAEG;IACI,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI;IAM1D;;OAEG;IACI,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI;IAM7E;;;;;OAKG;IACU,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA0C7E;;;OAGG;IACU,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAS/C;;;;OAIG;IACU,aAAa,IAAI,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,IAAI,CAAC;IAiBxG;;OAEG;IACI,SAAS,IAAI,IAAI;IASxB;;OAEG;IACI,UAAU,IAAI,IAAI;IAMzB;;OAEG;IACI,WAAW,IAAI,OAAO;IAI7B;;OAEG;IACI,YAAY,IAAI,MAAM;IAuB7B;;OAEG;IACU,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IA6C1C;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAsB5B;;OAEG;IACI,OAAO,IAAI,IAAI;IActB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAa5B;;OAEG;YACW,eAAe;IAkC7B;;OAEG;YACW,UAAU;IAmBxB;;OAEG;IACH,OAAO,CAAC,oBAAoB;CAyF7B"}
|
package/dist/cuoral.js
CHANGED
|
@@ -25,6 +25,11 @@ export class Cuoral {
|
|
|
25
25
|
key: options.publicKey,
|
|
26
26
|
_t: Date.now().toString(),
|
|
27
27
|
});
|
|
28
|
+
// Add session_id if available (for widget to use existing session)
|
|
29
|
+
const existingSessionId = localStorage.getItem('__x_loadID');
|
|
30
|
+
if (existingSessionId) {
|
|
31
|
+
params.set('cuoral_mobile_session_id', existingSessionId);
|
|
32
|
+
}
|
|
28
33
|
if (options.email)
|
|
29
34
|
params.set('email', options.email);
|
|
30
35
|
if (options.firstName)
|
|
@@ -49,18 +54,23 @@ export class Cuoral {
|
|
|
49
54
|
* Initialize Cuoral
|
|
50
55
|
*/
|
|
51
56
|
async initialize() {
|
|
57
|
+
// Fetch session configuration and initialize intelligence if enabled by backend
|
|
58
|
+
await this.initializeIntelligence();
|
|
59
|
+
console.log('[Cuoral] Initialize - Session ID:', localStorage.getItem('__x_loadID'));
|
|
60
|
+
// Setup localStorage listener to detect when widget changes session
|
|
61
|
+
this.setupStorageListener();
|
|
52
62
|
this.bridge.initialize();
|
|
53
63
|
// Recreate modal if it was destroyed (e.g., after clearSession)
|
|
54
64
|
if (this.options.useModal && !this.modal) {
|
|
55
65
|
const widgetUrl = this.getWidgetUrl();
|
|
56
66
|
this.modal = new CuoralModal(widgetUrl, this.options.showFloatingButton);
|
|
57
67
|
}
|
|
58
|
-
//
|
|
68
|
+
// Update modal URL with session ID
|
|
59
69
|
if (this.modal) {
|
|
70
|
+
const widgetUrl = this.getWidgetUrl();
|
|
71
|
+
this.modal.updateWidgetUrl(widgetUrl);
|
|
60
72
|
this.modal.initialize();
|
|
61
73
|
}
|
|
62
|
-
// Fetch session configuration and initialize intelligence if enabled by backend
|
|
63
|
-
await this.initializeIntelligence();
|
|
64
74
|
}
|
|
65
75
|
/**
|
|
66
76
|
* Initialize intelligence based on backend configuration
|
|
@@ -92,9 +102,13 @@ export class Cuoral {
|
|
|
92
102
|
}
|
|
93
103
|
// Only initialize intelligence if customer_intelligence is enabled in backend
|
|
94
104
|
if (config && config.customer_intelligence === true) {
|
|
105
|
+
console.log('[Cuoral] Initializing intelligence with session:', sessionId);
|
|
95
106
|
this.intelligence = new CuoralIntelligence(sessionId);
|
|
96
107
|
this.intelligence.init();
|
|
97
108
|
}
|
|
109
|
+
else {
|
|
110
|
+
console.log('[Cuoral] Intelligence not enabled or no config for session:', sessionId);
|
|
111
|
+
}
|
|
98
112
|
}
|
|
99
113
|
catch (error) {
|
|
100
114
|
console.warn('[Cuoral] Failed to initialize intelligence:', error);
|
|
@@ -151,6 +165,48 @@ export class Cuoral {
|
|
|
151
165
|
this.intelligence.trackError(message, stackTrace, metadata);
|
|
152
166
|
}
|
|
153
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Update user profile for the current session
|
|
170
|
+
* Call this after user logs in to update the intelligence session with their profile
|
|
171
|
+
* @param email - User's email address
|
|
172
|
+
* @param name - User's full name
|
|
173
|
+
*/
|
|
174
|
+
async updateUserProfile(email, name) {
|
|
175
|
+
try {
|
|
176
|
+
const sessionId = localStorage.getItem('__x_loadID');
|
|
177
|
+
if (!sessionId) {
|
|
178
|
+
console.warn('[Cuoral] No session ID found, cannot update profile');
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
console.log('[Cuoral] Updating user profile for session:', sessionId);
|
|
182
|
+
const response = await fetch('https://api.cuoral.com/conversation/set-profile', {
|
|
183
|
+
method: 'POST',
|
|
184
|
+
headers: { 'Content-Type': 'application/json' },
|
|
185
|
+
body: JSON.stringify({
|
|
186
|
+
session_id: sessionId,
|
|
187
|
+
email: email,
|
|
188
|
+
name: name,
|
|
189
|
+
}),
|
|
190
|
+
});
|
|
191
|
+
if (!response.ok) {
|
|
192
|
+
console.error('[Cuoral] Failed to update profile:', response.statusText);
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
console.log('[Cuoral] ✓ User profile updated successfully for session:', sessionId);
|
|
196
|
+
// Store user info locally
|
|
197
|
+
this.options.email = email;
|
|
198
|
+
const nameParts = name.split(' ');
|
|
199
|
+
if (nameParts.length > 0) {
|
|
200
|
+
this.options.firstName = nameParts[0];
|
|
201
|
+
this.options.lastName = nameParts.slice(1).join(' ');
|
|
202
|
+
}
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
console.error('[Cuoral] Error updating user profile:', error);
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
154
210
|
/**
|
|
155
211
|
* Start native screen recording programmatically
|
|
156
212
|
* @returns Promise<boolean> - true if recording started successfully
|
|
@@ -166,11 +222,19 @@ export class Cuoral {
|
|
|
166
222
|
}
|
|
167
223
|
/**
|
|
168
224
|
* Stop native screen recording programmatically
|
|
169
|
-
*
|
|
225
|
+
* Recording will be automatically uploaded to the portal
|
|
226
|
+
* @returns Promise<{filePath?: string; duration?: number; uploaded?: boolean} | null> - Recording result or null if failed
|
|
170
227
|
*/
|
|
171
228
|
async stopRecording() {
|
|
172
229
|
try {
|
|
173
|
-
|
|
230
|
+
const sessionId = localStorage.getItem('__x_loadID');
|
|
231
|
+
const customerId = localStorage.getItem('cuoralCustomerId');
|
|
232
|
+
return await this.recorder.stopRecording({
|
|
233
|
+
autoUpload: true,
|
|
234
|
+
sessionId: sessionId || undefined,
|
|
235
|
+
publicKey: this.options.publicKey,
|
|
236
|
+
customerId: customerId || undefined,
|
|
237
|
+
});
|
|
174
238
|
}
|
|
175
239
|
catch (error) {
|
|
176
240
|
console.error('[Cuoral] Failed to stop recording:', error);
|
|
@@ -216,7 +280,7 @@ export class Cuoral {
|
|
|
216
280
|
// Add session_id if available
|
|
217
281
|
const sessionId = localStorage.getItem('__x_loadID');
|
|
218
282
|
if (sessionId) {
|
|
219
|
-
params.set('
|
|
283
|
+
params.set('cuoral_mobile_session_id', sessionId);
|
|
220
284
|
}
|
|
221
285
|
if (this.options.email)
|
|
222
286
|
params.set('email', this.options.email);
|
|
@@ -270,6 +334,28 @@ export class Cuoral {
|
|
|
270
334
|
}
|
|
271
335
|
}
|
|
272
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Setup localStorage listener for session changes
|
|
339
|
+
* Widget updates localStorage when creating new session, SDK detects and syncs
|
|
340
|
+
*/
|
|
341
|
+
setupStorageListener() {
|
|
342
|
+
// Poll localStorage every 2 seconds to detect session changes
|
|
343
|
+
// (storage event doesn't fire for same-window changes)
|
|
344
|
+
let lastKnownSession = localStorage.getItem('__x_loadID');
|
|
345
|
+
setInterval(() => {
|
|
346
|
+
const currentSession = localStorage.getItem('__x_loadID');
|
|
347
|
+
if (currentSession && currentSession !== lastKnownSession) {
|
|
348
|
+
console.log('[Cuoral] 🔄 Session changed in localStorage');
|
|
349
|
+
console.log('[Cuoral] Old session:', lastKnownSession);
|
|
350
|
+
console.log('[Cuoral] New session:', currentSession);
|
|
351
|
+
lastKnownSession = currentSession;
|
|
352
|
+
// Update intelligence to use new session
|
|
353
|
+
if (this.intelligence) {
|
|
354
|
+
this.intelligence.updateSessionId(currentSession);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}, 2000);
|
|
358
|
+
}
|
|
273
359
|
/**
|
|
274
360
|
* Clean up resources
|
|
275
361
|
*/
|
|
@@ -364,9 +450,27 @@ export class Cuoral {
|
|
|
364
450
|
});
|
|
365
451
|
// Handle stop recording requests from widget
|
|
366
452
|
this.bridge.on(CuoralMessageType.STOP_RECORDING, async () => {
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
453
|
+
const sessionId = localStorage.getItem('__x_loadID');
|
|
454
|
+
const customerId = localStorage.getItem('cuoralCustomerId');
|
|
455
|
+
const result = await this.recorder.stopRecording({
|
|
456
|
+
autoUpload: true,
|
|
457
|
+
sessionId: sessionId || undefined,
|
|
458
|
+
publicKey: this.options.publicKey,
|
|
459
|
+
customerId: customerId || undefined,
|
|
460
|
+
});
|
|
461
|
+
if (result && result.uploaded) {
|
|
462
|
+
// Video was automatically uploaded, just notify widget
|
|
463
|
+
this.bridge.sendToWidget({
|
|
464
|
+
type: CuoralMessageType.RECORDING_UPLOADED,
|
|
465
|
+
payload: {
|
|
466
|
+
duration: result.duration,
|
|
467
|
+
uploaded: true,
|
|
468
|
+
timestamp: Date.now()
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
else if (result) {
|
|
473
|
+
// Upload failed or was disabled, send video data to widget (old behavior)
|
|
370
474
|
const capacitorUrl = result.filePath ? Capacitor.convertFileSrc(result.filePath) : '';
|
|
371
475
|
try {
|
|
372
476
|
// Fetch the video blob from the capacitor URL
|