cobrowse-sdk-react-native 2.13.0 → 2.15.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.
@@ -0,0 +1,33 @@
1
+ import { useEffect, useState } from 'react'
2
+ import CobrowseIO from './CobrowseIO'
3
+
4
+ export function useSession () {
5
+ const [session, setSession] = useState(null)
6
+
7
+ // initial value
8
+ useEffect(() => {
9
+ let isMounted = true
10
+ const getSession = async () => {
11
+ const session = await CobrowseIO.currentSession()
12
+
13
+ if (isMounted) {
14
+ setSession(session)
15
+ }
16
+ }
17
+
18
+ getSession()
19
+
20
+ return () => {
21
+ isMounted = false
22
+ }
23
+ }, [])
24
+
25
+ // listen to session updates
26
+ useEffect(() => {
27
+ const subscription = CobrowseIO.addListener(CobrowseIO.SESSION_UPDATED, setSession)
28
+
29
+ return () => subscription.remove()
30
+ }, [])
31
+
32
+ return session
33
+ }
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "cobrowse-sdk-react-native",
3
- "version": "2.13.0",
3
+ "version": "2.15.0",
4
4
  "description": "Cobrowse SDK for React Native",
5
5
  "main": "js/index.js",
6
6
  "types": "ts/index.d.ts",
7
7
  "scripts": {
8
- "lint-fix": "ts-standard ts/*.d.ts --fix",
9
- "start:dev": "nodemon --exec ./scripts/copy.sh"
8
+ "lint": "ts-standard",
9
+ "lint:fix": "npm run lint -- --fix",
10
+ "start:dev": "nodemon --exec ./scripts/copy.sh",
11
+ "test:types": "tsc -p tsconfig.eslint.json --noEmit"
10
12
  },
11
13
  "author": {
12
14
  "name": "Andy Pritchard"
@@ -27,17 +29,23 @@
27
29
  ],
28
30
  "license": "Apache-2.0",
29
31
  "optionalDependencies": {
30
- "@types/react": "^18.0.18",
31
- "@types/react-native": "^0.69.6"
32
+ "@types/react": "^18.0.24",
33
+ "@types/react-native": "^0.70.6"
32
34
  },
33
35
  "dependencies": {
34
36
  "lodash": "^4.17.21"
35
37
  },
36
38
  "devDependencies": {
37
- "@types/react": "^18.0.18",
38
- "@types/react-native": "^0.69.6",
39
- "nodemon": "^2.0.19",
40
- "ts-standard": "^11.0.0",
41
- "typescript": "^4.8.2"
39
+ "@types/react": "^18.0.24",
40
+ "@types/react-native": "^0.70.6",
41
+ "nodemon": "^2.0.20",
42
+ "ts-standard": "^12.0.2",
43
+ "typescript": "^4.8.4"
44
+ },
45
+ "ts-standard": {
46
+ "project": "tsconfig.eslint.json",
47
+ "env": [
48
+ "jest"
49
+ ]
42
50
  }
43
51
  }
@@ -0,0 +1,8 @@
1
+ import type { ReactElement } from 'react'
2
+ import type { ViewProps } from 'react-native'
3
+
4
+ type Props = Readonly<{
5
+ buttonColor?: string
6
+ }> & ViewProps
7
+
8
+ export default function (props: Props): ReactElement | null
@@ -1,5 +1,5 @@
1
- import type { Component } from 'react'
2
- import type { View, Text } from 'react-native'
1
+ import type { Component, ReactElement } from 'react'
2
+ import type { ViewProps, TextProps } from 'react-native'
3
3
 
4
4
  export default class CobrowseView extends Component {
5
5
  componentDidMount (): Promise<void>
@@ -8,13 +8,13 @@ export default class CobrowseView extends Component {
8
8
 
9
9
  endSession (): Promise<void>
10
10
 
11
- renderError (): Text
11
+ renderError (): ReactElement<TextProps>
12
12
 
13
- renderCode (): View
13
+ renderCode (): ReactElement<ViewProps>
14
14
 
15
- renderManageSession (): View
15
+ renderManageSession (): ReactElement<ViewProps>
16
16
 
17
- renderContent (): Text | View
17
+ renderContent (): ReactElement<TextProps | ViewProps>
18
18
 
19
- render (): View
19
+ render (): ReactElement<ViewProps>
20
20
  }
package/ts/Redacted.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { ReactNode, ReactElement } from 'react'
2
2
 
3
3
  type Props = Readonly<{}> &
4
- Readonly<{
5
- children?: ReactNode | undefined
6
- }>
4
+ Readonly<{
5
+ children?: ReactNode | undefined
6
+ }>
7
7
 
8
8
  export default function (props: Props): ReactElement | null
package/ts/Session.d.ts CHANGED
@@ -7,6 +7,8 @@ export type SessionState = 'active' | 'authorizing' | 'ended' | 'pending'
7
7
 
8
8
  export type RemoteControlState = 'on' | 'requested' | 'rejected' | 'off'
9
9
 
10
+ export type FullDeviceState = 'on' | 'requested' | 'rejected' | 'off'
11
+
10
12
  export interface Agent {
11
13
  id: string
12
14
  name: string
@@ -50,7 +52,7 @@ export default class Session {
50
52
 
51
53
  isEnded (): boolean
52
54
 
53
- setFullDevice (state: boolean): Promise<void>
55
+ setFullDevice (state: boolean | FullDeviceState): Promise<void>
54
56
 
55
57
  setRemoteControl (state: RemoteControlState): Promise<void>
56
58
  }
@@ -3,12 +3,13 @@ import { View, ScrollView, Text, Image, FlatList, SectionList } from 'react-nati
3
3
 
4
4
  export function useUnredaction<
5
5
  T = View | ScrollView | Text | Image | FlatList | SectionList
6
- >(shouldWarnUnhandledRefs?: boolean , componentName?: string): (elem: T) => void
6
+ > (shouldWarnUnhandledRefs?: boolean, componentName?: string): (elem: T) => void
7
7
 
8
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
9
  type ForwardedRefType<T, P> = typeof React.forwardRef
9
10
 
10
11
  // HOC for adding unredaction to a whole component class
11
- export function unredact(Component: ReactElement): ForwardedRefType<View, Record<string, unknown>>
12
+ export function unredact (Component: ReactElement): ForwardedRefType<View, Record<string, unknown>>
12
13
 
13
14
  // also expose a basic Component based on a View
14
15
  declare const Unredacted: ForwardRefRenderFunction<View, Record<string, unknown>>
package/ts/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export { default as Redacted } from './Redacted'
4
4
  export { default as SessionControl } from './SessionControl'
5
5
  export { default as Unredacted, unredact, useUnredaction } from './Unredacted'
6
6
  export { default as CobrowseAccessibilityService } from './CobrowseAccessibilityService'
7
+ export { useSession } from './useSession'
@@ -0,0 +1,3 @@
1
+ import Session from './Session'
2
+
3
+ export function useSession (): Session | null