@rtcio/react
Version:
A wrapper around the @rtcio/core library for React integration
20 lines • 624 B
JavaScript
import { usePeerContext } from "./usePeerContext";
import { useMemo } from "react";
/**
* !IMPORTANT make sure you manually cleanup any events you subscribe to here.
* Otherwise, use the `useRtcListener` hook for React to automatically manage
* subscriptions
*/
export function useRtc() {
const ctx = usePeerContext();
if (!ctx) {
throw new Error("useRtc must be called in a P2PProvider");
}
return useMemo(() => {
return {
rtc: ctx.rtc.map((val) => val.rtc),
myId: ctx.rtc.map((val) => val.myId),
};
}, [ctx.rtc]);
}
//# sourceMappingURL=useRtc.js.map