fix(iframe_api): Change the format of the arguments in the constructor

This commit is contained in:
hristoterezov 2017-07-13 14:23:54 -05:00 committed by yanas
parent 3736d6ca78
commit 70122789e7
2 changed files with 98 additions and 43 deletions

View File

@ -9,54 +9,56 @@ To embed Jitsi Meet in your application you need to add the Jitsi Meet API libra
```javascript
<script src="https://meet.jit.si/external_api.js"></script>
```
## API
### `api = new JitsiMeetExternalAPI(domain, room, [width], [height], [htmlElement], [configOverwite], [interfaceConfigOverwrite], [noSsl], [jwt])`
### `api = new JitsiMeetExternalAPI(domain, options)`
The next step for embedding Jitsi Meet is to create the Jitsi Meet API object.
Its constructor gets a number of options:
* **domain**: domain used to build the conference URL, "meet.jit.si" for
example.
* **room**: name of the room to join.
* **width**: (optional) width for the iframe which will be created.
* **height**: (optional) height for the iframe which will be created.
* **htmlElement**: (optional) HTL DOM Element where the iframe will be added as
a child.
* **configOverwite**: (optional) JS object with overrides for options defined in
[config.js].
* **interfaceConfigOverwrite**: (optional) JS object with overrides for options
defined in [interface_config.js].
* **noSsl**: (optional, defaults to true) Boolean indicating if the server
should be contacted using HTTP or HTTPS.
* **jwt**: (optional) [JWT](https://jwt.io/) token.
* **options**: object with properties - the optional arguments:
* **room**: (optional) name of the room to join.
* **width**: (optional) width for the iframe which will be created.
* **height**: (optional) height for the iframe which will be created.
* **htmlElement**: (optional) HTL DOM Element where the iframe will be added as a child.
* **configOverwite**: (optional) JS object with overrides for options defined in [config.js].
* **interfaceConfigOverwrite**: (optional) JS object with overrides for options defined in [interface_config.js].
* **noSsl**: (optional, defaults to true) Boolean indicating if the server should be contacted using HTTP or HTTPS.
* **jwt**: (optional) [JWT](https://jwt.io/) token.
Example:
```javascript
var domain = "meet.jit.si";
var room = "JitsiMeetAPIExample";
var width = 700;
var height = 700;
var htmlElement = document.querySelector('#meet');
var api = new JitsiMeetExternalAPI(domain, room, width, height, htmlElement);
var options = {
domain: "meet.jit.si",
room: "JitsiMeetAPIExample",
width: 700,
height: 700,
htmlElement: document.querySelector('#meet')
}
var api = new JitsiMeetExternalAPI(domain, options);
```
You can overwrite options set in [config.js] and [interface_config.js].
For example, to enable the filmstrip-only interface mode, you can use:
```javascript
var interfaceConfigOverwrite = {filmStripOnly: true};
var api = new JitsiMeetExternalAPI(domain, room, width, height, undefined, undefined, interfaceConfigOverwrite);
var options = {
interfaceConfigOverwrite: {filmStripOnly: true}
};
var api = new JitsiMeetExternalAPI(domain, options);
```
You can also pass a jwt token to Jitsi Meet:
```javascript
var jwt = "<jwt_token>";
var noSsl = false;
var api = new JitsiMeetExternalAPI(domain, room, width, height, htmlElement, configOverwrite, interfaceConfigOverwrite, noSsl, jwt);
var options = {
jwt: "<jwt_token>",
noSsl: false
};
var api = new JitsiMeetExternalAPI(domain, options);
```
### Controlling the embedded Jitsi Meet Conference

View File

@ -142,6 +142,54 @@ function generateURL(domain, options = {}) {
return url;
}
/**
* Parses the arguments passed to the constructor. If the old format is used
* the function translates the arguments to the new format.
*
* @param {Array} args - The arguments to be parsed.
* @returns {Object} JS object with properties.
*/
function parseArguments(args) {
if (!args.length) {
return {};
}
const firstArg = args[0];
switch (typeof firstArg) {
case 'string': // old arguments format
case undefined: // eslint-disable-line no-case-declarations
// not sure which format but we are trying to parse the old
// format because if the new format is used everything will be undefined
// anyway.
const [
roomName,
width,
height,
parentNode,
configOverwrite,
interfaceConfigOverwrite,
noSSL,
jwt
] = args;
return {
roomName,
width,
height,
parentNode,
configOverwrite,
interfaceConfigOverwrite,
noSSL,
jwt
};
case 'object': // new arguments format
return args[0];
default:
throw new Error('Can\'t parse the arguments!');
}
}
/**
* The IFrame API interface class.
*/
@ -151,29 +199,34 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
*
* @param {string} domain - The domain name of the server that hosts the
* conference.
* @param {string} [roomName] - The name of the room to join.
* @param {number} [width] - Width of the iframe.
* @param {number} [height] - Height of the iframe.
* @param {DOMElement} [parentNode] - The node that will contain the
* @param {Object} [options] - Optional arguments.
* @param {string} [options.roomName] - The name of the room to join.
* @param {number} [options.width] - Width of the iframe.
* @param {number} [options.height] - Height of the iframe.
* @param {DOMElement} [options.parentNode] - The node that will contain the
* iframe.
* @param {Object} [configOverwrite] - Object containing configuration
* options defined in config.js to be overridden.
* @param {Object} [interfaceConfigOverwrite] - Object containing
* @param {Object} [options.configOverwrite] - Object containing
* configuration options defined in config.js to be overridden.
* @param {Object} [options.interfaceConfigOverwrite] - Object containing
* configuration options defined in interface_config.js to be overridden.
* @param {boolean} [noSSL] - If the value is true https won't be used.
* @param {string} [jwt] - The JWT token if needed by jitsi-meet for
* @param {boolean} [options.noSSL] - If the value is true https won't be
* used.
* @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
* authentication.
*/
constructor(domain, // eslint-disable-line max-params
roomName = '',
width = MIN_WIDTH,
height = MIN_HEIGHT,
parentNode = document.body,
configOverwrite = {},
interfaceConfigOverwrite = {},
noSSL = false,
jwt = undefined) {
constructor(domain, ...args) {
super();
const {
roomName = '',
width = MIN_WIDTH,
height = MIN_HEIGHT,
parentNode = document.body,
configOverwrite = {},
interfaceConfigOverwrite = {},
noSSL = false,
jwt = undefined
} = parseArguments(args);
this._parentNode = parentNode;
this._url = generateURL(domain, {
configOverwrite,