|
@@ -1,10 +1,14 @@
|
|
|
import React, { useContext } from "react";
|
|
|
import { useSocket } from "@scripters/use-socket.io";
|
|
|
import { join } from "client2client.io";
|
|
|
+import { useTranslation } from "react-i18next";
|
|
|
+
|
|
|
+import Waiter from "../components/Waiter";
|
|
|
|
|
|
export const C2CContext = React.createContext([null, false]);
|
|
|
|
|
|
export const C2CProvider = ({ room, ...props }) => {
|
|
|
+ const { t } = useTranslation();
|
|
|
const socket = useSocket();
|
|
|
const [joined, setJoined] = React.useState(false);
|
|
|
const [isMaster, setIsMaster] = React.useState(false);
|
|
@@ -12,6 +16,23 @@ export const C2CProvider = ({ room, ...props }) => {
|
|
|
const roomRef = React.useRef(null);
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
+ const connect = () => {
|
|
|
+ // Do nothing for now. Need c2c handling reconnection.
|
|
|
+ // setJoined(true);
|
|
|
+ };
|
|
|
+ const disconnect = () => {
|
|
|
+ console.log("disconnected");
|
|
|
+ setJoined(false);
|
|
|
+ };
|
|
|
+ socket.on("connect", connect);
|
|
|
+ socket.on("disconnect", disconnect);
|
|
|
+ return () => {
|
|
|
+ socket.off("disconnect", disconnect);
|
|
|
+ socket.off("connect", connect);
|
|
|
+ };
|
|
|
+ }, [socket]);
|
|
|
+
|
|
|
+ React.useEffect(() => {
|
|
|
if (!socket) {
|
|
|
return;
|
|
|
}
|
|
@@ -32,8 +53,8 @@ export const C2CProvider = ({ room, ...props }) => {
|
|
|
});
|
|
|
}, [room, socket]);
|
|
|
|
|
|
- if (!joined) {
|
|
|
- return null;
|
|
|
+ if (!joined || !c2c) {
|
|
|
+ return <Waiter message={t("Waiting for connection…")} />;
|
|
|
}
|
|
|
|
|
|
return (
|