-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathWebSocketClientModule.kt
More file actions
82 lines (68 loc) · 3 KB
/
WebSocketClientModule.kt
File metadata and controls
82 lines (68 loc) · 3 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.mattermost.networkclient
import com.facebook.fbreact.specs.NativeWebSocketClientSpec
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableMap
internal class WebSocketClientModule(reactContext: ReactApplicationContext) : NativeWebSocketClientSpec(reactContext) {
private var implementation: WebSocketClientModuleImpl = WebSocketClientModuleImpl(reactContext)
override fun getName(): String = WebSocketClientModuleImpl.NAME
override fun invalidate() {
super.invalidate()
implementation.invalidate()
}
override fun addListener(eventType: String?) {
// Keep: Required for RN built in Event Emitter Calls
}
override fun removeListeners(count: Double) {
// Keep: Required for RN built in Event Emitter Calls
}
override fun ensureClientFor(url: String?, config: ReadableMap?, promise: Promise?) {
if (url.isNullOrEmpty() || config == null || promise == null) {
promise?.reject(Exception("missing parameter to create client"))
return
}
implementation.ensureClientFor(url, config, promise)
}
override fun createClientFor(url: String?, config: ReadableMap?, promise: Promise?) {
if (url.isNullOrEmpty() || config == null || promise == null) {
promise?.reject(Exception("missing parameter to create client"))
return
}
implementation.createClientFor(url, config, promise)
}
override fun connectFor(url: String?, promise: Promise?) {
if (url.isNullOrEmpty() || promise == null) {
promise?.reject(Exception("missing parameter to connect client"))
return
}
implementation.connectFor(url, promise)
}
override fun disconnectFor(url: String?, promise: Promise?) {
if (url.isNullOrEmpty() || promise == null) {
promise?.reject(Exception("missing parameter to disconnect client"))
return
}
implementation.disconnectFor(url, promise)
}
override fun sendDataFor(url: String?, data: String?, promise: Promise?) {
if (url.isNullOrEmpty() || data.isNullOrEmpty() || promise == null) {
promise?.reject(Exception("missing parameter to send data"))
return
}
implementation.sendDataFor(url, data, promise)
}
override fun invalidateClientFor(url: String?, promise: Promise?) {
if (url.isNullOrEmpty() || promise == null) {
promise?.reject(Exception("missing parameter to invalidate client"))
return
}
implementation.invalidateClientFor(url, promise)
}
override fun sendBinaryDataFor(url: String?, data: String?, promise: Promise?) {
if (url.isNullOrEmpty() || data.isNullOrEmpty() || promise == null) {
promise?.reject(Exception("missing parameter to send binary data"))
return
}
implementation.sendBinaryDataFor(url, data, promise)
}
}