-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (52 loc) · 1.68 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
import {
NativeModules, NativeEventEmitter,
} from 'react-native'
const { ARArgyleSdk } = NativeModules
// export default class ArgyleSdk {
class ArgyleSdk {
static errorCodes = {
NO_CONNECTION: 'NO_CONNECTION',
SERVER_ERROR: 'SERVER_ERROR',
EXPIRED_TOKEN: 'EXPIRED_TOKEN',
}
static eventsEmitter = new NativeEventEmitter(ARArgyleSdk)
static listeners = {}
static loginWith(pluginKey, apiHost, _token) {
let token = _token || ""
ARArgyleSdk.loginWith(pluginKey, apiHost, token)
}
static start() {
ARArgyleSdk.start()
}
static updateToken(newToken) {
ARArgyleSdk.updateToken(newToken)
}
static dataPartners(availablePartnersList) {
ARArgyleSdk.dataPartners(availablePartnersList)
}
static removeListenerIfAdded(key) {
if (ArgyleSdk.listeners[key]) {
ArgyleSdk.eventsEmitter.removeListener(key, ArgyleSdk.listeners[key])
}
}
static addListener(key, callback) {
ArgyleSdk.removeListenerIfAdded(key)
ArgyleSdk.listeners[key] = ArgyleSdk.eventsEmitter.addListener(key, callback)
}
static onAccountConnected(callback) {
ArgyleSdk.addListener("onAccountConnected", callback)
}
static onAccountRemoved(callback) {
ArgyleSdk.addListener("onAccountRemoved", callback)
}
static onUserCreated(callback) {
ArgyleSdk.addListener("onUserCreated", callback)
}
static onError(callback) {
ArgyleSdk.addListener("onError", res => callback(res.error))
}
static onTokenExpired(callback) {
ArgyleSdk.addListener("onTokenExpired", callback)
}
}
module.exports = ArgyleSdk