Backend
Course: WebRTC Basic implementation, advance discussion - chapter 5
- Create an empty TS project, add ws to it
npm init -ynpx tsc --initnpm install ws @types/ws- Change rootDir and outDir in tsconfig
"rootDir": "./src","outDir": "./dist",- Create a simple websocket server
import { WebSocketServer } from 'ws';
const wss = new WebSocketServer({ port: 8080 });
let senderSocket: null | WebSocket = null;let receiverSocket: null | WebSocket = null;
wss.on('connection', function connection(ws) { ws.on('error', console.error);
ws.on('message', function message(data: any) { const message = JSON.parse(data);
});
ws.send('something');});- Try running the server
tsc -bnode dist/index.js- Add message handlers
$1bThat is all that you need for a simple one way communication b/w two tabs
To have both the sides be able to send each other media, and support multiple rooms, see https://github.com/hkirat/omegle/