-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Berend Sliedrecht <[email protected]>
- Loading branch information
1 parent
b75b7d7
commit c1abff6
Showing
22 changed files
with
297 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,6 @@ | |
"@jridgewell/gen-mapping" "^0.1.0" | ||
"@jridgewell/trace-mapping" "^0.3.9" | ||
|
||
"@animo-id/react-native-ble-didcomm@../": | ||
version "0.0.0" | ||
dependencies: | ||
buffer "6.0.3" | ||
|
||
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.18.6": | ||
version "7.18.6" | ||
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.18.6.tgz#3b25d38c89600baa2dcc219edfa88a74eb2c427a" | ||
|
@@ -1481,14 +1476,6 @@ buffer-from@^1.0.0: | |
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" | ||
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== | ||
|
||
[email protected]: | ||
version "6.0.3" | ||
resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" | ||
integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== | ||
dependencies: | ||
base64-js "^1.3.1" | ||
ieee754 "^1.2.1" | ||
|
||
buffer@^5.5.0: | ||
version "5.7.1" | ||
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0" | ||
|
@@ -2286,7 +2273,7 @@ [email protected]: | |
statuses "2.0.1" | ||
toidentifier "1.0.1" | ||
|
||
ieee754@^1.1.13, ieee754@^1.2.1: | ||
ieee754@^1.1.13: | ||
version "1.2.1" | ||
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" | ||
integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { Central } from './central' | ||
import type { PropsWithChildren } from 'react' | ||
import { useContext } from 'react' | ||
import * as React from 'react' | ||
|
||
interface CentralContextItems { | ||
central: Central | ||
} | ||
|
||
const CentralContext = React.createContext<CentralContextItems | undefined>( | ||
undefined | ||
) | ||
|
||
export const useCentral = () => { | ||
const centralContext = useContext(CentralContext) | ||
if (!centralContext) { | ||
throw new Error('Central hook is not called within the CentralProvider') | ||
} | ||
return centralContext | ||
} | ||
|
||
export const CentralProvider: React.FC< | ||
PropsWithChildren<{ central: Central }> | ||
> = ({ central, children }) => { | ||
return ( | ||
<CentralContext.Provider value={{ central }}> | ||
{children} | ||
</CentralContext.Provider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './useCentralOnConnected' | ||
export * from './useCentralOnDisconnected' | ||
export * from './useCentralOnDiscovered' | ||
export * from './useCentralOnReceivedMessage' | ||
export * from './useCentralShutdownOnUnmount' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useEffect } from 'react' | ||
import { useCentral } from '../CentralProvider' | ||
|
||
export const useCentralOnConnected = ( | ||
cb: (identifier: string) => void | Promise<void> | ||
) => { | ||
const { central } = useCentral() | ||
|
||
useEffect(() => { | ||
const listener = central.registerOnConnectedListener(({ identifier }) => | ||
cb(identifier) | ||
) | ||
|
||
return () => { | ||
listener.remove() | ||
} | ||
}, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useEffect } from 'react' | ||
import { useCentral } from '../CentralProvider' | ||
|
||
export const useCentralOnDisconnected = ( | ||
cb: (identifier: string) => void | Promise<void> | ||
) => { | ||
const { central } = useCentral() | ||
|
||
useEffect(() => { | ||
const listener = central.registerOnDisconnectedListener(({ identifier }) => | ||
cb(identifier) | ||
) | ||
|
||
return () => { | ||
listener.remove() | ||
} | ||
}, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useEffect } from 'react' | ||
import { useCentral } from '../CentralProvider' | ||
|
||
export const useCentralOnDiscovered = ( | ||
cb: (identifier: string) => void | Promise<void> | ||
) => { | ||
const { central } = useCentral() | ||
|
||
useEffect(() => { | ||
const listener = central.registerOnDiscoveredListener(({ identifier }) => | ||
cb(identifier) | ||
) | ||
|
||
return () => { | ||
listener.remove() | ||
} | ||
}, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useEffect } from 'react' | ||
import { useCentral } from '../CentralProvider' | ||
|
||
export const useCentralOnReceivedMessage = ( | ||
cb: (message: string) => void | Promise<void> | ||
) => { | ||
const { central } = useCentral() | ||
|
||
useEffect(() => { | ||
const listener = central.registerMessageListener(({ message }) => | ||
cb(message) | ||
) | ||
|
||
return () => { | ||
listener.remove() | ||
} | ||
}, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useEffect } from 'react' | ||
import { useCentral } from '../CentralProvider' | ||
|
||
export const useCentralShutdownOnUnmount = () => { | ||
const { central } = useCentral() | ||
|
||
useEffect(() => { | ||
return () => { | ||
void central.shutdown() | ||
} | ||
}, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './hooks' | ||
export * from './central' | ||
export * from './CentralProvider' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Peripheral } from './peripheral' | ||
import type { PropsWithChildren } from 'react' | ||
import { useContext } from 'react' | ||
import * as React from 'react' | ||
|
||
interface PeripheralContextItems { | ||
peripheral: Peripheral | ||
} | ||
|
||
const PeripheralContext = React.createContext< | ||
PeripheralContextItems | undefined | ||
>(undefined) | ||
|
||
export const usePeripheral = () => { | ||
const peripheralContext = useContext(PeripheralContext) | ||
if (!peripheralContext) { | ||
throw new Error( | ||
'Peripheral hook is not called within the PeripheralProvider' | ||
) | ||
} | ||
return peripheralContext | ||
} | ||
|
||
export const PeripheralProvider: React.FC< | ||
PropsWithChildren<{ peripheral: Peripheral }> | ||
> = ({ peripheral, children }) => { | ||
return ( | ||
<PeripheralContext.Provider value={{ peripheral }}> | ||
{children} | ||
</PeripheralContext.Provider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './usePeripheralOnReceivedMessage' | ||
export * from './usePeripheralOnDisconnected' | ||
export * from './usePeripheralOnConnected' | ||
export * from './usePeripheralShutdownOnUnmount' |
Oops, something went wrong.