'Adobe PDF Embed API can not change the pdf

I want to show a PDF in a brower and change the PDF to a different one when a message (with the name of the new file) was send to the webside via a websocket.

I user Adobe PDF Embed API to show the PDF.

const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const selecteddocument = urlParams.get('document')
const terminalNumber = urlParams.get('terminal')

const viewerConfig = {
    /* Allowed possible values are "FIT_PAGE", "FIT_WIDTH" or "" */
    defaultViewMode: "",
    showPageControls: true,
    showAnnotationTools: false,
    showLeftHandPanel: false,
    showPrintPDF: false,
    showDownloadPDF: false,
    enableFormFilling: false,
    defaultViewMode: "CONTINUOUS"

};
/* Wait for Adobe Document Services PDF Embed API to be ready */
document.addEventListener("adobe_dc_view_sdk.ready", function () {
    /* Initialize the AdobeDC View object */
    var adobeDCView = new AdobeDC.View({
        /* Pass your registered client id */
        clientId: "",
        /* Pass the div id in which PDF should be rendered */
        divId: "adobe-dc-view",
    });

    updatePDF("ENG-000062");
    function updatePDF(message) {
        console.log(message)
        /* Invoke the file preview API on Adobe DC View object */
        adobeDCView.previewFile({
            /* Pass information on how to access the file */
            content: {
                /* Location of file where it is hosted */
                location: {
                    url: "http://localhost:5001/documents/" + message + ".pdf",

                },
            },
            /* Pass meta data of file */
            metaData: {
                /* file name */
                fileName: message
            }
        }, viewerConfig);
    }


    (async function() {


        async function connectToServer() {
            const ws = new WebSocket('ws://localhost:7071/ws');
            return new Promise((resolve, reject) => {
                const timer = setInterval(() => {
                    if(ws.readyState === 1) {
                        clearInterval(timer);
                        resolve(ws);
                    }
                }, 10);
            });
        }

        const ws = await connectToServer();
        ws.send('{"TerminalID": 1}');
/*        ws.onmessage = (webSocketMessage) => {
            const messageBody = JSON.parse(webSocketMessage.data);
            console.log(messageBody.document);
            updatePDF(messageBody.document);
        };*/
        // Listen for messages
        ws.addEventListener('message', function (event) {
          const messageBody = JSON.parse(event.data);
          console.log(messageBody.document);
          updatePDF(messageBody.document);
        });

    })();
});

When I try to open a different file I get

Uncaught Error: [mobx] Invariant failed: Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an action if this change is intended. Tried to modify: [email protected]

How to fix this



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source