@webrtc2/client
Version:
WebRTC2 Client - React Native, Web & Electron WebRTC hooks and components for cross-platform real-time video calls, audio communication, and screen sharing
113 lines (105 loc) • 3.26 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
AudioCall: () => AudioCall,
ScreenShare: () => ScreenShare,
VERSION: () => VERSION,
VideoCall: () => VideoCall,
WebRTCProvider: () => WebRTCProvider,
useWebRTC: () => useWebRTC
});
module.exports = __toCommonJS(index_exports);
// src/components/AudioCall.tsx
function AudioCall() {
return null;
}
// src/components/ScreenShare.tsx
function ScreenShare() {
return null;
}
// src/components/VideoCall.tsx
function VideoCall() {
return null;
}
// src/hooks/useWebRTC.ts
var import_react = require("react");
function useWebRTC() {
const [localStream, setLocalStream] = (0, import_react.useState)(null);
const [remoteStream, setRemoteStream] = (0, import_react.useState)(null);
const [connectionState, setConnectionState] = (0, import_react.useState)("disconnected");
const [callState, setCallState] = (0, import_react.useState)("idle");
const connect = (0, import_react.useCallback)(async (roomId) => {
try {
setConnectionState("connecting");
setCallState("calling");
console.log("Connecting to room:", roomId);
setTimeout(() => {
setConnectionState("connected");
setCallState("connected");
}, 1e3);
} catch (error) {
console.error("Failed to connect:", error);
setConnectionState("failed");
setCallState("ended");
}
}, []);
const disconnect = (0, import_react.useCallback)(() => {
setConnectionState("disconnected");
setCallState("idle");
setLocalStream(null);
setRemoteStream(null);
console.log("Disconnected");
}, []);
return {
connect,
disconnect,
localStream,
remoteStream,
connectionState,
callState
};
}
// src/providers/WebRTCProvider.tsx
var import_react2 = require("react");
var import_jsx_runtime = require("react/jsx-runtime");
var WebRTCContext = (0, import_react2.createContext)(null);
var defaultConfig = {
iceServers: [
{ urls: "stun:stun.l.google.com:19302" }
],
signaling: {
url: "ws://localhost:3001"
}
};
function WebRTCProvider({ children, config = defaultConfig }) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WebRTCContext.Provider, { value: { config }, children });
}
// src/index.ts
var VERSION = "1.0.0";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AudioCall,
ScreenShare,
VERSION,
VideoCall,
WebRTCProvider,
useWebRTC
});