mirror of
https://github.com/MercuryWorkshop/adrift.git
synced 2025-05-12 22:00:02 -04:00
simple rtc demo
This commit is contained in:
commit
e6443eb06e
11 changed files with 6373 additions and 0 deletions
55
client/App.tsx
Normal file
55
client/App.tsx
Normal file
|
@ -0,0 +1,55 @@
|
|||
import { openWindow, deleteWindow } from "corium";
|
||||
import { h, render, Component, Fragment } from 'preact';
|
||||
import { RTCConnection } from "./rtc";
|
||||
|
||||
export default class App extends Component {
|
||||
rtc = new RTCConnection({
|
||||
onmessage: console.log,
|
||||
onopen: () => {
|
||||
this.rtc.dataChannel.send("test message");
|
||||
}
|
||||
});
|
||||
|
||||
state = {
|
||||
|
||||
|
||||
};
|
||||
|
||||
onInput = e => {
|
||||
const { value } = e.target;
|
||||
this.setState(prev => ({ ...prev, answer: value }));
|
||||
}
|
||||
|
||||
render(props, state) {
|
||||
return <>
|
||||
<div>
|
||||
|
||||
</div>
|
||||
|
||||
<button onClick={async () => {
|
||||
console.log("whra");
|
||||
let offer = await this.rtc.createOffer();
|
||||
|
||||
console.log("hra");
|
||||
this.setState(prev => ({ ...prev, offer: JSON.stringify(offer) }));
|
||||
|
||||
|
||||
}}>create offer</button>
|
||||
<p>
|
||||
offer: <code>{state.offer}</code>
|
||||
</p>
|
||||
|
||||
paste answer: <input type="text" value={state.answer} onInput={this.onInput} />
|
||||
|
||||
<button onClick={async () => {
|
||||
let { answer, candidates } = JSON.parse(state.answer);
|
||||
await this.rtc.answer(answer, candidates);
|
||||
alert("connected");
|
||||
}}>
|
||||
connect
|
||||
</button>
|
||||
|
||||
</>;
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue