@clix-so/react-native-sdk 1.2.0 → 1.3.0
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/ios/ClixLiveActivity.swift +18 -0
- package/ios/ClixLiveActivityModule.m +5 -0
- package/ios/ClixLiveActivityModule.swift +114 -0
- package/lib/module/core/Clix.js +5 -0
- package/lib/module/core/Clix.js.map +1 -1
- package/lib/module/native/ClixLiveActivityBridge.js +38 -0
- package/lib/module/native/ClixLiveActivityBridge.js.map +1 -0
- package/lib/module/services/LiveActivityAPIService.js +25 -0
- package/lib/module/services/LiveActivityAPIService.js.map +1 -0
- package/lib/module/services/LiveActivityService.js +39 -0
- package/lib/module/services/LiveActivityService.js.map +1 -0
- package/lib/typescript/src/core/Clix.d.ts +2 -0
- package/lib/typescript/src/core/Clix.d.ts.map +1 -1
- package/lib/typescript/src/native/ClixLiveActivityBridge.d.ts +7 -0
- package/lib/typescript/src/native/ClixLiveActivityBridge.d.ts.map +1 -0
- package/lib/typescript/src/services/LiveActivityAPIService.d.ts +7 -0
- package/lib/typescript/src/services/LiveActivityAPIService.d.ts.map +1 -0
- package/lib/typescript/src/services/LiveActivityService.d.ts +13 -0
- package/lib/typescript/src/services/LiveActivityService.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/core/Clix.ts +9 -0
- package/src/native/ClixLiveActivityBridge.ts +60 -0
- package/src/services/LiveActivityAPIService.ts +42 -0
- package/src/services/LiveActivityService.ts +68 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
#if canImport(ActivityKit)
|
|
4
|
+
import ActivityKit
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
/// Public API for LiveActivity setup. Use this from your AppDelegate.
|
|
8
|
+
public class ClixLiveActivity: NSObject {
|
|
9
|
+
|
|
10
|
+
#if canImport(ActivityKit)
|
|
11
|
+
/// Starts listening for push-to-start tokens. Call this from AppDelegate.
|
|
12
|
+
/// - Parameter activityType: The ActivityAttributes type to listen for
|
|
13
|
+
@available(iOS 16.1, *)
|
|
14
|
+
public static func setup<Attributes: ActivityAttributes>(_ activityType: Attributes.Type) {
|
|
15
|
+
ClixLiveActivityModule.setup(activityType)
|
|
16
|
+
}
|
|
17
|
+
#endif
|
|
18
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import React
|
|
3
|
+
|
|
4
|
+
#if canImport(ActivityKit)
|
|
5
|
+
import ActivityKit
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
@objc(ClixLiveActivityModule)
|
|
9
|
+
class ClixLiveActivityModule: RCTEventEmitter {
|
|
10
|
+
|
|
11
|
+
private static var sharedInstance: ClixLiveActivityModule?
|
|
12
|
+
private static var pendingSetups: [() -> Void] = []
|
|
13
|
+
private var hasListeners = false
|
|
14
|
+
private var activeListeners: Set<String> = []
|
|
15
|
+
private var pendingTokens: [(activityType: String, token: String)] = []
|
|
16
|
+
|
|
17
|
+
override init() {
|
|
18
|
+
super.init()
|
|
19
|
+
ClixLiveActivityModule.sharedInstance = self
|
|
20
|
+
|
|
21
|
+
// Execute any pending setups that were called before the module was initialized
|
|
22
|
+
for pendingSetup in ClixLiveActivityModule.pendingSetups {
|
|
23
|
+
pendingSetup()
|
|
24
|
+
}
|
|
25
|
+
ClixLiveActivityModule.pendingSetups.removeAll()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override func supportedEvents() -> [String]! {
|
|
33
|
+
return ["onPushToStartToken"]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override func startObserving() {
|
|
37
|
+
hasListeners = true
|
|
38
|
+
// Send any pending tokens
|
|
39
|
+
for pending in pendingTokens {
|
|
40
|
+
sendEvent(withName: "onPushToStartToken", body: [
|
|
41
|
+
"activityType": pending.activityType,
|
|
42
|
+
"token": pending.token
|
|
43
|
+
])
|
|
44
|
+
}
|
|
45
|
+
pendingTokens.removeAll()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override func stopObserving() {
|
|
49
|
+
hasListeners = false
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#if canImport(ActivityKit)
|
|
53
|
+
/// Starts listening for push-to-start tokens. Call this from AppDelegate.
|
|
54
|
+
/// - Parameter activityType: The ActivityAttributes type to listen for
|
|
55
|
+
@available(iOS 16.1, *)
|
|
56
|
+
static func setup<Attributes: ActivityAttributes>(_ activityType: Attributes.Type) {
|
|
57
|
+
guard #available(iOS 17.2, *) else {
|
|
58
|
+
print("[Clix] LiveActivity pushToStartToken requires iOS 17.2+")
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let activityTypeName = String(describing: Attributes.self)
|
|
63
|
+
|
|
64
|
+
guard let instance = sharedInstance else {
|
|
65
|
+
// Store setup for later execution when the module is initialized
|
|
66
|
+
pendingSetups.append {
|
|
67
|
+
setup(activityType)
|
|
68
|
+
}
|
|
69
|
+
print("[Clix] ClixLiveActivityModule not ready yet. Setup will be executed when ready.")
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
instance.startListening(activityType, activityTypeName: activityTypeName)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@available(iOS 17.2, *)
|
|
77
|
+
private func startListening<Attributes: ActivityAttributes>(
|
|
78
|
+
_ activityType: Attributes.Type,
|
|
79
|
+
activityTypeName: String
|
|
80
|
+
) {
|
|
81
|
+
guard !activeListeners.contains(activityTypeName) else {
|
|
82
|
+
print("[Clix] Already listening for pushToStartToken: \(activityTypeName)")
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
activeListeners.insert(activityTypeName)
|
|
87
|
+
print("[Clix] Starting pushToStartToken listener: \(activityTypeName)")
|
|
88
|
+
|
|
89
|
+
Task {
|
|
90
|
+
for await tokenData in Activity<Attributes>.pushToStartTokenUpdates {
|
|
91
|
+
let token = tokenData.map { String(format: "%02x", $0) }.joined()
|
|
92
|
+
print("[Clix] Received pushToStartToken for \(activityTypeName): \(token)")
|
|
93
|
+
|
|
94
|
+
await MainActor.run {
|
|
95
|
+
self.emitToken(activityType: activityTypeName, token: token)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
#endif
|
|
101
|
+
|
|
102
|
+
private func emitToken(activityType: String, token: String) {
|
|
103
|
+
let body: [String: Any] = [
|
|
104
|
+
"activityType": activityType,
|
|
105
|
+
"token": token
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
if hasListeners {
|
|
109
|
+
sendEvent(withName: "onPushToStartToken", body: body)
|
|
110
|
+
} else {
|
|
111
|
+
pendingTokens.append((activityType: activityType, token: token))
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
package/lib/module/core/Clix.js
CHANGED
|
@@ -5,6 +5,8 @@ import { DeviceAPIService } from "../services/DeviceAPIService.js";
|
|
|
5
5
|
import { DeviceService } from "../services/DeviceService.js";
|
|
6
6
|
import { EventAPIService } from "../services/EventAPIService.js";
|
|
7
7
|
import { EventService } from "../services/EventService.js";
|
|
8
|
+
import { LiveActivityAPIService } from "../services/LiveActivityAPIService.js";
|
|
9
|
+
import { LiveActivityService } from "../services/LiveActivityService.js";
|
|
8
10
|
import { NotificationService } from "../services/NotificationService.js";
|
|
9
11
|
import { StorageService } from "../services/StorageService.js";
|
|
10
12
|
import { TokenService } from "../services/TokenService.js";
|
|
@@ -34,12 +36,15 @@ export class Clix {
|
|
|
34
36
|
const apiClient = new ClixAPIClient(config);
|
|
35
37
|
const deviceApiService = new DeviceAPIService(apiClient);
|
|
36
38
|
const eventApiService = new EventAPIService(apiClient);
|
|
39
|
+
const liveActivityApiService = new LiveActivityAPIService(apiClient);
|
|
37
40
|
this.shared.storageService = new StorageService(config.projectId);
|
|
38
41
|
this.shared.tokenService = new TokenService(this.shared.storageService);
|
|
39
42
|
this.shared.deviceService = new DeviceService(this.shared.storageService, this.shared.tokenService, deviceApiService);
|
|
40
43
|
this.shared.eventService = new EventService(eventApiService, this.shared.deviceService);
|
|
41
44
|
this.shared.notificationService = new NotificationService(this.shared.deviceService, this.shared.tokenService, this.shared.eventService);
|
|
45
|
+
this.shared.liveActivityService = new LiveActivityService(this.shared.deviceService, liveActivityApiService);
|
|
42
46
|
this.shared.storageService.set(this.configKey, config);
|
|
47
|
+
this.shared.liveActivityService.initialize();
|
|
43
48
|
await this.shared.notificationService.initialize(); // NOTE(nyanxyz): must be initialized before any await calls
|
|
44
49
|
await this.shared.deviceService.initialize();
|
|
45
50
|
ClixLogger.debug('Clix SDK initialized successfully');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ClixAPIClient","DeviceAPIService","DeviceService","EventAPIService","EventService","NotificationService","StorageService","TokenService","ClixLogger","ClixLogLevel","ClixInitCoordinator","ClixNotification","Clix","initCoordinator","Notification","shared","configKey","initialize","options","config","endpoint","logLevel","INFO","extraHeaders","setLogLevel","ERROR","debug","apiClient","deviceApiService","eventApiService","storageService","projectId","tokenService","deviceService","eventService","notificationService","set","completeInitialization","error","errorInstance","Error","String","failInitialization","setUserId","userId","waitForInitialization","setProjectUserId","removeUserId","removeProjectUserId","setUserProperty","key","value","updateUserProperties","setUserProperties","properties","removeUserProperty","removeUserProperties","keys","trackEvent","name","level","getDeviceId","getCurrentDeviceId","undefined"],"sourceRoot":"../../../src","sources":["core/Clix.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,8BAA2B;AACzD,SAASC,gBAAgB,QAAQ,iCAA8B;AAC/D,SAASC,aAAa,QAAQ,8BAA2B;AACzD,SAASC,eAAe,QAAQ,gCAA6B;AAC7D,SAASC,YAAY,QAAQ,6BAA0B;AACvD,SAASC,mBAAmB,QAAQ,oCAAiC;AACrE,SAASC,cAAc,QAAQ,+BAA4B;AAC3D,SAASC,YAAY,QAAQ,6BAA0B;AACvD,SAASC,UAAU,EAAEC,YAAY,QAAQ,gCAA6B;AAGtE,SAASC,mBAAmB,QAAQ,0BAAuB;AAC3D,SAASC,gBAAgB,QAAQ,uBAAoB;AAMrD,OAAO,MAAMC,IAAI,CAAC;EAEhB,OAAOC,eAAe,GAAG,IAAIH,mBAAmB,CAAC,CAAC;EAElD,OAAOI,YAAY,GAAGH,gBAAgB,CAACI,MAAM;
|
|
1
|
+
{"version":3,"names":["ClixAPIClient","DeviceAPIService","DeviceService","EventAPIService","EventService","LiveActivityAPIService","LiveActivityService","NotificationService","StorageService","TokenService","ClixLogger","ClixLogLevel","ClixInitCoordinator","ClixNotification","Clix","initCoordinator","Notification","shared","configKey","initialize","options","config","endpoint","logLevel","INFO","extraHeaders","setLogLevel","ERROR","debug","apiClient","deviceApiService","eventApiService","liveActivityApiService","storageService","projectId","tokenService","deviceService","eventService","notificationService","liveActivityService","set","completeInitialization","error","errorInstance","Error","String","failInitialization","setUserId","userId","waitForInitialization","setProjectUserId","removeUserId","removeProjectUserId","setUserProperty","key","value","updateUserProperties","setUserProperties","properties","removeUserProperty","removeUserProperties","keys","trackEvent","name","level","getDeviceId","getCurrentDeviceId","undefined"],"sourceRoot":"../../../src","sources":["core/Clix.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,8BAA2B;AACzD,SAASC,gBAAgB,QAAQ,iCAA8B;AAC/D,SAASC,aAAa,QAAQ,8BAA2B;AACzD,SAASC,eAAe,QAAQ,gCAA6B;AAC7D,SAASC,YAAY,QAAQ,6BAA0B;AACvD,SAASC,sBAAsB,QAAQ,uCAAoC;AAC3E,SAASC,mBAAmB,QAAQ,oCAAiC;AACrE,SAASC,mBAAmB,QAAQ,oCAAiC;AACrE,SAASC,cAAc,QAAQ,+BAA4B;AAC3D,SAASC,YAAY,QAAQ,6BAA0B;AACvD,SAASC,UAAU,EAAEC,YAAY,QAAQ,gCAA6B;AAGtE,SAASC,mBAAmB,QAAQ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AWA,CAAA,EAAgC;IACtD,IAAI;MACF,MAAMnD,IAAI,CAACC,eAAe,CAACkC,qBAAqB,CAAC,CAAC;MAClD,OAAO,IAAI,CAAChC,MAAM,EAAEmB,aAAa,EAAE8B,kBAAkB,CAAC,CAAC;IACzD,CAAC,CAAC,OAAOxB,KAAK,EAAE;MACdhC,UAAU,CAACgC,KAAK,CAAC,4BAA4BA,KAAK,EAAE,CAAC;MACrD,OAAOyB,SAAS;IAClB;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
|
|
4
|
+
import { ClixLogger } from "../utils/logging/ClixLogger.js";
|
|
5
|
+
const MODULE_NAME = 'ClixLiveActivityModule';
|
|
6
|
+
const resolveModule = () => {
|
|
7
|
+
if (Platform.OS !== 'ios') {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
const nativeModule = NativeModules[MODULE_NAME];
|
|
11
|
+
if (!nativeModule) {
|
|
12
|
+
ClixLogger.debug('ClixLiveActivityModule is not available');
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return nativeModule;
|
|
16
|
+
};
|
|
17
|
+
let eventEmitter;
|
|
18
|
+
const getEventEmitter = () => {
|
|
19
|
+
if (Platform.OS !== 'ios') {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (!eventEmitter) {
|
|
23
|
+
const nativeModule = resolveModule();
|
|
24
|
+
if (nativeModule) {
|
|
25
|
+
eventEmitter = new NativeEventEmitter(nativeModule);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return eventEmitter;
|
|
29
|
+
};
|
|
30
|
+
export const subscribeToPushToStartToken = callback => {
|
|
31
|
+
const emitter = getEventEmitter();
|
|
32
|
+
if (!emitter) {
|
|
33
|
+
ClixLogger.debug('NativeEventEmitter is not available for LiveActivity');
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return emitter.addListener('onPushToStartToken', callback);
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=ClixLiveActivityBridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","NativeEventEmitter","Platform","ClixLogger","MODULE_NAME","resolveModule","OS","undefined","nativeModule","debug","eventEmitter","getEventEmitter","subscribeToPushToStartToken","callback","emitter","addListener"],"sourceRoot":"../../../src","sources":["native/ClixLiveActivityBridge.ts"],"mappings":";;AAAA,SACEA,aAAa,EACbC,kBAAkB,EAClBC,QAAQ,QAEH,cAAc;AACrB,SAASC,UAAU,QAAQ,gCAA6B;AAExD,MAAMC,WAAW,GAAG,wBAAwB;AAY5C,MAAMC,aAAa,GAAGA,CAAA,KAAgD;EACpE,IAAIH,QAAQ,CAACI,EAAE,KAAK,KAAK,EAAE;IACzB,OAAOC,SAAS;EAClB;EAEA,MAAMC,YAAY,GAAIR,aAAa,CAA6BI,WAAW,CAAC;EAC5E,IAAI,CAACI,YAAY,EAAE;IACjBL,UAAU,CAACM,KAAK,CAAC,yCAAyC,CAAC;IAC3D,OAAOF,SAAS;EAClB;EACA,OAAOC,YAAY;AACrB,CAAC;AAED,IAAIE,YAA4C;AAEhD,MAAMC,eAAe,GAAGA,CAAA,KAAsC;EAC5D,IAAIT,QAAQ,CAACI,EAAE,KAAK,KAAK,EAAE;IACzB,OAAOC,SAAS;EAClB;EAEA,IAAI,CAACG,YAAY,EAAE;IACjB,MAAMF,YAAY,GAAGH,aAAa,CAAC,CAAC;IACpC,IAAIG,YAAY,EAAE;MAChBE,YAAY,GAAG,IAAIT,kBAAkB,CAACO,YAAmB,CAAC;IAC5D;EACF;EACA,OAAOE,YAAY;AACrB,CAAC;AAED,OAAO,MAAME,2BAA2B,GACtCC,QAAgD,IACZ;EACpC,MAAMC,OAAO,GAAGH,eAAe,CAAC,CAAC;EACjC,IAAI,CAACG,OAAO,EAAE;IACZX,UAAU,CAACM,KAAK,CAAC,sDAAsD,CAAC;IACxE,OAAOF,SAAS;EAClB;EAEA,OAAOO,OAAO,CAACC,WAAW,CAAC,oBAAoB,EAAEF,QAAQ,CAAC;AAC5D,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { ClixLogger } from "../utils/logging/ClixLogger.js";
|
|
4
|
+
export class LiveActivityAPIService {
|
|
5
|
+
constructor(apiClient) {
|
|
6
|
+
this.apiClient = apiClient;
|
|
7
|
+
}
|
|
8
|
+
async registerLiveActivityStartToken(deviceId, activityType, token) {
|
|
9
|
+
try {
|
|
10
|
+
ClixLogger.debug(`Registering liveActivityStartToken for device: ${deviceId}, activityType: ${activityType}`);
|
|
11
|
+
const response = await this.apiClient.post(`/devices/${deviceId}/live-activity-start-tokens`, {
|
|
12
|
+
attributes_type: activityType,
|
|
13
|
+
push_to_start_token: token
|
|
14
|
+
});
|
|
15
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
16
|
+
throw new Error(`HTTP ${response.statusCode}: ${JSON.stringify(response.data)}`);
|
|
17
|
+
}
|
|
18
|
+
ClixLogger.debug(`PushToStartToken set successfully for device: ${deviceId}`);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
ClixLogger.error(`Failed to set pushToStartToken for device: ${deviceId}`, error);
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=LiveActivityAPIService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ClixLogger","LiveActivityAPIService","constructor","apiClient","registerLiveActivityStartToken","deviceId","activityType","token","debug","response","post","attributes_type","push_to_start_token","statusCode","Error","JSON","stringify","data","error"],"sourceRoot":"../../../src","sources":["services/LiveActivityAPIService.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,gCAA6B;AAGxD,OAAO,MAAMC,sBAAsB,CAAC;EAClCC,WAAWA,CAAkBC,SAAwB,EAAE;IAAA,KAA1BA,SAAwB,GAAxBA,SAAwB;EAAG;EAExD,MAAMC,8BAA8BA,CAClCC,QAAgB,EAChBC,YAAoB,EACpBC,KAAa,EACE;IACf,IAAI;MACFP,UAAU,CAACQ,KAAK,CACd,kDAAkDH,QAAQ,mBAAmBC,YAAY,EAC3F,CAAC;MAED,MAAMG,QAAQ,GAAG,MAAM,IAAI,CAACN,SAAS,CAACO,IAAI,CACxC,YAAYL,QAAQ,6BAA6B,EACjD;QACEM,eAAe,EAAEL,YAAY;QAC7BM,mBAAmB,EAAEL;MACvB,CACF,CAAC;MAED,IAAIE,QAAQ,CAACI,UAAU,GAAG,GAAG,IAAIJ,QAAQ,CAACI,UAAU,IAAI,GAAG,EAAE;QAC3D,MAAM,IAAIC,KAAK,CACb,QAAQL,QAAQ,CAACI,UAAU,KAAKE,IAAI,CAACC,SAAS,CAACP,QAAQ,CAACQ,IAAI,CAAC,EAC/D,CAAC;MACH;MAEAjB,UAAU,CAACQ,KAAK,CACd,iDAAiDH,QAAQ,EAC3D,CAAC;IACH,CAAC,CAAC,OAAOa,KAAK,EAAE;MACdlB,UAAU,CAACkB,KAAK,CACd,8CAA8Cb,QAAQ,EAAE,EACxDa,KACF,CAAC;MACD,MAAMA,KAAK;IACb;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { subscribeToPushToStartToken } from "../native/ClixLiveActivityBridge.js";
|
|
4
|
+
import { ClixLogger } from "../utils/logging/ClixLogger.js";
|
|
5
|
+
export class LiveActivityService {
|
|
6
|
+
isInitialized = false;
|
|
7
|
+
constructor(deviceService, liveActivityAPIService) {
|
|
8
|
+
this.deviceService = deviceService;
|
|
9
|
+
this.liveActivityAPIService = liveActivityAPIService;
|
|
10
|
+
}
|
|
11
|
+
initialize() {
|
|
12
|
+
if (this.isInitialized) {
|
|
13
|
+
ClixLogger.debug('LiveActivityService already initialized');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
this.subscription = subscribeToPushToStartToken(this.handlePushToStartToken.bind(this));
|
|
17
|
+
if (this.subscription) {
|
|
18
|
+
this.isInitialized = true;
|
|
19
|
+
ClixLogger.debug('LiveActivityService initialized successfully');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
cleanup() {
|
|
23
|
+
this.subscription?.remove();
|
|
24
|
+
this.subscription = undefined;
|
|
25
|
+
this.isInitialized = false;
|
|
26
|
+
ClixLogger.debug('LiveActivityService cleaned up');
|
|
27
|
+
}
|
|
28
|
+
async handlePushToStartToken(event) {
|
|
29
|
+
try {
|
|
30
|
+
ClixLogger.debug(`Received pushToStartToken for ${event.activityType}: ${event.token}`);
|
|
31
|
+
const deviceId = this.deviceService.getCurrentDeviceId();
|
|
32
|
+
await this.liveActivityAPIService.registerLiveActivityStartToken(deviceId, event.activityType, event.token);
|
|
33
|
+
ClixLogger.debug(`PushToStartToken sent successfully for ${event.activityType}`);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
ClixLogger.error(`Failed to send pushToStartToken for ${event.activityType}`, error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=LiveActivityService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["subscribeToPushToStartToken","ClixLogger","LiveActivityService","isInitialized","constructor","deviceService","liveActivityAPIService","initialize","debug","subscription","handlePushToStartToken","bind","cleanup","remove","undefined","event","activityType","token","deviceId","getCurrentDeviceId","registerLiveActivityStartToken","error"],"sourceRoot":"../../../src","sources":["services/LiveActivityService.ts"],"mappings":";;AACA,SACEA,2BAA2B,QAEtB,qCAAkC;AACzC,SAASC,UAAU,QAAQ,gCAA6B;AAIxD,OAAO,MAAMC,mBAAmB,CAAC;EAEvBC,aAAa,GAAG,KAAK;EAE7BC,WAAWA,CACQC,aAA4B,EAC5BC,sBAA8C,EAC/D;I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{ DeviceService } from '../services/DeviceService';
|
|
2
2
|
import { EventService } from '../services/EventService';
|
|
3
|
+
import { LiveActivityService } from '../services/LiveActivityService';
|
|
3
4
|
import { NotificationService } from '../services/NotificationService';
|
|
4
5
|
import { StorageService } from '../services/StorageService';
|
|
5
6
|
import { TokenService } from '../services/TokenService';
|
|
@@ -19,6 +20,7 @@ export declare class Clix {
|
|
|
19
20
|
eventService?: EventService;
|
|
20
21
|
deviceService?: DeviceService;
|
|
21
22
|
notificationService?: NotificationService;
|
|
23
|
+
liveActivityService?: LiveActivityService;
|
|
22
24
|
private static configKey;
|
|
23
25
|
/**
|
|
24
26
|
* Initialize Clix SDK
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Clix.d.ts","sourceRoot":"","sources":["../../../../src/core/Clix.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"Clix.d.ts","sourceRoot":"","sources":["../../../../src/core/Clix.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAc,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAA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AEG;WACU,UAAU,CACrB,IAAI,EAAE,MAAM,EACZ,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GACnC,OAAO,CAAC,IAAI,CAAC;IAShB;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAK7C;;OAEG;WACU,WAAW,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CASxD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type EmitterSubscription } from 'react-native';
|
|
2
|
+
export interface PushToStartTokenEvent {
|
|
3
|
+
activityType: string;
|
|
4
|
+
token: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const subscribeToPushToStartToken: (callback: (event: PushToStartTokenEvent) => void) => EmitterSubscription | undefined;
|
|
7
|
+
//# sourceMappingURL=ClixLiveActivityBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClixLiveActivityBridge.d.ts","sourceRoot":"","sources":["../../../../src/native/ClixLiveActivityBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAC;AAKtB,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf;AAoCD,eAAO,MAAM,2BAA2B,GACtC,UAAU,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,KAC/C,mBAAmB,GAAG,SAQxB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ClixAPIClient } from './ClixAPIClient';
|
|
2
|
+
export declare class LiveActivityAPIService {
|
|
3
|
+
private readonly apiClient;
|
|
4
|
+
constructor(apiClient: ClixAPIClient);
|
|
5
|
+
registerLiveActivityStartToken(deviceId: string, activityType: string, token: string): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=LiveActivityAPIService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveActivityAPIService.d.ts","sourceRoot":"","sources":["../../../../src/services/LiveActivityAPIService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,sBAAsB;IACrB,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;IAE/C,8BAA8B,CAClC,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;CA+BjB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DeviceService } from './DeviceService';
|
|
2
|
+
import type { LiveActivityAPIService } from './LiveActivityAPIService';
|
|
3
|
+
export declare class LiveActivityService {
|
|
4
|
+
private readonly deviceService;
|
|
5
|
+
private readonly liveActivityAPIService;
|
|
6
|
+
private subscription?;
|
|
7
|
+
private isInitialized;
|
|
8
|
+
constructor(deviceService: DeviceService, liveActivityAPIService: LiveActivityAPIService);
|
|
9
|
+
initialize(): void;
|
|
10
|
+
cleanup(): void;
|
|
11
|
+
private handlePushToStartToken;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=LiveActivityService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveActivityService.d.ts","sourceRoot":"","sources":["../../../../src/services/LiveActivityService.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEvE,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IALzC,OAAO,CAAC,YAAY,CAAC,CAAsB;IAC3C,OAAO,CAAC,aAAa,CAAS;gBAGX,aAAa,EAAE,aAAa,EAC5B,sBAAsB,EAAE,sBAAsB;IAGjE,UAAU,IAAI,IAAI;IAgBlB,OAAO,IAAI,IAAI;YAOD,sBAAsB;CA0BrC"}
|
package/package.json
CHANGED
package/src/core/Clix.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { DeviceAPIService } from '../services/DeviceAPIService';
|
|
|
3
3
|
import { DeviceService } from '../services/DeviceService';
|
|
4
4
|
import { EventAPIService } from '../services/EventAPIService';
|
|
5
5
|
import { EventService } from '../services/EventService';
|
|
6
|
+
import { LiveActivityAPIService } from '../services/LiveActivityAPIService';
|
|
7
|
+
import { LiveActivityService } from '../services/LiveActivityService';
|
|
6
8
|
import { NotificationService } from '../services/NotificationService';
|
|
7
9
|
import { StorageService } from '../services/StorageService';
|
|
8
10
|
import { TokenService } from '../services/TokenService';
|
|
@@ -28,6 +30,7 @@ export class Clix {
|
|
|
28
30
|
eventService?: EventService;
|
|
29
31
|
deviceService?: DeviceService;
|
|
30
32
|
notificationService?: NotificationService;
|
|
33
|
+
liveActivityService?: LiveActivityService;
|
|
31
34
|
|
|
32
35
|
private static configKey = 'clix_config';
|
|
33
36
|
|
|
@@ -52,6 +55,7 @@ export class Clix {
|
|
|
52
55
|
const apiClient = new ClixAPIClient(config);
|
|
53
56
|
const deviceApiService = new DeviceAPIService(apiClient);
|
|
54
57
|
const eventApiService = new EventAPIService(apiClient);
|
|
58
|
+
const liveActivityApiService = new LiveActivityAPIService(apiClient);
|
|
55
59
|
|
|
56
60
|
this.shared.storageService = new StorageService(config.projectId);
|
|
57
61
|
this.shared.tokenService = new TokenService(this.shared.storageService);
|
|
@@ -69,8 +73,13 @@ export class Clix {
|
|
|
69
73
|
this.shared.tokenService,
|
|
70
74
|
this.shared.eventService
|
|
71
75
|
);
|
|
76
|
+
this.shared.liveActivityService = new LiveActivityService(
|
|
77
|
+
this.shared.deviceService,
|
|
78
|
+
liveActivityApiService
|
|
79
|
+
);
|
|
72
80
|
|
|
73
81
|
this.shared.storageService.set(this.configKey, config);
|
|
82
|
+
this.shared.liveActivityService.initialize();
|
|
74
83
|
await this.shared.notificationService.initialize(); // NOTE(nyanxyz): must be initialized before any await calls
|
|
75
84
|
await this.shared.deviceService.initialize();
|
|
76
85
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NativeModules,
|
|
3
|
+
NativeEventEmitter,
|
|
4
|
+
Platform,
|
|
5
|
+
type EmitterSubscription,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
import { ClixLogger } from '../utils/logging/ClixLogger';
|
|
8
|
+
|
|
9
|
+
const MODULE_NAME = 'ClixLiveActivityModule';
|
|
10
|
+
|
|
11
|
+
export interface PushToStartTokenEvent {
|
|
12
|
+
activityType: string;
|
|
13
|
+
token: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type ClixLiveActivityNativeModule = {
|
|
17
|
+
addListener: (eventName: string) => void;
|
|
18
|
+
removeListeners: (count: number) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const resolveModule = (): ClixLiveActivityNativeModule | undefined => {
|
|
22
|
+
if (Platform.OS !== 'ios') {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const nativeModule = (NativeModules as Record<string, unknown>)[MODULE_NAME];
|
|
27
|
+
if (!nativeModule) {
|
|
28
|
+
ClixLogger.debug('ClixLiveActivityModule is not available');
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return nativeModule as ClixLiveActivityNativeModule;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let eventEmitter: NativeEventEmitter | undefined;
|
|
35
|
+
|
|
36
|
+
const getEventEmitter = (): NativeEventEmitter | undefined => {
|
|
37
|
+
if (Platform.OS !== 'ios') {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!eventEmitter) {
|
|
42
|
+
const nativeModule = resolveModule();
|
|
43
|
+
if (nativeModule) {
|
|
44
|
+
eventEmitter = new NativeEventEmitter(nativeModule as any);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return eventEmitter;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const subscribeToPushToStartToken = (
|
|
51
|
+
callback: (event: PushToStartTokenEvent) => void
|
|
52
|
+
): EmitterSubscription | undefined => {
|
|
53
|
+
const emitter = getEventEmitter();
|
|
54
|
+
if (!emitter) {
|
|
55
|
+
ClixLogger.debug('NativeEventEmitter is not available for LiveActivity');
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return emitter.addListener('onPushToStartToken', callback);
|
|
60
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ClixLogger } from '../utils/logging/ClixLogger';
|
|
2
|
+
import { ClixAPIClient } from './ClixAPIClient';
|
|
3
|
+
|
|
4
|
+
export class LiveActivityAPIService {
|
|
5
|
+
constructor(private readonly apiClient: ClixAPIClient) {}
|
|
6
|
+
|
|
7
|
+
async registerLiveActivityStartToken(
|
|
8
|
+
deviceId: string,
|
|
9
|
+
activityType: string,
|
|
10
|
+
token: string
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
try {
|
|
13
|
+
ClixLogger.debug(
|
|
14
|
+
`Registering liveActivityStartToken for device: ${deviceId}, activityType: ${activityType}`
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const response = await this.apiClient.post(
|
|
18
|
+
`/devices/${deviceId}/live-activity-start-tokens`,
|
|
19
|
+
{
|
|
20
|
+
attributes_type: activityType,
|
|
21
|
+
push_to_start_token: token,
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`HTTP ${response.statusCode}: ${JSON.stringify(response.data)}`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
ClixLogger.debug(
|
|
32
|
+
`PushToStartToken set successfully for device: ${deviceId}`
|
|
33
|
+
);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
ClixLogger.error(
|
|
36
|
+
`Failed to set pushToStartToken for device: ${deviceId}`,
|
|
37
|
+
error
|
|
38
|
+
);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { EmitterSubscription } from 'react-native';
|
|
2
|
+
import {
|
|
3
|
+
subscribeToPushToStartToken,
|
|
4
|
+
type PushToStartTokenEvent,
|
|
5
|
+
} from '../native/ClixLiveActivityBridge';
|
|
6
|
+
import { ClixLogger } from '../utils/logging/ClixLogger';
|
|
7
|
+
import type { DeviceService } from './DeviceService';
|
|
8
|
+
import type { LiveActivityAPIService } from './LiveActivityAPIService';
|
|
9
|
+
|
|
10
|
+
export class LiveActivityService {
|
|
11
|
+
private subscription?: EmitterSubscription;
|
|
12
|
+
private isInitialized = false;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
private readonly deviceService: DeviceService,
|
|
16
|
+
private readonly liveActivityAPIService: LiveActivityAPIService
|
|
17
|
+
) {}
|
|
18
|
+
|
|
19
|
+
initialize(): void {
|
|
20
|
+
if (this.isInitialized) {
|
|
21
|
+
ClixLogger.debug('LiveActivityService already initialized');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this.subscription = subscribeToPushToStartToken(
|
|
26
|
+
this.handlePushToStartToken.bind(this)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (this.subscription) {
|
|
30
|
+
this.isInitialized = true;
|
|
31
|
+
ClixLogger.debug('LiveActivityService initialized successfully');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
cleanup(): void {
|
|
36
|
+
this.subscription?.remove();
|
|
37
|
+
this.subscription = undefined;
|
|
38
|
+
this.isInitialized = false;
|
|
39
|
+
ClixLogger.debug('LiveActivityService cleaned up');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private async handlePushToStartToken(
|
|
43
|
+
event: PushToStartTokenEvent
|
|
44
|
+
): Promise<void> {
|
|
45
|
+
try {
|
|
46
|
+
ClixLogger.debug(
|
|
47
|
+
`Received pushToStartToken for ${event.activityType}: ${event.token}`
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const deviceId = this.deviceService.getCurrentDeviceId();
|
|
51
|
+
|
|
52
|
+
await this.liveActivityAPIService.registerLiveActivityStartToken(
|
|
53
|
+
deviceId,
|
|
54
|
+
event.activityType,
|
|
55
|
+
event.token
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
ClixLogger.debug(
|
|
59
|
+
`PushToStartToken sent successfully for ${event.activityType}`
|
|
60
|
+
);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
ClixLogger.error(
|
|
63
|
+
`Failed to send pushToStartToken for ${event.activityType}`,
|
|
64
|
+
error
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|