meetecho / janus-gateway

Janus WebRTC Server
https://janus.conf.meetecho.com
GNU General Public License v3.0
8.17k stars 2.47k forks source link

Added UMD #3377

Closed redexp closed 3 months ago

redexp commented 4 months ago

No braking changes, but now this file can be treat as module for commonjs or require.js or have regular global Janus var

I used this UMD template https://github.com/umdjs/umd/blob/master/templates/returnExports.js

januscla commented 4 months ago

Thanks for your contribution, @redexp! Please make sure you sign our CLA, as it's a required step before we can merge this.

redexp commented 4 months ago

Another pros - you can define as many private var as you need. Like that var defaultExtension that I assumed should be private, but right now it's in global scope and could be overwritten in some other file.

lminiero commented 4 months ago

I'm not knowledgeable about JavaScript enough to have an opinion: I only care that this doesn't break existing demos. I'll leave @atoppi to evaluate if this could cause us problems. I do notice that this apparently didn't pass our linter check on Github Actions, though.

redexp commented 4 months ago

linter errors on typeof define I think if I change it to typeof root.define then it should pass linter

redexp commented 4 months ago

@atoppi

    28:38  error    'define' is not defined                       no-undef
    29:3   error    'define' is not defined                       no-undef
    30:43  error    'module' is not defined                       no-undef
    31:3   error    'module' is not defined                       no-undef
atoppi commented 4 months ago

@redexp yeah, please fix those and also the issues about indentation. If you wanna test locally before triggering our github workflow, just use eslint janus.js with our eslint configuration file (.eslintrc.js).

redexp commented 3 months ago

@atoppi I'v added rule to ignore one indent in main part code. It's ok practice with UMD, eslint itself shows example how to do it

atoppi commented 3 months ago

Merging, I'll figure out how to better fix the eslint stuff by myself.

atoppi commented 3 months ago

@redexp add to do a bunch of modifications due to the broken rollup script after your merge. Can you test if this still works for you after the commit above?

redexp commented 3 months ago

instead of this

var Janus = (function (factory) {
    if (...) {
        ...
    } else if (typeof window === 'object') {
        return factory();
    }

I'd rather do like

(function (factory) {
    if (...) {
        ...
    } else if (typeof window === 'object') {
        window.Janus = factory();
    }
atoppi commented 3 months ago

Unfortunately we have a rollup script that bundles janus.js in an es module. It basically takes this template, replaces @JANUS_CODE@ with the content of janus.js and exports a Janus object, hence we need that object to be explicitly declared by janus.js.