gregsadetsky / rctv

https://rctv.recurse.com
4 stars 2 forks source link

implement unloading of app that uses api but doesn't call onload fast enough ((or dont....?)) #16

Open gregsadetsky opened 1 year ago

gregsadetsky commented 1 year ago
const TIME_LIMIT = 15 * 1000; /* 15 seconds */
const GET_RC_PAYLOAD = 'getRCPayload'
const SDK_LOADED_START = 'sdkLoadedStart'
const SDK_LOADED_END = 'sdkLoadedEnd'

let timeoutID = null;

window.onmessage = (event) => {
    const data = event.data;
    const iframe = event.source.window;
    switch (data.type) {
        case GET_RC_PAYLOAD:
            {
                iframe.postMessage({
                    type: 'RCPayload',
                    payload: window.rcPayload
                }, '*');
                break;
            }
        case SDK_LOADED_START:
            {
                timeoutID = setTimeout(() => {
                    alert("HAHA SLOW COMPUTER MONKEY")
                    // TODO: Go to the next iframe
                }, TIME_LIMIT)
                break;
            }
        case SDK_LOADED_END:
            {
                if (timeoutID) { clearTimeout(timeoutID) }
                break;
            }
    }
}
gregsadetsky commented 1 year ago

(probably, approximately)