capacitor-event-bird 0.0.13 → 0.0.14

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.
@@ -8,6 +8,7 @@ public class CapacitorEventBirdPlugin: CAPPlugin, CAPBridgedPlugin {
8
8
 
9
9
  public let pluginMethods: [CAPPluginMethod] = [
10
10
  CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise),
11
+ CAPPluginMethod(name: "getFCMToken", returnType: CAPPluginReturnPromise),
11
12
  CAPPluginMethod(name: "logout", returnType: CAPPluginReturnPromise),
12
13
  CAPPluginMethod(name: "waitlistAfterInit", returnType: CAPPluginReturnPromise),
13
14
  CAPPluginMethod(name: "openHelpModal", returnType: CAPPluginReturnPromise),
@@ -15,7 +16,11 @@ public class CapacitorEventBirdPlugin: CAPPlugin, CAPBridgedPlugin {
15
16
  ]
16
17
 
17
18
  private var pendingEchoCalls: [CAPPluginCall] = []
19
+ private var pendingFCMCalls: [CAPPluginCall] = []
20
+
18
21
  private var savedToken: String?
22
+ private var savedFCMToken: String?
23
+
19
24
  private let implementation = CapacitorEventBird()
20
25
 
21
26
  @objc func echo(_ call: CAPPluginCall) {
@@ -28,16 +33,35 @@ public class CapacitorEventBirdPlugin: CAPPlugin, CAPBridgedPlugin {
28
33
  }
29
34
  }
30
35
 
36
+ @objc func getFCMToken(_ call: CAPPluginCall) {
37
+ if let token = savedFCMToken {
38
+ print("[Native] JS called getFCMToken, passing the token.")
39
+ call.resolve(["value": token])
40
+ } else {
41
+ print("[Native] JS called getFCMToken, but token not ready. Queuing callback.")
42
+ pendingFCMCalls.append(call)
43
+ }
44
+ }
45
+
31
46
  @objc func getDeviceId(_ call: CAPPluginCall) {
32
47
  call.resolve(["value": UIDevice.current.identifierForVendor?.uuidString])
33
48
  return
34
49
  }
35
50
 
51
+ @objc public func setFCMToken(_ token: String) {
52
+ print("[Native] Setting FCM token in plugin")
53
+ self.savedFCMToken = token
54
+
55
+ for call in pendingFCMCalls {
56
+ call.resolve(["value": token])
57
+ }
58
+ pendingFCMCalls.removeAll()
59
+ }
60
+
36
61
  @objc public func setAuthToken(_ token: String) {
37
62
  print("[Native] Setting auth token in plugin")
38
63
  self.savedToken = token
39
64
 
40
- // Resolve all pending echo calls
41
65
  for call in pendingEchoCalls {
42
66
  call.resolve(["value": token])
43
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-event-bird",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "returns events back to native env",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",