Compare commits
No commits in common. "3b5955ff31bdc5e78059e36f4b1ff56d3b8e92a5" and "9624ff93f0f03e2023b3be8c292612d2dc8be160" have entirely different histories.
3b5955ff31
...
9624ff93f0
@ -3,7 +3,10 @@ package fr.titionfire.ffsaf.ws.recv;
|
||||
import fr.titionfire.ffsaf.data.model.CategoryModel;
|
||||
import fr.titionfire.ffsaf.data.model.MatchModel;
|
||||
import fr.titionfire.ffsaf.data.model.TreeModel;
|
||||
import fr.titionfire.ffsaf.data.repository.*;
|
||||
import fr.titionfire.ffsaf.data.repository.CategoryRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.CompetitionRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.MatchRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.TreeRepository;
|
||||
import fr.titionfire.ffsaf.domain.entity.MatchEntity;
|
||||
import fr.titionfire.ffsaf.domain.entity.TreeEntity;
|
||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||
@ -43,9 +46,6 @@ public class RCategorie {
|
||||
@Inject
|
||||
TreeRepository treeRepository;
|
||||
|
||||
@Inject
|
||||
CardboardRepository cardboardRepository;
|
||||
|
||||
private Uni<CategoryModel> getById(long id, WebSocketConnection connection) {
|
||||
return categoryRepository.findById(id)
|
||||
.invoke(Unchecked.consumer(o -> {
|
||||
@ -210,7 +210,6 @@ public class RCategorie {
|
||||
public Uni<Void> deleteCategory(WebSocketConnection connection, Long id) {
|
||||
return getById(id, connection)
|
||||
.call(cat -> Panache.withTransaction(() -> treeRepository.delete("category = ?1", cat.getId())
|
||||
.call(__ -> cardboardRepository.delete("match.category = ?1", cat))
|
||||
.call(__ -> matchRepository.delete("category = ?1", cat))))
|
||||
.chain(cat -> Panache.withTransaction(() -> categoryRepository.delete(cat)))
|
||||
.invoke(__ -> SSCategorie.sendDelCategory(connection, id))
|
||||
|
||||
@ -44,9 +44,6 @@ public class RMatch {
|
||||
@Inject
|
||||
CompetitionGuestRepository competitionGuestRepository;
|
||||
|
||||
@Inject
|
||||
CardboardRepository cardboardRepository;
|
||||
|
||||
private Uni<MatchModel> getById(long id, WebSocketConnection connection) {
|
||||
return matchRepository.findById(id)
|
||||
.invoke(Unchecked.consumer(o -> {
|
||||
@ -280,10 +277,7 @@ public class RMatch {
|
||||
@WSReceiver(code = "deleteMatch", permission = PermLevel.ADMIN)
|
||||
public Uni<Void> deleteMatch(WebSocketConnection connection, Long idMatch) {
|
||||
return getById(idMatch, connection)
|
||||
.map(__ -> idMatch)
|
||||
.chain(l -> Panache.withTransaction(() ->
|
||||
cardboardRepository.delete("match.id = ?1", l)
|
||||
.chain(__ -> matchRepository.delete("id = ?1", l))))
|
||||
.chain(matchModel -> Panache.withTransaction(() -> matchRepository.delete(matchModel)))
|
||||
.invoke(__ -> SSMatch.sendDeleteMatch(connection, idMatch))
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import {createContext, useContext, useEffect, useId, useReducer, useRef, useState} from "react";
|
||||
import {apiAxios} from "../utils/Tools.js";
|
||||
import {toast} from "react-toastify";
|
||||
import {useAuth} from "./useAuth.jsx";
|
||||
|
||||
function uuidv4() {
|
||||
@ -43,7 +45,6 @@ export function WSProvider({url, onmessage, children}) {
|
||||
const id = useId();
|
||||
const {is_authenticated} = useAuth()
|
||||
const [isReady, setIsReady] = useState(false)
|
||||
const [doReconnect, setDoReconnect] = useState(false)
|
||||
const [state, dispatch] = useReducer(reducer, {listener: []})
|
||||
const ws = useRef(null)
|
||||
const listenersRef = useRef([])
|
||||
@ -58,33 +59,10 @@ export function WSProvider({url, onmessage, children}) {
|
||||
listenersRef.current = state.listener
|
||||
}, [state.listener])
|
||||
|
||||
useEffect(() => {
|
||||
if (!doReconnect && !is_authenticated && isReady)
|
||||
return;
|
||||
|
||||
const timer = setInterval(() => {
|
||||
if (isReady || !doReconnect || !is_authenticated)
|
||||
return;
|
||||
|
||||
console.log("WSProvider: reconnecting to", url);
|
||||
try {
|
||||
const newSocket = new WebSocket(url)
|
||||
newSocket.onopen = ws.current.onopen
|
||||
newSocket.onclose = ws.current.onclose
|
||||
newSocket.onmessage = ws.current.onmessage
|
||||
ws.current = newSocket
|
||||
}catch (e) {
|
||||
|
||||
}
|
||||
}, 5000);
|
||||
return () => clearInterval(timer);
|
||||
}, [isReady, doReconnect, is_authenticated]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!mountCounter[id])
|
||||
mountCounter[id] = 0
|
||||
mountCounter[id] += 1
|
||||
setDoReconnect(true)
|
||||
console.log(`WSProvider ${id} mounted ${mountCounter[id]} time(s)`);
|
||||
|
||||
if (mountCounter[id] === 1 && (ws.current === null || ws.current.readyState >= WebSocket.CLOSING)){
|
||||
@ -94,6 +72,24 @@ export function WSProvider({url, onmessage, children}) {
|
||||
socket.onopen = () => setIsReady(true)
|
||||
socket.onclose = () => {
|
||||
setIsReady(false)
|
||||
if (mountCounter[id] > 0) {
|
||||
setTimeout(() => {
|
||||
//if (is_authenticated){
|
||||
console.log("WSProvider: reconnecting to", url);
|
||||
try {
|
||||
const newSocket = new WebSocket(url)
|
||||
ws.current = newSocket
|
||||
newSocket.onopen = socket.onopen
|
||||
newSocket.onclose = socket.onclose
|
||||
newSocket.onmessage = socket.onmessage
|
||||
}catch (e) {
|
||||
|
||||
}
|
||||
//}else{
|
||||
// console.log("WSProvider: not reconnecting, user is not authenticated");
|
||||
//}
|
||||
}, 5000)
|
||||
}
|
||||
}
|
||||
socket.onmessage = (event) => {
|
||||
const msg = JSON.parse(event.data)
|
||||
@ -136,7 +132,6 @@ export function WSProvider({url, onmessage, children}) {
|
||||
setTimeout(() => {
|
||||
console.log(`WSProvider ${id} checking for close, ${mountCounter[id]} instance(s) remain`);
|
||||
if (mountCounter[id] === 0) {
|
||||
setDoReconnect(false)
|
||||
console.log("WSProvider: closing connection to", url);
|
||||
ws.current.close()
|
||||
}
|
||||
@ -144,14 +139,13 @@ export function WSProvider({url, onmessage, children}) {
|
||||
}
|
||||
}, [])
|
||||
|
||||
const send2 = (uuid, code, type, data, resolve = () => {
|
||||
const send = (uuid, code, type, data, resolve = () => {
|
||||
}, reject = () => {
|
||||
}) => {
|
||||
if (!isReadyRef.current) {
|
||||
reject("WebSocket is not connected");
|
||||
return;
|
||||
}
|
||||
|
||||
if (type === "REQUEST") {
|
||||
const timeout = setTimeout(() => {
|
||||
reject("timeout");
|
||||
@ -178,26 +172,6 @@ export function WSProvider({url, onmessage, children}) {
|
||||
data: data
|
||||
}))
|
||||
}
|
||||
const send = (uuid, code, type, data, resolve = () => {
|
||||
}, reject = () => {
|
||||
}) => {
|
||||
if (isReadyRef.current) {
|
||||
send2(uuid, code, type, data, resolve, reject);
|
||||
}else {
|
||||
let counter = 0;
|
||||
const waitInterval = setInterval(() => {
|
||||
if (isReadyRef.current) {
|
||||
clearInterval(waitInterval);
|
||||
send2(uuid, code, type, data, resolve, reject);
|
||||
}
|
||||
counter += 1;
|
||||
if (counter >= 300) { // 30 seconds timeout
|
||||
clearInterval(waitInterval);
|
||||
reject("WebSocket is not connected");
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const ret = {isReady, dispatch, send, wait_length: callbackRef}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user