@whereby.com/browser-sdk 2.0.0-alpha2 → 2.0.0-alpha21

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/README.md CHANGED
@@ -1,38 +1,87 @@
1
1
  # `@whereby.com/browser-sdk`
2
2
 
3
- > This is a pre-release of the v2 version of this library, adding support for more custom integration using React hooks and plain JavaScript classes in addition to the web component for embedding.
3
+ > This is a pre-release of the v2 version of this library, adding support for
4
+ > more custom integration using React hooks and plain JavaScript classes in
5
+ > addition to the web component for embedding.
4
6
 
5
- Whereby browser SDK is a library for seamless integration of Whereby (https://whereby.com) video calls into your web application.
7
+ Whereby browser SDK is a library for seamless integration of Whereby
8
+ (https://whereby.com) video calls into your web application.
6
9
 
7
10
  ## Installation
8
11
 
9
- ```
12
+ ```shell
10
13
  npm install @whereby.com/browser-sdk
11
14
  ```
15
+
12
16
  or
13
- ```
17
+
18
+ ```shell
14
19
  yarn add @whereby.com/browser-sdk
15
20
  ```
16
21
 
17
22
  ## Usage
18
23
 
19
- > In order to make use of this functionality, you must have a Whereby account from which you can create room urls, either [manually or through our API](https://docs.whereby.com/creating-and-deleting-rooms).
24
+ > In order to make use of this functionality, you must have a Whereby account
25
+ > from which you can create room urls, either [manually or through our
26
+ > API](https://docs.whereby.com/creating-and-deleting-rooms).
20
27
 
21
28
  ### React hooks
22
29
 
23
- The `useRoomConnection` hook provides a way to connect participants in a given room, subscribe to state updates, and perform actions on the connection, like toggling camera or microphone.
30
+ #### useLocalMedia
31
+
32
+ The `useLocalMedia` hook enables preview and selection of local devices (camera
33
+ & microphone) prior to establishing a connection within a Whereby room. Use
34
+ this hook to build rich pre-call experiences, allowing end users to confirm
35
+ their device selection up-front. This hook works seamlessly with the
36
+ `useRoomConnection` hook described below.
37
+
38
+ ```js
39
+ import { useLocalMedia, VideoView } from "@whereby.com/browser-sdk";
40
+
41
+ function MyPreCallUX() {
42
+ const localMedia = useLocalMedia({ audio: false, video: true });
43
+
44
+ const { currentCameraDeviceId, cameraDevices, localStream } = localMedia.state;
45
+ const { setCameraDevice, toggleCameraEnabled } = localMedia.actions;
46
+
47
+ return <div className="preCallView">
48
+ { /* Render any UI, making use of state */ }
49
+ { cameraDevices.map((d) => (
50
+ <p
51
+ key={d.deviceId}
52
+ onClick={() => {
53
+ if (d.deviceId !== currentCameraDeviceId) {
54
+ setCameraDevice(d.deviceId);
55
+ }
56
+ }}
57
+ >
58
+ {d.label}
59
+ </p>
60
+ )) }
61
+ <VideoView muted stream={localStream} />
62
+ </div>;
63
+ }
24
64
 
25
65
  ```
26
- import { useRoomConnection } from “@whereby.com/browser-sdk”;
66
+
67
+ #### useRoomConnection
68
+
69
+ The `useRoomConnection` hook provides a way to connect participants in a given
70
+ room, subscribe to state updates, and perform actions on the connection, like
71
+ toggling camera or microphone.
72
+
73
+ ```js
74
+ import { useRoomConnection } from "@whereby.com/browser-sdk";
27
75
 
28
76
  function MyCallUX( { roomUrl, localStream }) {
29
- const [state, actions, components ] = useRoomConnection(
77
+ const { state, actions, components } = useRoomConnection(
30
78
  "<room_url>"
31
79
  {
32
- localMediaConstraints: {
80
+ localMedia: null, // Supply localMedia from `useLocalMedia` hook, or constraints
81
+ localMediaConstraints: {
33
82
  audio: true,
34
83
  video: true,
35
- },
84
+ }
36
85
  }
37
86
  );
38
87
 
@@ -50,27 +99,50 @@ function MyCallUX( { roomUrl, localStream }) {
50
99
 
51
100
  ```
52
101
 
53
- ### Web component for embedding
102
+ #### Usage with Next.js
54
103
 
55
- Use the `<whereby-embed />` web component to make use of Whereby's pre-built responsive UI. Refer to our [documentation](https://docs.whereby.com/embedding-rooms/in-a-web-page/using-the-whereby-embed-element) to learn which attributes are supported.
104
+ If you are integrating these React hooks with Next.js, you need to ensure your
105
+ custom video experience components are rendered client side, as the underlying
106
+ APIs we use are only available in the browser context. Simply add `"use
107
+ client";` to the top of component, like in the following example:
56
108
 
109
+ ```js
110
+ "use client";
57
111
 
58
- #### React
112
+ import { VideoView, useLocalMedia } from "@whereby.com/browser-sdk";
59
113
 
60
- ```
61
- import "@whereby.com/browser-sdk"
114
+ export default function MyNextVideoExperience() {
115
+ const { state, actions } = useLocalMedia({ audio: false, video: true });
62
116
 
63
- const MyComponent = ({ roomUrl }) => {
64
- return <whereby-embed chat="off" room={roomUrl} />
117
+ return (
118
+ <p>{ state.localStream && <VideoView muted stream={state.localStream} /> }</p>
119
+ );
65
120
  }
66
121
 
67
- export default MyComponent
122
+ ```
123
+
124
+ ### Web component for embedding
68
125
 
126
+ Use the `<whereby-embed />` web component to make use of Whereby's pre-built
127
+ responsive UI. Refer to our
128
+ [documentation](https://docs.whereby.com/embedding-rooms/in-a-web-page/using-the-whereby-embed-element)
129
+ to learn which attributes are supported.
130
+
131
+ #### React
132
+
133
+ ```js
134
+ import "@whereby.com/browser-sdk";
135
+
136
+ const MyComponent = ({ roomUrl }) => {
137
+ return <whereby-embed chat="off" room={roomUrl} />;
138
+ };
139
+
140
+ export default MyComponent;
69
141
  ```
70
142
 
71
143
  #### In plain HTML
72
144
 
73
- ```
145
+ ```html
74
146
  <html>
75
147
  <head>
76
148
  <script src="...."></script>
@@ -85,4 +157,6 @@ export default MyComponent
85
157
 
86
158
  **Note**
87
159
 
88
- Although we have just higlighted two combinations of how to load and use the web component, it should be possible to use this library with all the major frontend frameworks.
160
+ Although we have just higlighted two combinations of how to load and use the
161
+ web component, it should be possible to use this library with all the major
162
+ frontend frameworks.