You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document contains detailed instructions on including Viam in your Node project. For a runnable example, see the [examples directory](/examples/node/).
4
+
5
+
## Requirements
6
+
7
+
This document assumes you already have Node installed. If not, follow the [instructions](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs) provided by Node.
8
+
9
+
### Dependencies
10
+
11
+
In addition to the Viam SDK, the following direct dependencies are requires:
12
+
13
+
-`@connectrpc/connect-node`
14
+
-`node-datachannel`
15
+
16
+
You can use either Yarn or NPM to install the dependencies. This document will use NPM, but either will work.
Using the SDK with Node also requires the use of some polyfills. In your application's entrypoint (`main.ts`, `index.ts`, or something similar), you will need to register those polyfills:
23
+
24
+
```ts
25
+
// main.ts
26
+
27
+
importwrtc=require('node-datachannel/polyfill');
28
+
for (const key inwrtc) {
29
+
(globalasany)[key] = (wrtcasany)[key];
30
+
}
31
+
```
32
+
33
+
### Transport
34
+
35
+
Communicating with your Viam machine in Node requires the use of a custom transport. In your app's entrypoint, you will also need to register the custom transport:
To use the SDK, you can use similar instructions to those found on the [documentation site](https://docs.viam.com/build/program/). Below is an example of how you could use the SDK to display a list of resources on the connected device:
In the above example, it is assumed that certain environment variables are set (`HOST`, `API_KEY_ID`, and `API_KEY_SECRET`). You can set those in the process or have a `.env` file set them automatically. If you use a `.env.` file, be sure to exclude it from version control.
Viam's React Native support is still experimental. Therefore, we've provided this document for with detailed instructions on including Viam in your React Native project.
3
+
This document contains detailed instructions on including Viam in your React Native project. For an runnable example, see the [examples directory](/examples/react-native/).
4
4
5
5
## Requirements
6
6
@@ -11,63 +11,102 @@ This document assumes you already have a React Native project. If not, follow th
11
11
12
12
### Dependencies
13
13
14
-
You must use the latest version of Viam's TypeScript SDK, `>=0.11.0`, alongside a few other direct dependencies:`react-native-webrtc`, `react-native-url-polyfill`, and `@improbable-eng/grpc-web-react-native-transport`.
14
+
You must use the latest version of Viam's TypeScript SDK, `>=0.26.1`, alongside a few other direct dependencies:
15
15
16
-
You can use either Yarn or NPM to install the dependencies. This document will use NPM, but either will work.
You will also have to update your `index.js`. These updates should be placed above all other imports or customizations.
29
+
Using the SDK with React Native also requires a number of polyfills. You can find these at [polyfills.native.ts](/examples/react-native/polyfills.native.ts) and [polyfills.ts](/examples/react-native/polyfills.ts). They are also pasted in their entirety below. You can copy these directly into your application.
25
30
26
-
Firstly, you will have to import the URL polyfill:
31
+
```ts
32
+
// polyfills.native.ts
27
33
28
-
```js
34
+
// Dervied from https://raw.githubusercontent.com/connectrpc/examples-es/refs/heads/main/react-native
Communicating with your Viam machine in React Native requires the use of a custom transport. You can find it in the examples directory at [transport.ts](/examples/react-native/transport.ts). You can copy that file as is and put it in your project's root directory (sibling to the `polyfill` files).
47
80
48
-
Your final `index.js` might look something like this:
81
+
## Configuration
49
82
50
-
```js
51
-
/** @format */
83
+
### `App.tsx`
52
84
53
-
import'react-native-url-polyfill/auto';
85
+
You will also have to update your `App.tsx` to import and install the `polyfills` and update the Viam transport factory.
In addition, your `metro.config.js` file needs to be updated as well. `react-native` and `react-native-webrtc` require conflicting versions of the library `event-target-shim`. Because of that, we need to tell the Metro Bundler to package this library properly. The following is a full example of what the `metro.config.js` file could look like. If you have made any changes yourself to the bundler, yours will look different.
73
112
@@ -127,8 +166,7 @@ To use the SDK, you can use similar instructions to those found on the [document
0 commit comments