|
1 | | -import { all, call, fork, put, takeEvery, takeLatest, select, takeLeading } from 'redux-saga/effects'; |
| 1 | +import type { Task } from 'redux-saga'; |
| 2 | +import { all, call, cancel, fork, put, takeEvery, takeLatest, select, takeLeading } from 'redux-saga/effects'; |
2 | 3 | import { auth } from '../../api/auth'; |
3 | 4 | import { |
4 | 5 | accountEditFailed, |
@@ -66,6 +67,7 @@ import { getUTMParams, IUserUtm } from '../../views/user/utils/utmParams'; |
66 | 67 | import { clearAppFilters, setGeneralLoaderVisibility } from '../general/actions'; |
67 | 68 | import { getQueryStringParams, history } from '../../utils/history'; |
68 | 69 | import { watchWsEvents } from '../realtime/watchWsEvents'; |
| 70 | +import { closeAllConnections } from '../utils/webSocketConnections'; |
69 | 71 | import { TUploadedFile, uploadUserAvatar } from '../../utils/uploadFiles'; |
70 | 72 | import { changePhotoProfile } from '../../api/changePhotoProfile'; |
71 | 73 | import { ELoggedState, IAuthUser } from '../../types/redux'; |
@@ -268,6 +270,7 @@ export function* registerWithInvite({ payload }: TRegisterUserInvited) { |
268 | 270 | } |
269 | 271 |
|
270 | 272 | function* handleLogoutUnsubscribing({ shouldExpireToken }: { shouldExpireToken: boolean }) { |
| 273 | + yield call(stopWatchWsEvents); |
271 | 274 | yield put(clearAppFilters()); |
272 | 275 | resetFirebaseDeviceToken(); |
273 | 276 | resetSuperuserToken(); |
@@ -688,12 +691,24 @@ export function* watchSetUserToken() { |
688 | 691 | yield takeEvery(EAuthActions.SetToken, handleSetUserToken); |
689 | 692 | } |
690 | 693 |
|
| 694 | +let watchWsEventsTask: Task | undefined; |
| 695 | + |
| 696 | +function* stopWatchWsEvents() { |
| 697 | + if (watchWsEventsTask) { |
| 698 | + yield cancel(watchWsEventsTask); |
| 699 | + watchWsEventsTask = undefined; |
| 700 | + } |
| 701 | + |
| 702 | + yield call(closeAllConnections); |
| 703 | +} |
| 704 | + |
691 | 705 | function* handleWatchUserWSEvents() { |
692 | | - yield fork(watchWsEvents); |
| 706 | + yield call(stopWatchWsEvents); |
| 707 | + watchWsEventsTask = yield fork(watchWsEvents); |
693 | 708 | } |
694 | 709 |
|
695 | 710 | export function* watchUserWSEvents() { |
696 | | - yield takeEvery(EAuthActions.WatchUserWSEvents, handleWatchUserWSEvents); |
| 711 | + yield takeLeading(EAuthActions.WatchUserWSEvents, handleWatchUserWSEvents); |
697 | 712 | } |
698 | 713 |
|
699 | 714 | export function* watchUploadUserPhoto() { |
|
0 commit comments