Support for SPAs / error when reloading (quick fix!)

Description
I’ve been working on getting the web sdk working inside a Single Page Application style site. Because the ZoomMtg object creates the #zmmtg-root element when it’s loaded, I made it only load the SDK on the vue-routed page which needs it.

I have it destroying/unloading the ZoomMtg object when the user navigates away, but when they navigate back again, there are some issues with Object.defineProperty things that the zoomus-websdk.umd.min.js file applies.

These are Array.prototype.uniquelize, Array.prototype.union, and Array.prototype.minus.

The quick fix is to match other is-this-set checks in the same file , e.g. Array.prototype.union || Object.defineProperty(Array.prototype,"union"

The better fix would be to mark all of the properties as configurable, and add a ZoomMtg.unload to unset them all, among other things. The even better fix would be to allow deferred activation too, so I can load the sdk with my other javascript!

Browser Console Error
Uncaught TypeError: Cannot redefine property: uniquelize
at Function.defineProperty ()

Which Web Meeting SDK version?
2.0.1

Meeting SDK Code Snippets
node_modules/@zoomus/websdk/dist/zoomus-websdk.umd.min.js, prettified

Array.prototype.intersect || Object.defineProperty(Array.prototype, "intersect", {
    enumerable: !1,
    value: function() {
        for (var e = new Array, t = {}, n = 0; n < arguments.length; n++)
            for (var r = 0; r < arguments[n].length; r++) {
                var o = arguments[n][r];
                t[o] ? (t[o]++,
                t[o] === arguments.length && e.push(o)) : t[o] = 1
            }
        return e
    }
}),
Object.defineProperty(Array.prototype, "uniquelize", {
    enumerable: !1,
    value: function() {
        for (var e = {}, t = [], n = 0, r = this.length; n < r; n++)
            e[this[n]] || (e[this[n]] = 1,
            t.push(this[n]));
        return t
    }
}),
String.prototype.startsWith || Object.defineProperty(Array.prototype, "startsWith", {
    enumerable: !1,
    value: function(e, t) {
        return t = t || 0,
        this.indexOf(e, t) === t
    }
}),
Object.defineProperty(Array.prototype, "union", {
    enumerable: !1,
    value: function() {
        for (var e = new Array, t = {}, n = 0; n < arguments.length; n++)
            for (var r = 0; r < arguments[n].length; r++) {
                var o = arguments[n][r];
                t[o] || (t[o] = 1,
                e.push(o))
            }
        return e
    }
}),
Object.defineProperty(Array.prototype, "minus", {
    enumerable: !1,
    value: function(e) {
        for (var t = new Array, n = {}, r = 0; r < e.length; r++)
            n[e[r]] = 1;
        for (var o = 0; o < this.length; o++)
            n[this[o]] || (n[this[o]] = 1,
            t.push(this[o]));
        return t
    }
});

To Reproduce(If applicable)
Steps to reproduce the behavior:

  1. Give the SDK its own public js file. I have webpack mix working on a source file with import {ZoomMtg} from "@zoomus/websdk"; etc
  2. Load the js file when the component mounts
  3. Remove the file when the component unmounts, delete #zmmtg-root
  4. Load the js file a second time when the component mounts again.

Device (please complete the following information):

  • Browser: Chrome, but all of them

For anyone else hoping to fix this themselves, here’s the regex to use with mix.after() or similar:

/,Object\.defineProperty\(Array\.prototype,"(.+?)"/g,
 ',Array.prototype.$1||Object.defineProperty(Array.prototype,"$1"',

Hey @bitcrush-robin,

Thank you for reaching out to the Zoom Developer Forum and for sharing your workaround!

I think that functionality to defer the loading of the SDK or manually unload it would definitely be valuable. Would you be able to create a feature request in our #feature-requests category and send the link to me? I’ll send that to our engineering team to make sure it’s prioritized.

Thanks,
Max

Hi @MaxM, thanks for the reply.

I’ve posted here now: Web SDK Support for deferred load and unloading, for SPA sites

1 Like

Hi. @bitcrush-robin,

Thank you for the update! Please be assured we will share this your feedback with our engineer team. In the meantime, please be sure to subscribe to our blog, and change log for the latest news, updates, and fixes.

Best,
Donte

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.