Moved urls to environment and turn server retreval
This commit is contained in:
parent
16b27a7058
commit
79b46e0b5a
2
.env
Normal file
2
.env
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
REACT_APP_BROKER_URL=http://localhost:9000
|
||||||
|
REACT_APP_ICE_SERVERS_URL=http://localhost:9000/iceservers
|
2
.env.production
Normal file
2
.env.production
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
REACT_APP_BROKER_URL=https://agent.owlbear.rodeo
|
||||||
|
REACT_APP_ICE_SERVERS_URL=http://agent.owlbear.rodeo/iceservers
|
@ -6,7 +6,7 @@ import Peer from "../helpers/Peer";
|
|||||||
|
|
||||||
import AuthContext from "../contexts/AuthContext";
|
import AuthContext from "../contexts/AuthContext";
|
||||||
|
|
||||||
const socket = io("https://agent.owlbear.rodeo");
|
const socket = io(process.env.REACT_APP_BROKER_URL);
|
||||||
|
|
||||||
function useSession(
|
function useSession(
|
||||||
partyId,
|
partyId,
|
||||||
@ -18,9 +18,16 @@ function useSession(
|
|||||||
onPeerError
|
onPeerError
|
||||||
) {
|
) {
|
||||||
const { password, setAuthenticationStatus } = useContext(AuthContext);
|
const { password, setAuthenticationStatus } = useContext(AuthContext);
|
||||||
|
const [iceServers, setIceServers] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
async function joinParty() {
|
||||||
|
const response = await fetch(process.env.REACT_APP_ICE_SERVERS_URL);
|
||||||
|
const data = await response.json();
|
||||||
|
setIceServers(data.iceServers);
|
||||||
socket.emit("join party", partyId, password);
|
socket.emit("join party", partyId, password);
|
||||||
|
}
|
||||||
|
joinParty();
|
||||||
}, [partyId, password]);
|
}, [partyId, password]);
|
||||||
|
|
||||||
const [peers, setPeers] = useState({});
|
const [peers, setPeers] = useState({});
|
||||||
@ -127,7 +134,11 @@ function useSession(
|
|||||||
// Setup event listeners for the socket
|
// Setup event listeners for the socket
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function addPeer(id, initiator, sync) {
|
function addPeer(id, initiator, sync) {
|
||||||
const connection = new Peer({ initiator, trickle: false });
|
const connection = new Peer({
|
||||||
|
initiator,
|
||||||
|
trickle: false,
|
||||||
|
config: { iceServers },
|
||||||
|
});
|
||||||
|
|
||||||
setPeers((prevPeers) => ({
|
setPeers((prevPeers) => ({
|
||||||
...prevPeers,
|
...prevPeers,
|
||||||
@ -178,7 +189,7 @@ function useSession(
|
|||||||
socket.removeListener("signal", handleSignal);
|
socket.removeListener("signal", handleSignal);
|
||||||
socket.removeListener("auth error", handleAuthError);
|
socket.removeListener("auth error", handleAuthError);
|
||||||
};
|
};
|
||||||
}, [peers, setAuthenticationStatus]);
|
}, [peers, setAuthenticationStatus, iceServers]);
|
||||||
|
|
||||||
return { peers, socket };
|
return { peers, socket };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user