@rematter/pylon-react-native 0.1.4
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/README.md +503 -0
- package/RNPylonChat.podspec +33 -0
- package/android/build.gradle +74 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/pylon/chatwidget/Pylon.kt +149 -0
- package/android/src/main/java/com/pylon/chatwidget/PylonChat.kt +715 -0
- package/android/src/main/java/com/pylon/chatwidget/PylonChatController.kt +63 -0
- package/android/src/main/java/com/pylon/chatwidget/PylonChatListener.kt +76 -0
- package/android/src/main/java/com/pylon/chatwidget/PylonChatView.kt +7 -0
- package/android/src/main/java/com/pylon/chatwidget/PylonConfig.kt +62 -0
- package/android/src/main/java/com/pylon/chatwidget/PylonDebugView.kt +76 -0
- package/android/src/main/java/com/pylon/chatwidget/PylonUser.kt +41 -0
- package/android/src/main/java/com/pylonchat/reactnative/RNPylonChatPackage.kt +17 -0
- package/android/src/main/java/com/pylonchat/reactnative/RNPylonChatView.kt +298 -0
- package/android/src/main/java/com/pylonchat/reactnative/RNPylonChatViewManager.kt +201 -0
- package/ios/PylonChat/PylonChat.swift +865 -0
- package/ios/RNPylonChatView.swift +332 -0
- package/ios/RNPylonChatViewManager.m +55 -0
- package/ios/RNPylonChatViewManager.swift +23 -0
- package/lib/PylonChatView.d.ts +27 -0
- package/lib/PylonChatView.js +78 -0
- package/lib/PylonChatWidget.android.d.ts +19 -0
- package/lib/PylonChatWidget.android.js +144 -0
- package/lib/PylonChatWidget.ios.d.ts +14 -0
- package/lib/PylonChatWidget.ios.js +79 -0
- package/lib/PylonModule.d.ts +32 -0
- package/lib/PylonModule.js +44 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +15 -0
- package/lib/types.d.ts +34 -0
- package/lib/types.js +2 -0
- package/package.json +39 -0
- package/src/PylonChatView.tsx +170 -0
- package/src/PylonChatWidget.android.tsx +165 -0
- package/src/PylonChatWidget.d.ts +15 -0
- package/src/PylonChatWidget.ios.tsx +79 -0
- package/src/PylonModule.ts +52 -0
- package/src/index.ts +15 -0
- package/src/types.ts +37 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
package com.pylon.chatwidget
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.Intent
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Entry point for configuring and interacting with the Pylon SDK.
|
|
8
|
+
*
|
|
9
|
+
* The object keeps the SDK configuration and user session in memory and exposes
|
|
10
|
+
* a couple of convenience helpers so app developers do not have to wire
|
|
11
|
+
* everything manually.
|
|
12
|
+
*/
|
|
13
|
+
object Pylon {
|
|
14
|
+
|
|
15
|
+
private data class State(
|
|
16
|
+
val appContext: Context,
|
|
17
|
+
val config: PylonConfig,
|
|
18
|
+
val user: PylonUser?
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
@Volatile
|
|
22
|
+
private var state: State? = null
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Initialize the SDK with the bare minimum information (the App ID). You
|
|
26
|
+
* can optionally customise the configuration via the [block].
|
|
27
|
+
*/
|
|
28
|
+
@JvmStatic
|
|
29
|
+
@JvmOverloads
|
|
30
|
+
fun initialize(context: Context, appId: String, block: PylonConfig.Builder.() -> Unit = {}) {
|
|
31
|
+
val config = PylonConfig.build(appId, block)
|
|
32
|
+
setState(context.applicationContext, config, state?.user)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Initialize the SDK with a previously built [PylonConfig] instance.
|
|
37
|
+
*/
|
|
38
|
+
@JvmStatic
|
|
39
|
+
fun initialize(context: Context, config: PylonConfig) {
|
|
40
|
+
setState(context.applicationContext, config, state?.user)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Update the active configuration while keeping the current user session.
|
|
45
|
+
*/
|
|
46
|
+
@JvmStatic
|
|
47
|
+
fun updateConfiguration(block: PylonConfig.Builder.() -> Unit) {
|
|
48
|
+
val current = requireState()
|
|
49
|
+
val updated = PylonConfig.from(current.config, block)
|
|
50
|
+
state = current.copy(config = updated)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Attach user information so the chat widget can identify the visitor.
|
|
55
|
+
*/
|
|
56
|
+
@JvmStatic
|
|
57
|
+
fun setUser(user: PylonUser) {
|
|
58
|
+
val current = requireState()
|
|
59
|
+
state = current.copy(user = user)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Convenience overload to build the user object inline.
|
|
64
|
+
*/
|
|
65
|
+
@JvmStatic
|
|
66
|
+
@JvmOverloads
|
|
67
|
+
fun setUser(email: String, name: String, block: PylonUser.Builder.() -> Unit = {}) {
|
|
68
|
+
setUser(PylonUser.build(email, name, block))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Clear any stored user information (useful on logout flows).
|
|
73
|
+
*/
|
|
74
|
+
@JvmStatic
|
|
75
|
+
fun clearUser() {
|
|
76
|
+
val current = requireState()
|
|
77
|
+
state = current.copy(user = null)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Attach or update the identity verification hash as described in the Pylon
|
|
82
|
+
* chat widget identity verification docs. Requires that a user has already
|
|
83
|
+
* been set so we have an email to associate with the hash.
|
|
84
|
+
*/
|
|
85
|
+
@JvmStatic
|
|
86
|
+
fun setEmailHash(emailHash: String?) {
|
|
87
|
+
val current = requireState()
|
|
88
|
+
val user = current.user ?: error("Set user before calling setEmailHash().")
|
|
89
|
+
state = current.copy(user = user.copy(emailHash = emailHash))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Check whether the SDK has been initialised.
|
|
94
|
+
*/
|
|
95
|
+
@JvmStatic
|
|
96
|
+
fun isInitialized(): Boolean = state != null
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create a [PylonChatController] that wraps a [PylonChat] view with the current
|
|
100
|
+
* configuration already wired in. The caller receives both the controller
|
|
101
|
+
* (to show or hide the chat programmatically) and the view instance that can
|
|
102
|
+
* be added to the UI hierarchy.
|
|
103
|
+
*/
|
|
104
|
+
@JvmStatic
|
|
105
|
+
@JvmOverloads
|
|
106
|
+
fun createChat(context: Context, listener: PylonChatListener? = null): PylonChatController {
|
|
107
|
+
val state = requireState()
|
|
108
|
+
val chatView = PylonChat(context, state.config, state.user)
|
|
109
|
+
listener?.let { chatView.setListener(it) }
|
|
110
|
+
chatView.ensurePylonLoaded()
|
|
111
|
+
return PylonChatController(chatView)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Create a chat view with specific config and user (instance-based, no global state).
|
|
116
|
+
*/
|
|
117
|
+
@JvmStatic
|
|
118
|
+
@JvmOverloads
|
|
119
|
+
fun createChat(context: Context, config: PylonConfig, user: PylonUser? = null, listener: PylonChatListener? = null): PylonChatController {
|
|
120
|
+
val chatView = PylonChat(context, config, user)
|
|
121
|
+
listener?.let { chatView.setListener(it) }
|
|
122
|
+
chatView.ensurePylonLoaded()
|
|
123
|
+
return PylonChatController(chatView)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
internal fun requireConfig(): PylonConfig = requireState().config
|
|
127
|
+
|
|
128
|
+
internal fun currentUser(): PylonUser? = state?.user
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Convenience helper so apps can forward activity results without worrying about
|
|
132
|
+
* request codes. Returns true when the SDK consumed the result.
|
|
133
|
+
*/
|
|
134
|
+
@JvmStatic
|
|
135
|
+
fun handleActivityResult(resultCode: Int, data: Intent?): Boolean {
|
|
136
|
+
return PylonChat.handleActivityResult(resultCode, data)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private fun requireState(): State = state ?: error("Pylon SDK not initialised. Call Pylon.initialize() first.")
|
|
140
|
+
|
|
141
|
+
@Synchronized
|
|
142
|
+
private fun setState(context: Context, config: PylonConfig, user: PylonUser?) {
|
|
143
|
+
state = State(
|
|
144
|
+
appContext = context,
|
|
145
|
+
config = config,
|
|
146
|
+
user = user
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
}
|