import { useState as n } from "react";
import { h8 as u, h9 as H } from "./684d2f28.js";
import "react-dom";
const E = () => {
  const [t, m] = n(null), [e, l] = n(null), [s, d] = n(null), [r, f] = n(!1), [C, h] = n(200), [k, w] = n(200), y = () => {
    const i = u.createClient({
      mode: "rtc",
      codec: "vp8"
    });
    m(i);
  }, c = async (i) => {
    if (s)
      return s.setEnabled(i);
    const a = await u.createCameraVideoTrack();
    a.play("camera-video"), d(a);
  }, p = async (i) => {
    if (e)
      return e.setEnabled(i);
    const a = await u.createMicrophoneAudioTrack();
    a.play(), l(a);
  }, g = async () => {
    if (r) {
      if (!t || !t.localTracks.length)
        return;
      s && (await c(!1), await t.unpublish(s), s.stop(), d(null)), e && (await p(!1), await t.unpublish(e), e.stop(), l(null)), await t.leave(), f(!1);
    }
  }, b = async (i, a, o) => {
    a || (a = "react-room"), r && await g(), t == null || t.on("user-published", S), await (t == null ? void 0 : t.join(i, a, o || null, H())), f(!0);
  }, A = async (i, a) => {
    await c(!0), r || await b(i, a, null), await (t == null ? void 0 : t.publish(s));
    const o = s == null ? void 0 : s.getMediaStreamTrack();
    if (o) {
      const v = o.getSettings(), T = v.width, V = v.height;
      w(T), h(V);
    }
  }, S = async (i, a) => {
    if (a === "video") {
      const o = await (t == null ? void 0 : t.subscribe(i, a));
      o == null || o.play("remote-video");
    }
    if (a === "audio") {
      const o = await (t == null ? void 0 : t.subscribe(i, a));
      o == null || o.play();
    }
  };
  return {
    client: t,
    audioTrack: e,
    videoTrack: s,
    isJoined: r,
    turnOnCamera: c,
    turnOnMicrophone: p,
    leaveChannel: g,
    joinChannel: b,
    publishVideo: A,
    initializeAgora: y,
    videoWidth: k,
    videoHeight: C,
    setHeight: h,
    setWidth: w
  };
};
export {
  E as default
};
