Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add web-components #36

Merged
merged 14 commits into from
Dec 4, 2023
26 changes: 26 additions & 0 deletions webcomponents/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Visual Studio cache directory
.vs/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
16 changes: 16 additions & 0 deletions webcomponents/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import JoyRtcComponent from './model/joy-rtc'
import { DOMAttributes } from "react"
rocka marked this conversation as resolved.
Show resolved Hide resolved

type CustomElement<T> = Partial<T & DOMAttributes<T> & { children: any } & { style?: any }>;

declare global {
namespace JSX {
interface IntrinsicElements {
['joy-rtc']: CustomElement<JoyRtcComponent>;
}
}
}


export * from "./model/joy-rtc"

3 changes: 2 additions & 1 deletion webui/src/joy-rtc.ts → webcomponents/model/joy-rtc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nipplejs from "nipplejs";

class JoyRtcComponent extends HTMLElement {
export class JoyRtcComponent extends HTMLElement {
private ws: WebSocket | null = null;
private pc: RTCPeerConnection | null = null;
private dc: RTCDataChannel | null = null;
Expand Down Expand Up @@ -302,4 +302,5 @@ class JoyRtcComponent extends HTMLElement {
}

customElements.define("joy-rtc", JoyRtcComponent);

export default JoyRtcComponent;
15 changes: 15 additions & 0 deletions webcomponents/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "webcomponent",
"version": "0.0.0",
"description": "joyrtc web component lib",
"dependencies": {
"nipplejs": "^0.10.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.34",
"@types/react-dom": "^18.0.11",
"typescript": "^5.2.2"
}
}
14 changes: 1 addition & 13 deletions webui/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import { DOMAttributes } from "react"
import "./app.css"

import JoyRtcComponent from './joy-rtc'
import './joy-rtc'
import '../../webcomponents/index'

import { ProtoHttpToWs } from './util';

type CustomElement<T> = Partial<T & DOMAttributes<T> & { children: any } & { style?: any }>;

declare global {
namespace JSX {
interface IntrinsicElements {
['joy-rtc']: CustomElement<JoyRtcComponent>;
}
}
}

function App() {
return (
Expand Down
2 changes: 1 addition & 1 deletion webui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default defineConfig({
},
},
},
plugins: [react()],
plugins: [react()]
})