cobrowse-sdk-react-native 2.15.0 → 2.17.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/.github/workflows/lint.yaml +0 -2
- package/android/build.gradle +1 -1
- package/android/src/main/java/io/cobrowse/reactnative/CobrowseIOModule.java +36 -0
- package/cobrowse-sdk-react-native.podspec +1 -1
- package/ios/RCTCobrowseIO.m +8 -0
- package/js/CBIOBroadcastPickerView.tsx +15 -0
- package/js/CobrowseAccessibilityService.ts +15 -0
- package/js/CobrowseIO.ts +161 -0
- package/js/CobrowseView.tsx +150 -0
- package/js/{Redacted.js → Redacted.tsx} +3 -2
- package/js/Session.ts +128 -0
- package/js/SessionControl.ts +38 -0
- package/js/Unredacted.tsx +106 -0
- package/js/{index.js → index.ts} +1 -0
- package/js/{useSession.js → useSession.ts} +5 -4
- package/lib/commonjs/CBIOBroadcastPickerView.js +15 -0
- package/lib/commonjs/CBIOBroadcastPickerView.js.map +1 -0
- package/lib/commonjs/CobrowseAccessibilityService.js +22 -0
- package/lib/commonjs/CobrowseAccessibilityService.js.map +1 -0
- package/lib/commonjs/CobrowseIO.js +154 -0
- package/lib/commonjs/CobrowseIO.js.map +1 -0
- package/lib/commonjs/CobrowseView.js +146 -0
- package/lib/commonjs/CobrowseView.js.map +1 -0
- package/lib/commonjs/Redacted.js +14 -0
- package/lib/commonjs/Redacted.js.map +1 -0
- package/lib/commonjs/Session.js +100 -0
- package/lib/commonjs/Session.js.map +1 -0
- package/lib/commonjs/SessionControl.js +39 -0
- package/lib/commonjs/SessionControl.js.map +1 -0
- package/lib/commonjs/Unredacted.js +82 -0
- package/lib/commonjs/Unredacted.js.map +1 -0
- package/lib/commonjs/index.js +77 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/useSession.js +35 -0
- package/lib/commonjs/useSession.js.map +1 -0
- package/lib/module/CBIOBroadcastPickerView.js +8 -0
- package/lib/module/CBIOBroadcastPickerView.js.map +1 -0
- package/lib/module/CobrowseAccessibilityService.js +13 -0
- package/lib/module/CobrowseAccessibilityService.js.map +1 -0
- package/lib/module/CobrowseIO.js +146 -0
- package/lib/module/CobrowseIO.js.map +1 -0
- package/lib/module/CobrowseView.js +136 -0
- package/lib/module/CobrowseView.js.map +1 -0
- package/lib/module/Redacted.js +7 -0
- package/lib/module/Redacted.js.map +1 -0
- package/lib/module/Session.js +93 -0
- package/lib/module/Session.js.map +1 -0
- package/lib/module/SessionControl.js +31 -0
- package/lib/module/SessionControl.js.map +1 -0
- package/lib/module/Unredacted.js +71 -0
- package/lib/module/Unredacted.js.map +1 -0
- package/lib/module/index.js +9 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/useSession.js +28 -0
- package/lib/module/useSession.js.map +1 -0
- package/lib/typescript/CBIOBroadcastPickerView.d.ts +8 -0
- package/lib/typescript/CBIOBroadcastPickerView.d.ts.map +1 -0
- package/lib/typescript/CobrowseAccessibilityService.d.ts +8 -0
- package/lib/typescript/CobrowseAccessibilityService.d.ts.map +1 -0
- package/lib/typescript/CobrowseIO.d.ts +31 -0
- package/lib/typescript/CobrowseIO.d.ts.map +1 -0
- package/lib/typescript/CobrowseView.d.ts +25 -0
- package/lib/typescript/CobrowseView.d.ts.map +1 -0
- package/lib/typescript/Redacted.d.ts +4 -0
- package/lib/typescript/Redacted.d.ts.map +1 -0
- package/lib/typescript/Session.d.ts +42 -0
- package/lib/typescript/Session.d.ts.map +1 -0
- package/lib/typescript/SessionControl.d.ts +17 -0
- package/lib/typescript/SessionControl.d.ts.map +1 -0
- package/lib/typescript/Unredacted.d.ts +10 -0
- package/lib/typescript/Unredacted.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +10 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/useSession.d.ts +3 -0
- package/lib/typescript/useSession.d.ts.map +1 -0
- package/package.json +25 -4
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +28 -0
- package/js/CBIOBroadcastPickerView.js +0 -11
- package/js/CobrowseAccessibilityService.js +0 -11
- package/js/CobrowseIO.js +0 -145
- package/js/CobrowseView.js +0 -129
- package/js/Session.js +0 -107
- package/js/SessionControl.js +0 -26
- package/js/Unredacted.js +0 -82
- package/ts/CBIOBroadcastPickerView.d.ts +0 -8
- package/ts/CobrowseAccessibilityService.d.ts +0 -6
- package/ts/CobrowseIO.d.ts +0 -29
- package/ts/CobrowseView.d.ts +0 -20
- package/ts/Redacted.d.ts +0 -8
- package/ts/Session.d.ts +0 -58
- package/ts/SessionControl.d.ts +0 -9
- package/ts/Unredacted.d.ts +0 -16
- package/ts/index.d.ts +0 -7
- package/ts/useSession.d.ts +0 -3
package/js/CobrowseIO.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { Platform, Alert } from 'react-native'
|
|
2
|
-
import Session from './Session'
|
|
3
|
-
const CobrowseIONative = require('react-native').NativeModules.CobrowseIO
|
|
4
|
-
const NativeEventEmitter = require('react-native').NativeEventEmitter
|
|
5
|
-
|
|
6
|
-
const emitter = new NativeEventEmitter(CobrowseIONative)
|
|
7
|
-
|
|
8
|
-
export default class CobrowseIO {
|
|
9
|
-
/** @deprecated */
|
|
10
|
-
static get SESSION_UPDATED () {
|
|
11
|
-
return 'session.updated'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** @deprecated */
|
|
15
|
-
static get SESSION_ENDED () {
|
|
16
|
-
return 'session.ended'
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static handleSessionRequest (session) {
|
|
20
|
-
if (this._sessionRequestShown) return
|
|
21
|
-
this._sessionRequestShown = true
|
|
22
|
-
Alert.alert(
|
|
23
|
-
'Support Request',
|
|
24
|
-
'A support agent would like to use this app with you. Do you accept?',
|
|
25
|
-
[{
|
|
26
|
-
text: 'Reject',
|
|
27
|
-
onPress: () => {
|
|
28
|
-
this._sessionRequestShown = false
|
|
29
|
-
session.end()
|
|
30
|
-
},
|
|
31
|
-
style: 'cancel'
|
|
32
|
-
}, {
|
|
33
|
-
text: 'Accept',
|
|
34
|
-
onPress: () => {
|
|
35
|
-
this._sessionRequestShown = false
|
|
36
|
-
session.activate()
|
|
37
|
-
}
|
|
38
|
-
}], { cancelable: false })
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static handleRemoteControlRequest (session) {
|
|
42
|
-
if (this._remoteControlRequestShown) return
|
|
43
|
-
this._remoteControlRequestShown = true
|
|
44
|
-
Alert.alert(
|
|
45
|
-
'Remote Control Request',
|
|
46
|
-
'A support agent would like to take remote control of this app. Do you accept?',
|
|
47
|
-
[{
|
|
48
|
-
text: 'Reject',
|
|
49
|
-
onPress: () => {
|
|
50
|
-
this._remoteControlRequestShown = false
|
|
51
|
-
session.setRemoteControl('rejected')
|
|
52
|
-
},
|
|
53
|
-
style: 'cancel'
|
|
54
|
-
}, {
|
|
55
|
-
text: 'Accept',
|
|
56
|
-
onPress: () => {
|
|
57
|
-
this._remoteControlRequestShown = false
|
|
58
|
-
session.setRemoteControl('on')
|
|
59
|
-
}
|
|
60
|
-
}], { cancelable: false })
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
static addListener (event, cb) {
|
|
64
|
-
return emitter.addListener(event, (session) => cb(new Session(session)))
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static start () {
|
|
68
|
-
return CobrowseIONative.start()
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
static stop () {
|
|
72
|
-
return CobrowseIONative.stop()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// eslint-disable-next-line accessor-pairs
|
|
76
|
-
static set api (api) {
|
|
77
|
-
CobrowseIONative.api(api)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// eslint-disable-next-line accessor-pairs
|
|
81
|
-
static set license (license) {
|
|
82
|
-
CobrowseIONative.license(license)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// eslint-disable-next-line accessor-pairs
|
|
86
|
-
static set customData (customData) {
|
|
87
|
-
CobrowseIONative.customData(customData)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// eslint-disable-next-line accessor-pairs
|
|
91
|
-
static set deviceToken (token) {
|
|
92
|
-
CobrowseIONative.deviceToken(token)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
static currentSession () {
|
|
96
|
-
return CobrowseIONative.currentSession().then((session) => session ? new Session(session) : null)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
static createSession () {
|
|
100
|
-
return CobrowseIONative.createSession().then((session) => session ? new Session(session) : null)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
static getSession (codeOrId) {
|
|
104
|
-
return CobrowseIONative.getSession(codeOrId).then((session) => session ? new Session(session) : null)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** @deprecated */
|
|
108
|
-
static activateSession () {
|
|
109
|
-
return CobrowseIONative.activateSession().then((session) => session ? new Session(session) : null)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** @deprecated */
|
|
113
|
-
static endSession () {
|
|
114
|
-
return CobrowseIONative.endSession()
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// the session.requested event is considered internal, it should
|
|
119
|
-
// not be used outside these bindings
|
|
120
|
-
CobrowseIO.addListener('session.requested', (session) => {
|
|
121
|
-
if (CobrowseIO.showSessionControls === false) {
|
|
122
|
-
CobrowseIONative.overwriteSessionIndicator()
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (Platform.OS === 'ios' && CobrowseIO.handleFullDeviceRequest) {
|
|
126
|
-
CobrowseIONative.overwriteFullControlUI()
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
CobrowseIO.handleSessionRequest(session)
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
CobrowseIO.addListener('session.updated', (session) => {
|
|
133
|
-
if (session.isActive() && session.remote_control === 'requested') {
|
|
134
|
-
CobrowseIO.handleRemoteControlRequest(session)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (session.isActive() && session.full_device_state === 'requested') {
|
|
138
|
-
if (CobrowseIO.handleFullDeviceRequest) {
|
|
139
|
-
CobrowseIO.handleFullDeviceRequest(session)
|
|
140
|
-
} else if (Platform.OS === 'android') {
|
|
141
|
-
// accept the incoming connection by default
|
|
142
|
-
session.setFullDevice('on')
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
})
|
package/js/CobrowseView.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react'
|
|
2
|
-
import {
|
|
3
|
-
View,
|
|
4
|
-
Text,
|
|
5
|
-
ActivityIndicator,
|
|
6
|
-
TouchableOpacity,
|
|
7
|
-
StyleSheet
|
|
8
|
-
} from 'react-native'
|
|
9
|
-
import CobrowseIO from './CobrowseIO'
|
|
10
|
-
|
|
11
|
-
const styles = StyleSheet.create({
|
|
12
|
-
container: {
|
|
13
|
-
flex: 1,
|
|
14
|
-
justifyContent: 'flex-end'
|
|
15
|
-
},
|
|
16
|
-
text: {
|
|
17
|
-
textAlign: 'center',
|
|
18
|
-
margin: 15,
|
|
19
|
-
fontSize: 15,
|
|
20
|
-
lineHeight: 20
|
|
21
|
-
},
|
|
22
|
-
code: {
|
|
23
|
-
fontSize: 29,
|
|
24
|
-
padding: 20,
|
|
25
|
-
fontWeight: 'bold',
|
|
26
|
-
textAlign: 'center'
|
|
27
|
-
},
|
|
28
|
-
button: {
|
|
29
|
-
color: 'rgb(0, 122, 255)',
|
|
30
|
-
fontSize: 18,
|
|
31
|
-
margin: 10
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
export default class CobrowseView extends Component {
|
|
36
|
-
constructor () {
|
|
37
|
-
super()
|
|
38
|
-
this.state = { error: null, session: null }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async componentDidMount () {
|
|
42
|
-
if (this.props.license) {
|
|
43
|
-
console.warn('Passing license to view is deprecated. Use CobrowseIO.license = "..." instead')
|
|
44
|
-
CobrowseIO.license = this.props.license
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
const current = await CobrowseIO.currentSession()
|
|
49
|
-
if (current) this.setState({ session: current })
|
|
50
|
-
else {
|
|
51
|
-
const session = await CobrowseIO.createSession()
|
|
52
|
-
this.setState({ session })
|
|
53
|
-
}
|
|
54
|
-
} catch (error) {
|
|
55
|
-
this.setState({ error })
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
this.updateListener = CobrowseIO.addListener('session.updated', (session) => {
|
|
59
|
-
this.setState({ session })
|
|
60
|
-
})
|
|
61
|
-
this.endListener = CobrowseIO.addListener('session.ended', (session) => {
|
|
62
|
-
if (this.props.onEnded) this.props.onEnded()
|
|
63
|
-
this.setState({ session: null })
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
componentWillUnmount () {
|
|
68
|
-
if (this.updateListener) this.updateListener.remove()
|
|
69
|
-
if (this.endListener) this.endListener.remove()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async endSession () {
|
|
73
|
-
try {
|
|
74
|
-
const { session } = this.state
|
|
75
|
-
await session.end()
|
|
76
|
-
this.setState({ session: null })
|
|
77
|
-
} catch (error) {
|
|
78
|
-
this.setState({ error })
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
renderError () {
|
|
83
|
-
return (
|
|
84
|
-
<Text style={[styles.text]}>{this.state.error.message}</Text>
|
|
85
|
-
)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
renderCode () {
|
|
89
|
-
let code = this.state.session && this.state.session.code
|
|
90
|
-
if (code) code = code.substr(0, 3) + '-' + code.substr(3)
|
|
91
|
-
return (
|
|
92
|
-
<View>
|
|
93
|
-
<Text style={[styles.code, { opacity: code ? 1 : 0.2 }]}>{code || '000-000'}</Text>
|
|
94
|
-
<Text style={[styles.text]}>Provide this code to your support agent to begin screen sharing.</Text>
|
|
95
|
-
<ActivityIndicator />
|
|
96
|
-
</View>
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
renderManageSession () {
|
|
101
|
-
return (
|
|
102
|
-
<View>
|
|
103
|
-
<Text style={[styles.text]}>You're sharing screens from this app with a support agent.</Text>
|
|
104
|
-
<TouchableOpacity onPress={() => this.endSession()}>
|
|
105
|
-
<Text style={[styles.text, styles.button]}>End Session</Text>
|
|
106
|
-
</TouchableOpacity>
|
|
107
|
-
</View>
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
renderContent () {
|
|
112
|
-
const { error, session } = this.state
|
|
113
|
-
if (error) {
|
|
114
|
-
return this.renderError()
|
|
115
|
-
} else if ((!session) || (session.state === 'pending' || session.state === 'authorizing')) {
|
|
116
|
-
return this.renderCode()
|
|
117
|
-
} else {
|
|
118
|
-
return this.renderManageSession()
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
render () {
|
|
123
|
-
return (
|
|
124
|
-
<View style={styles.container}>
|
|
125
|
-
{this.renderContent()}
|
|
126
|
-
</View>
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
}
|
package/js/Session.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
const CobrowseIONative = require('react-native').NativeModules.CobrowseIO
|
|
2
|
-
const NativeEventEmitter = require('react-native').NativeEventEmitter
|
|
3
|
-
|
|
4
|
-
const emitter = new NativeEventEmitter(CobrowseIONative)
|
|
5
|
-
|
|
6
|
-
export default class Session {
|
|
7
|
-
constructor (session) {
|
|
8
|
-
this._session = session || {}
|
|
9
|
-
this._listen()
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
_update (session, onMatch) {
|
|
13
|
-
if (this._session.id === undefined || (session && this._session.id === session.id)) {
|
|
14
|
-
this._session = session
|
|
15
|
-
if (typeof onMatch === 'function') onMatch()
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
_listen () {
|
|
20
|
-
const updates = emitter.addListener('session.updated', (session) => this._update(session))
|
|
21
|
-
const ended = emitter.addListener('session.ended', (session) => {
|
|
22
|
-
this._update(session, () => {
|
|
23
|
-
updates.remove()
|
|
24
|
-
ended.remove()
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
addListener (eventType, listener) {
|
|
30
|
-
// TODO: this class should extend EventEmitter and forward
|
|
31
|
-
// on the non-namespaced versions of these events
|
|
32
|
-
switch (eventType) {
|
|
33
|
-
case 'ended':
|
|
34
|
-
eventType = 'session.updated'
|
|
35
|
-
break
|
|
36
|
-
case 'updated':
|
|
37
|
-
eventType = 'session.ended'
|
|
38
|
-
break
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return emitter.addListener(eventType, (session) => {
|
|
42
|
-
this._update(session, () => {
|
|
43
|
-
listener(this)
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get id () {
|
|
49
|
-
return this._session.id
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
get code () {
|
|
53
|
-
return this._session.code
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get state () {
|
|
57
|
-
return this._session.state
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get full_device () {
|
|
61
|
-
return this._session.full_device
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
get full_device_state () {
|
|
65
|
-
return this._session.full_device_state
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
get remote_control () {
|
|
69
|
-
return this._session.remote_control
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get agent () {
|
|
73
|
-
return this._session.agent
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
activate () {
|
|
77
|
-
return CobrowseIONative.activateSession().then(() => {})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
end () {
|
|
81
|
-
return CobrowseIONative.endSession()
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
isActive () {
|
|
85
|
-
return this._session.state === 'active'
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
isAuthorizing () {
|
|
89
|
-
return this._session.state === 'authorizing'
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
isPending () {
|
|
93
|
-
return this._session.state === 'pending'
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
isEnded () {
|
|
97
|
-
return this._session.state === 'ended'
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
setFullDevice (state) {
|
|
101
|
-
return CobrowseIONative.updateSession({ full_device: state })
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
setRemoteControl (state) {
|
|
105
|
-
return CobrowseIONative.updateSession({ remote_control: state })
|
|
106
|
-
}
|
|
107
|
-
}
|
package/js/SessionControl.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import CobrowseIO from './CobrowseIO'
|
|
3
|
-
|
|
4
|
-
export default class SessionControl extends React.Component {
|
|
5
|
-
constructor () {
|
|
6
|
-
super()
|
|
7
|
-
this.state = { session: null }
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async componentDidMount () {
|
|
11
|
-
this.setState({ session: await CobrowseIO.currentSession() })
|
|
12
|
-
this.updateListener = CobrowseIO.addListener(CobrowseIO.SESSION_UPDATED, (session) => {
|
|
13
|
-
this.setState({ session })
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
componentWillUnmount () {
|
|
18
|
-
if (this.updateListener) this.updateListener.remove()
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
render () {
|
|
22
|
-
const { session } = this.state
|
|
23
|
-
if (session && session.isActive()) return this.props.children
|
|
24
|
-
else return null
|
|
25
|
-
}
|
|
26
|
-
}
|
package/js/Unredacted.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useEffect, useCallback, useMemo } from 'react'
|
|
2
|
-
import { View, findNodeHandle } from 'react-native'
|
|
3
|
-
import { throttle } from 'lodash'
|
|
4
|
-
const CobrowseIONative = require('react-native').NativeModules.CobrowseIO
|
|
5
|
-
|
|
6
|
-
function mergeRefs (refs) {
|
|
7
|
-
return (value) => {
|
|
8
|
-
refs.forEach((ref) => {
|
|
9
|
-
if (typeof ref === 'function') {
|
|
10
|
-
ref(value)
|
|
11
|
-
} else if (ref != null) {
|
|
12
|
-
ref.current = value
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const unredactedTags = new Set()
|
|
19
|
-
const sendUnredactionUpdates = throttle(() => {
|
|
20
|
-
CobrowseIONative.setUnredactedTags([...unredactedTags])
|
|
21
|
-
}, 50, { leading: false })
|
|
22
|
-
|
|
23
|
-
const removeUnredactedView = (view) => {
|
|
24
|
-
if (view) {
|
|
25
|
-
unredactedTags.delete(view)
|
|
26
|
-
sendUnredactionUpdates()
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const useUnredaction = (shouldWarnUnhandledRefs = true, componentName = '') => {
|
|
31
|
-
const ref = useRef(null)
|
|
32
|
-
|
|
33
|
-
const setRef = useCallback((node) => {
|
|
34
|
-
let hasRemovedRef = false
|
|
35
|
-
if (ref.current) {
|
|
36
|
-
hasRemovedRef = true
|
|
37
|
-
removeUnredactedView(ref.current)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (node) {
|
|
41
|
-
const view = findNodeHandle(node)
|
|
42
|
-
|
|
43
|
-
if (view) {
|
|
44
|
-
unredactedTags.add(view)
|
|
45
|
-
sendUnredactionUpdates()
|
|
46
|
-
|
|
47
|
-
ref.current = view
|
|
48
|
-
} else {
|
|
49
|
-
console.warn(`Failed to apply unredact() to ${componentName} due to view not found`)
|
|
50
|
-
}
|
|
51
|
-
} else if (!hasRemovedRef) {
|
|
52
|
-
console.warn(
|
|
53
|
-
`Failed to apply unredact() to ${componentName} due to null node handle – make sure you are forwarding refs`
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
}, [])
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
if (shouldWarnUnhandledRefs && !ref.current) {
|
|
60
|
-
console.warn(
|
|
61
|
-
`Failed to apply unredact() to ${componentName} due to null node handle – make sure the setRef function is called with the ref`
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return () => removeUnredactedView(ref.current)
|
|
66
|
-
}, [])
|
|
67
|
-
|
|
68
|
-
return setRef
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// HOC for adding unredaction to a whole component class
|
|
72
|
-
export function unredact (Component) {
|
|
73
|
-
return React.forwardRef(function Redacted (props, ref) {
|
|
74
|
-
const localRef = useUnredaction(true, Component?.name)
|
|
75
|
-
const refs = useMemo(() => mergeRefs([localRef, ref]), [localRef, ref])
|
|
76
|
-
return <Component {...props} collapsable={false} ref={refs} />
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// also expose a basic Component based on a View
|
|
81
|
-
const Unredacted = unredact(View)
|
|
82
|
-
export default Unredacted
|
package/ts/CobrowseIO.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-extraneous-class,accessor-pairs */
|
|
2
|
-
import type { EmitterSubscription } from 'react-native'
|
|
3
|
-
import Session from './Session'
|
|
4
|
-
|
|
5
|
-
export type NativeSessionEvent = 'session.updated' | 'session.ended'
|
|
6
|
-
|
|
7
|
-
export default class CobrowseIO {
|
|
8
|
-
static handleSessionRequest (session?: Session): void
|
|
9
|
-
|
|
10
|
-
static addListener (eventType: NativeSessionEvent, listener: (session: Session) => void): EmitterSubscription
|
|
11
|
-
|
|
12
|
-
static start (): void
|
|
13
|
-
|
|
14
|
-
static stop (): void
|
|
15
|
-
|
|
16
|
-
static set api (api: string)
|
|
17
|
-
|
|
18
|
-
static set license (license: string)
|
|
19
|
-
|
|
20
|
-
static set customData (customData: Record<string, any>)
|
|
21
|
-
|
|
22
|
-
static set deviceToken (token: string)
|
|
23
|
-
|
|
24
|
-
static currentSession (): Promise<Session>
|
|
25
|
-
|
|
26
|
-
static createSession (): Promise<Session>
|
|
27
|
-
|
|
28
|
-
static getSession (codeOrId: string): Promise<Session>
|
|
29
|
-
}
|
package/ts/CobrowseView.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Component, ReactElement } from 'react'
|
|
2
|
-
import type { ViewProps, TextProps } from 'react-native'
|
|
3
|
-
|
|
4
|
-
export default class CobrowseView extends Component {
|
|
5
|
-
componentDidMount (): Promise<void>
|
|
6
|
-
|
|
7
|
-
componentWillUnmount (): void
|
|
8
|
-
|
|
9
|
-
endSession (): Promise<void>
|
|
10
|
-
|
|
11
|
-
renderError (): ReactElement<TextProps>
|
|
12
|
-
|
|
13
|
-
renderCode (): ReactElement<ViewProps>
|
|
14
|
-
|
|
15
|
-
renderManageSession (): ReactElement<ViewProps>
|
|
16
|
-
|
|
17
|
-
renderContent (): ReactElement<TextProps | ViewProps>
|
|
18
|
-
|
|
19
|
-
render (): ReactElement<ViewProps>
|
|
20
|
-
}
|
package/ts/Redacted.d.ts
DELETED
package/ts/Session.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-extraneous-class,accessor-pairs */
|
|
2
|
-
import type { EmitterSubscription } from 'react-native'
|
|
3
|
-
|
|
4
|
-
export type SessionEvent = 'updated' | 'ended'
|
|
5
|
-
|
|
6
|
-
export type SessionState = 'active' | 'authorizing' | 'ended' | 'pending'
|
|
7
|
-
|
|
8
|
-
export type RemoteControlState = 'on' | 'requested' | 'rejected' | 'off'
|
|
9
|
-
|
|
10
|
-
export type FullDeviceState = 'on' | 'requested' | 'rejected' | 'off'
|
|
11
|
-
|
|
12
|
-
export interface Agent {
|
|
13
|
-
id: string
|
|
14
|
-
name: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface SessionLike {
|
|
18
|
-
id: string
|
|
19
|
-
code: string
|
|
20
|
-
state: SessionState
|
|
21
|
-
full_device: boolean
|
|
22
|
-
remote_control: RemoteControlState
|
|
23
|
-
agent: Agent
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default class Session {
|
|
27
|
-
constructor (sessionLike: SessionLike)
|
|
28
|
-
|
|
29
|
-
addListener (eventType: SessionEvent, listener: (session: Session) => void): EmitterSubscription
|
|
30
|
-
|
|
31
|
-
get id (): string
|
|
32
|
-
|
|
33
|
-
get code (): string
|
|
34
|
-
|
|
35
|
-
get state (): SessionState
|
|
36
|
-
|
|
37
|
-
get full_device (): boolean
|
|
38
|
-
|
|
39
|
-
get remote_control (): RemoteControlState
|
|
40
|
-
|
|
41
|
-
get agent (): Agent
|
|
42
|
-
|
|
43
|
-
activate (): Promise<void>
|
|
44
|
-
|
|
45
|
-
end (): Promise<void>
|
|
46
|
-
|
|
47
|
-
isActive (): boolean
|
|
48
|
-
|
|
49
|
-
isAuthorizing (): boolean
|
|
50
|
-
|
|
51
|
-
isPending (): boolean
|
|
52
|
-
|
|
53
|
-
isEnded (): boolean
|
|
54
|
-
|
|
55
|
-
setFullDevice (state: boolean | FullDeviceState): Promise<void>
|
|
56
|
-
|
|
57
|
-
setRemoteControl (state: RemoteControlState): Promise<void>
|
|
58
|
-
}
|
package/ts/SessionControl.d.ts
DELETED
package/ts/Unredacted.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React, { ReactElement, ForwardRefRenderFunction } from 'react'
|
|
2
|
-
import { View, ScrollView, Text, Image, FlatList, SectionList } from 'react-native'
|
|
3
|
-
|
|
4
|
-
export function useUnredaction<
|
|
5
|
-
T = View | ScrollView | Text | Image | FlatList | SectionList
|
|
6
|
-
> (shouldWarnUnhandledRefs?: boolean, componentName?: string): (elem: T) => void
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
-
type ForwardedRefType<T, P> = typeof React.forwardRef
|
|
10
|
-
|
|
11
|
-
// HOC for adding unredaction to a whole component class
|
|
12
|
-
export function unredact (Component: ReactElement): ForwardedRefType<View, Record<string, unknown>>
|
|
13
|
-
|
|
14
|
-
// also expose a basic Component based on a View
|
|
15
|
-
declare const Unredacted: ForwardRefRenderFunction<View, Record<string, unknown>>
|
|
16
|
-
export default Unredacted
|
package/ts/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default } from './CobrowseIO'
|
|
2
|
-
export { default as CobrowseView } from './CobrowseView'
|
|
3
|
-
export { default as Redacted } from './Redacted'
|
|
4
|
-
export { default as SessionControl } from './SessionControl'
|
|
5
|
-
export { default as Unredacted, unredact, useUnredaction } from './Unredacted'
|
|
6
|
-
export { default as CobrowseAccessibilityService } from './CobrowseAccessibilityService'
|
|
7
|
-
export { useSession } from './useSession'
|
package/ts/useSession.d.ts
DELETED