whereby / browser-sdk Goto Github PK
View Code? Open in Web Editor NEWBrowser SDK for Whereby Embedded
License: MIT License
Browser SDK for Whereby Embedded
License: MIT License
I'm trying to use the Whereby Browser SDK react components, but having issues.
I've created a little sample project here to show the issues I'm seeing.
I made a create-t3-app and create-react-app to check if it was a NextJS specific issue.
On both I am seeing the typings import error mentioned on #99, but also I cannot import and use the Whereby components at all.
This might be some issue with my local environment if you are not able to reproduce the issue. If you have any ideas how to fix this would be a big help.
I really do want to try out the Browser SDK to see if it could solve our issues at Multiverse, but currently I can't get it working!
$ node --version
v20.8.1
$ npm --version
10.1.0
Installed whereby browser SDK with:
npm i @whereby.com/[email protected]
Here's a version that uses a NextJS app, created with Create T3 App, like we use at Multiverse.
https://github.com/mjftw/whereby-errors-sandbox/tree/create-t3-app
Terminal output:
$ npm run dev
> [email protected] dev
> next dev
▲ Next.js 13.5.6
- Local: http://localhost:3000
- Environments: .env
✓ Ready in 2.1s
✓ Compiled / in 1167ms (238 modules)
✓ Compiled /clientside in 183ms (280 modules)
✓ Compiled /serverside in 115ms (284 modules)
⨯ ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/home/merlin/learning/whereby-browser-sandbox/node_modules/@whereby.com/browser-sdk/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///home/merlin/learning/whereby-browser-sandbox/node_modules/@whereby.com/browser-sdk/dist/lib.cjs.js:3:14
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:431:15) {
page: '/serverside'
}
✓ Compiled /_error in 59ms (286 modules)
Serverside rendering screenshot
And here's one where I used Create React App, just to see if it was a NextJS specific issue.
https://github.com/mjftw/whereby-errors-sandbox/tree/create-react-app
Terminal output
$ npm start
> [email protected] start
> react-scripts start
(node:3789123) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:3789123) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
Starting the development server...
Failed to compile.
Attempted import error: 'useLocalMedia' is not exported from '@whereby.com/browser-sdk' (imported as 'useLocalMedia').
ERROR in ./src/components/MyPreCallUX.tsx 9:21-34
export 'useLocalMedia' (imported as 'useLocalMedia') was not found in '@whereby.com/browser-sdk' (possible exports: default)
ERROR in ./src/components/MyPreCallUX.tsx 35:36-45
export 'VideoView' (imported as 'VideoView') was not found in '@whereby.com/browser-sdk' (possible exports: default)
ERROR in ./src/components/MyPreCallUX.tsx 50:10-23
export 'useLocalMedia' (imported as 'useLocalMedia') was not found in '@whereby.com/browser-sdk' (possible exports: default)
webpack compiled with 3 errors
Files successfully emitted, waiting for typecheck results...
Issues checking in progress...
ERROR in src/components/MyPreCallUX.tsx:1:42
TS7016: Could not find a declaration file for module '@whereby.com/browser-sdk'. '/home/merlin/learning/whereby-browser-sandbox/node_modules/@whereby.com/browser-sdk/dist/lib.cjs.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/whereby.com__browser-sdk` if it exists or add a new declaration (.d.ts) file containing `declare module '@whereby.com/browser-sdk';`
> 1 | import { useLocalMedia, VideoView } from "@whereby.com/browser-sdk";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
2 |
3 | function MyPreCallUX() {
4 | const localMedia = useLocalMedia({ audio: false, video: true });
ERROR in src/components/MyPreCallUX.tsx:13:27
TS7006: Parameter 'd' implicitly has an 'any' type.
11 | <div className="preCallView">
12 | {/* Render any UI, making use of state */}
> 13 | {cameraDevices.map((d) => (
| ^
14 | <p
15 | key={d.deviceId}
16 | onClick={() => {
I'm seeing some issues when trying to install your new Beta1 version with npm:
$ npm i @whereby.com/[email protected]
npm ERR! code 1
npm ERR! The git reference could not be found
npm ERR! command git --no-replace-objects checkout v5.3.0
npm ERR! error: pathspec 'v5.3.0' did not match any file(s) known to git
npm ERR! A complete log of this run can be found in: /home/merlin/.npm/_logs/2023-10-30T07_16_16_902Z-debug-0.log
I thought it might be my environment causing issues so tried the previous Apla26 version, but this works without issue.
$ npm i @whereby.com/[email protected]
npm WARN deprecated [email protected]: Please use the native JSON object instead of JSON 3
added 75 packages, changed 1 package, and audited 466 packages in 14s
130 packages are looking for funding
run `npm fund` for details
8 vulnerabilities (1 moderate, 6 high, 1 critical)
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
Environment info:
$ node --version
v20.8.1
$ npm --version
10.1.0
Very interested to try out the shiny new browser SDK now it's officially entered beta!
Thank you for developing the browser SDK for Whereby.
The recording feature, which is supported by the Whereby embeds, is quite useful. However, I have a question regarding listening to recording events while in the room. Is there a way to do this? Do you have any plans to develop such a feature in the future?
Thanks in advance!
In the WherebyEmbed custom element, a TypeError is encountered when attempting to access the origin property of roomUrl within the onmessage event handler. This issue arises if the onmessage handler is called before this.roomUrl is set or if roomUrl is not correctly initialized due to parsing errors in the room attribute.
To address this, a guard can be added to ensure this.roomUrl is defined before accessing its properties. Modify the code at line 104 as follows:
Replace:
if (origin !== this.roomUrl.origin) return;
With:
if (!this.roomUrl || origin !== this.roomUrl.origin) return;
Line 104 in 580f609
Hi,
I'm getting an error with a node module imported from @whereby.com/browser-sdk/embed.
I'm using Next.js ( [email protected] ) with App directory and @whereby.com/browser-sdk version 2.6.0
It seems like the node module @ungap/create-content
is not updated to support server/client components yet.
Here is the full error:
node_modules/@ungap/create-content/esm/index.js (56:1) @ eval ⨯ ReferenceError: document is not defined at __webpack_require__ (/Users/riccardolinares/Projects/comestai/.next/server/webpack-runtime.js:33:42) at __webpack_require__ (/Users/riccardolinares/Projects/comestai/.next/server/webpack-runtime.js:33:42) at __webpack_require__ (/Users/riccardolinares/Projects/comestai/.next/server/webpack-runtime.js:33:42) at __webpack_require__ (/Users/riccardolinares/Projects/comestai/.next/server/webpack-runtime.js:33:42) at __webpack_require__ (/Users/riccardolinares/Projects/comestai/.next/server/webpack-runtime.js:33:42) at __webpack_require__ (/Users/riccardolinares/Projects/comestai/.next/server/webpack-runtime.js:33:42) at eval (./src/components/whereby/room.tsx:7:88) at (ssr)/./src/components/whereby/room.tsx (/Users/riccardolinares/Projects/comestai/.next/server/app/room/[roomUrl]/page.js:162:1) at __webpack_require__ (/Users/riccardolinares/Projects/comestai/.next/server/webpack-runtime.js:33:42) null
How can I solve it?
When I try the beta version and use it according to the README, found out that the package does not export anything usable and the TS definitions are missing as well.
Rendered screen on NextJS dev mode using next dev
:
TS errors in VS Code:
These errors do not exist for the last alpha version..
Clone and run this repo: https://github.com/NokLam-hhl/whereby-sdk-fail-demo
Error: Failed to fetch update manifest Internal Server Error
at http://localhost:3000/_next/static/chunks/fallback/webpack.js?ts=1686740013295:1176:37
ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/bla/bla/bla/node_modules/@whereby.com/browser-sdk/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
Hello! Failed to use library (2.0.0-alpha9
version) with NextJS. Seems like it can be fixed by removing "type": "module"
from package.json.
Please assist how to overcome this issue to use with NextJS 12.0?
I'm trying out the new Browser SDK alpha, but seeing some import errors.
Am I right in thinking there are no Typescript type definitions for the module?
This is a key feature we'd need to adopt Whereby at my company, so keen to hear more on this.
We would otherwise attempt to add the type module definition ourself, but this is likely to be error prone since we are not the authors.
From what I remember, there are also no type definitions in the main released Embedded SDK version v1.11
right?
import { useLocalMedia, VideoView } from "@whereby.com/browser-sdk";
^^^^^^^^^^^^^^^^^^^^^^^^^^
Could not find a declaration file for module '@whereby.com/browser-sdk'. '/home/merlin/repos/mycoolapp/node_modules/@whereby.com/browser-sdk/dist/lib.cjs.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/whereby.com__browser-sdk` if it exists or add a new declaration (.d.ts) file containing `declare module '@whereby.com/browser-sdk';`ts(7016)
Version info:
$ npm --version
8.5.5
$ node --version
v16.15.0
~/r/hello_app (
package.json
"dependencies"
snippet:
"@whereby.com/browser-sdk": "^1.11.0",
"typescript": "^5.1.6",
Hi everyone,
Is there any event for a Picture-in-picture toggle?
I want the main video element to hide while triggering Picture-in-picture to access my web page below.
Thanks in advance.
Hi there,
First of all thank you for the work for this early version of the SDK. The flexibility introduced with it was the key factor for us to choose Whereby. We have been implementing the SDK in NextJS over the past few weeks and all is running smoothly with setting up the connection. However, we noticed that the video streams of other participants than the local one cannot be retrieved. We properly get the remote participants, but the stream is always empty.
Any pointers how to solve this?
SDK version: 2.0.0-alpha20
Our rendering:
{remoteParticipants.map((participant, i) => {
if (!participant) {
return null;
}
return (
<motion.div
key={participant.id}
className={classNames(
'flex-grow flex-shrink min-w-0',
variant === 'compact' && 'relative',
variant === 'spacious' && 'aspect-square rounded overflow-hidden bg-gray-100 w-[52%] absolute border',
i === 0 && variant === 'spacious' && 'right-0 top-0 z-10',
i === 1 && variant === 'spacious' && 'left-0 bottom-0',
)}
variants={defaultFadeInVariants}
initial="hidden"
animate="visible"
>
{participant.stream && (
<VideoView
stream={participant.stream}
style={{ width: "100%", height: "100%", objectFit: "cover" }}
/>
)}
<div
className={classNames(
`absolute bottom-2 backdrop-blur-lg p-2 flex justify-center rounded gap-4 bg-gray-800/90 text-white z-20`,
variant === 'spacious' && 'left-2',
i === 0 && variant === 'compact' && 'left-2',
i > 0 && variant === 'compact' && 'right-2',
)}
>
<span>{participant.displayName || 'Guest'}</span>
</div>
</motion.div>
);
})}
I'm trying to using your browser sdk version 3.3.4
.
We use Vite to build our app and after a bit of struggle to get Buffer working locally I managed to hve your web component integration loading and working fine. Isse now is that when I try to build our app with Vite I'm getting the following error
x Build failed in 20.81s
error during build:
../node_modules/@whereby.com/media/dist/index.mjs (10:7): "default" is not exported by "../node_modules/uuid-validate/index.js", imported by "../node_modules/@whereby.com/media/dist/index.mjs".
file: /opt/actions-runner/_work/monorepo/monorepo/node_modules/@whereby.com/media/dist/index.mjs:10:7
8: import { Address6 } from 'ip-address';
9: import checkIp from 'check-ip';
10: import validate from 'uuid-validate';
^
11: import { io } from 'socket.io-client';
Am I missing something on my side? It's the first time that this happen to me and I'm using Vite for quite a long time so wanted to double check if it was a me issue or it was something on your side.
This is currently my vite config
const viteConfig: UserConfig = {
define: {
...all evn variables,
"process.env": {},
},
resolve: {
alias: {
src: path.resolve(__dirname, "./src"),
buffer: "buffer/",
},
},
plugins: [
react(),
relay,
svgrPlugin(),
inject({
Buffer: ["buffer", "Buffer"],
}),
sentryVitePlugin({
authToken: process.env.SENTRY_AUTH_TOKEN ?? "",
org: "project-vault",
project: "nous-frontend-web",
}),
TanStackRouterVite(routeConfig),
isProduction ? null : bundleStats(),
],
server: {
port: 3000,
strictPort: true,
host: true,
},
build: {
sourcemap: true,
rollupOptions: {
output: {
assetFileNames: "assets/[name].[hash][extname]",
chunkFileNames: "assets/[name].[hash].js",
entryFileNames: "assets/[name].[hash].js",
manualChunks: (id) => {
if (id.includes("/@formatjs")) {
return "i18n"
}
if (id.includes("/glow/assets")) {
return "glow"
}
},
},
},
},
}
export default defineConfig(viteConfig)
Any help would be appreciated 🙏🏻
Version: 2.0.0-alpha10
React Component
const Room = ({ roomUrl, localMedia, displayName, isHost }) => {
const roomConnection = useRoomConnection(
roomUrl,
{
localMedia,
displayName,
logger: console
}
);
const { waitingParticipants, remoteParticipants, localParticipant, isJoining, roomConnectionStatus, chatMessages, mostRecentChatMessage } = roomConnection.state
const { acceptWaitingParticipant, knock, rejectWaitingParticipant, sendChatMessage, toggleCamera } = roomConnection.actions
if(roomConnectionStatus === 'room_locked') {
return <WaitingArea knock={knock}/>
}
if(roomConnectionStatus === 'rejected') {
return <p>You have been rejected access</p>
}
return (
<Container>
<Row>
<Col>
<h1>Room - {roomConnectionStatus}</h1>
</Col>
</Row>
{isHost && <Row>
<Col>
<p>Participants in Waiting Area</p>
<ul>
{waitingParticipants.map(a => (
<li key={a.id}>
<p>
{a.displayName}
</p>
<button className="btn btn-success" onClick={() => acceptWaitingParticipant(a.id)} >Approve</button>
<button className="btn btn-danger" onClick={() => rejectWaitingParticipant(a.id)} >Reject</button>
</li>
))}
</ul>
</Col>
</Row>}
<Row>
<Col>
<p>Participants</p>
</Col>
</Row>
<Row>
{remoteParticipants.map((r) => (
<Col key={r.id}>
<VideoView style={{width: '300px'}} stream={r.stream} />
<p>{r.displayName}</p>
</Col>
))}
</Row>
<hr />
{localParticipant && <Row>
<Col >
<VideoView style={{width: '200px'}} stream={localParticipant.stream} />
<p>{localParticipant.displayName}</p>
</Col>
</Row>}
</Container>
)
}
This Room
Component is a common component between a host and a participant.
As a host, I tested accepting a participant and all was working fine. But when I tested rejecting a participant, the participant's roomConnectionStatus
state was updated to rejected
which is valid. However at the same time the Host's roomConnectionStatus
was also updated to rejected
causing the page to render You have been rejected access
page for the host. The room url used was created using the WhereBy Rest Api with the isLocked
property set to true
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.