UNPKG

@devexcelsior/healing-webrtc-relay

Version:

Peer-to-peer healing relay using WebRTC for disconnected UI recovery

41 lines (40 loc) 1.33 kB
"use strict"; // © 2025 DevExcelsior – Commercial use prohibited. License required. // Contact: curtnpuckett@gmail.com Object.defineProperty(exports, "__esModule", { value: true }); exports.HealingPeerRelay = void 0; class HealingPeerRelay { constructor() { this.connection = new RTCPeerConnection(); } async createOffer() { const offer = await this.connection.createOffer(); await this.connection.setLocalDescription(offer); return JSON.stringify(offer); } async receiveAnswer(answer) { const remoteDesc = new RTCSessionDescription(JSON.parse(answer)); await this.connection.setRemoteDescription(remoteDesc); } onSignal(callback) { this.connection.ondatachannel = (event) => { const channel = event.channel; channel.onmessage = (msg) => { try { const parsed = JSON.parse(msg.data); callback(parsed); } catch { // ignore } }; }; } sendSignal(data) { const channel = this.connection.createDataChannel('healing'); channel.onopen = () => { channel.send(JSON.stringify(data)); }; } } exports.HealingPeerRelay = HealingPeerRelay;