@@ -14,13 +14,14 @@ import {
1414} from '../actions' ;
1515import {
1616 selectInfoResponses ,
17+ selectProbeResponses ,
1718 getVisibleCanvases ,
1819 getWindows ,
1920 getConfig ,
2021 getAuth ,
2122 getAccessTokens ,
2223} from '../selectors' ;
23- import { fetchInfoResponse } from './iiif' ;
24+ import { fetchInfoResponse , fetchProbeResponse } from './iiif' ;
2425
2526/** */
2627export function * refetchInfoResponsesOnLogout ( { tokenServiceId } ) {
@@ -70,6 +71,54 @@ export function* refetchInfoResponses({ serviceId }) {
7071 } ) ) ;
7172}
7273
74+ /** */
75+ export function * refetchProbeResponsesOnLogout ( { tokenServiceId } ) {
76+ // delay logout actions to give the cookie service a chance to invalidate our cookies
77+ // before we reinitialize openseadragon and rerequest images.
78+
79+ yield delay ( 2000 ) ;
80+ yield call ( refetchProbeResponses , { serviceId : tokenServiceId } ) ;
81+ }
82+
83+ /**
84+ * Figure out what info responses could have used the access token service and:
85+ * - refetch, if they are currently visible
86+ * - throw them out (and lazy re-fetch) otherwise
87+ */
88+ export function * refetchProbeResponses ( { serviceId } ) {
89+ const windows = yield select ( getWindows ) ;
90+
91+ const canvases = yield all (
92+ Object . keys ( windows ) . map ( windowId => select ( getVisibleCanvases , { windowId } ) ) ,
93+ ) ;
94+
95+ const visibleProbeServiceIds = flatten ( flatten ( canvases ) . map ( ( canvas ) => {
96+ const miradorCanvas = new MiradorCanvas ( canvas ) ;
97+ return miradorCanvas . imageResources . filter ( ( r ) => getProbeService ( r ) ) . map ( ( r ) => getProbeService ( r ) ) ;
98+ } ) ) ;
99+
100+ const probeResponses = yield select ( selectProbeResponses ) ;
101+ /** */
102+ const haveThisTokenService = probeResponse => {
103+ const services = Utils . getServices ( probeResponse ) ;
104+ return services . some ( e => {
105+ const probeTokenService = getTokenService ( e ) ;
106+ return probeTokenService && probeTokenService . id === serviceId ;
107+ } ) ;
108+ } ;
109+
110+ const obsoleteProbeResponses = Object . values ( probeResponses ) . filter (
111+ i => i . json && haveThisTokenService ( i . json ) ,
112+ ) ;
113+
114+ yield all ( obsoleteProbeResponses . map ( ( { id : probeId } ) => {
115+ if ( visibleProbeServiceIds . includes ( probeId ) ) {
116+ return call ( fetchProbeResponse , { probeId } ) ;
117+ }
118+ return put ( { probeId, type : ActionTypes . REMOVE_PROBE_RESPONSE } ) ;
119+ } ) ) ;
120+ }
121+
73122/** try to start any non-interactive auth flows */
74123export function * doAuthWorkflow ( { infoJson, windowId } ) {
75124 const auths = yield select ( getAuth ) ;
@@ -152,9 +201,13 @@ export function* invalidateInvalidAuth({ serviceId }) {
152201export default function * authSaga ( ) {
153202 yield all ( [
154203 takeEvery ( ActionTypes . RECEIVE_DEGRADED_INFO_RESPONSE , rerequestOnAccessTokenFailure ) ,
204+ takeEvery ( ActionTypes . RECEIVE_DEGRADED_PROBE_RESPONSE , rerequestOnAccessTokenFailure ) ,
155205 takeEvery ( ActionTypes . RECEIVE_ACCESS_TOKEN_FAILURE , invalidateInvalidAuth ) ,
156206 takeEvery ( ActionTypes . RECEIVE_DEGRADED_INFO_RESPONSE , doAuthWorkflow ) ,
207+ takeEvery ( ActionTypes . RECEIVE_DEGRADED_PROBE_RESPONSE , doAuthWorkflow ) ,
157208 takeEvery ( ActionTypes . RECEIVE_ACCESS_TOKEN , refetchInfoResponses ) ,
209+ takeEvery ( ActionTypes . RECEIVE_ACCESS_TOKEN , refetchProbeResponses ) ,
158210 takeEvery ( ActionTypes . RESET_AUTHENTICATION_STATE , refetchInfoResponsesOnLogout ) ,
211+ takeEvery ( ActionTypes . RESET_AUTHENTICATION_STATE , refetchProbeResponsesOnLogout ) ,
159212 ] ) ;
160213}
0 commit comments