Skip to content

Commit

Permalink
refactor: remove bbb-demo support
Browse files Browse the repository at this point in the history
BREAKING CHANGE

This module support was included in this project as a temporary
substitute of the API calls.
  • Loading branch information
pedrobmarin committed May 23, 2021
1 parent 9c9e456 commit c8f1f11
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# <string> BigBlueButton hostname.
BIGBLUEBOT_HOST=

# <string> BigBlueButton secret.
BIGBLUEBOT_SECRET=

# <string> Running BigBlueButton server version.
BIGBLUEBOT_VERSION=

Expand All @@ -13,9 +16,6 @@ BIGBLUEBOT_VERSION=
# <string> Moderator password. Defaults to "mp"
# BIGBLUEBOT_MODERATOR_PW=

# <string> BigBlueButton secret. Defaults to null.
# BIGBLUEBOT_SECRET=

# <number> Number of bots to spawn. Defaults to 1.
# BIGBLUEBOT_BOTS=

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BigBlueButton bots

## Requirements

A BigBlueButton server with `bbb-demo` installed or setting the server API secret
A BigBlueButton server and it's API secret

## Instructions

Expand All @@ -22,7 +22,11 @@ At the `.env` file you just copied, set:
```
BIGBLUEBOT_HOST=https://your.bigbluebutton.server
```
- your BigBlueButton server running version (currently 2.2 or 2.3)
- your BigBlueButton server API secret
```
BIGBLUEBOT_SECRET=yourbigbluebuttonsecret
```
- your BigBlueButton server running version (currently 2.2 or 2.3)
```
BIGBLUEBOT_VERSION=2.2
```
Expand All @@ -38,10 +42,6 @@ instance as described [here](https://docs.bigbluebutton.org/dev/api.html#getmeet
```
BIGBLUEBOT_ATTENDEE_PW=yourattendeepassword
BIGBLUEBOT_MODERATOR_PW=yourmoderatorpassword
```
- [optional] your BigBlueButton server API secret
```
BIGBLUEBOT_SECRET=yourbigbluebuttonsecret
```
- [optional] number of bots to join the room
```
Expand Down Expand Up @@ -144,6 +144,7 @@ const actions = async page => {
const options = {
host: 'https://your.bigbluebutton.server',
secret: 'yourbigbluebuttonsecret',
version: '2.2' OR '2.3',
room: 'yourbigbluebuttonroomidentifier',
password: {
moderator: 'yourmoderatorpassword',
Expand Down
1 change: 0 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"host": null,
"version": "2.2",
"basename": "html5client",
"demo": "demo/demoHTML5.jsp?action=create",
"user": {
"param": "username"
},
Expand Down
26 changes: 16 additions & 10 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ const { api, bot, url, misc } = conf.config;

const dependencies = (options) => {
if (!url.host && !options.host) {
logger.error('BigBlueButton host is not defined');
logger.error(`BigBlueButton's host is not defined`);
return false;
}

if (!api.secret && !options.secret) {
logger.error(`BigBlueButton's secret is not defined`);
return false;
}

if (!url.version && !options.version) {
logger.error(`BigBlueButton's version is not defined`);
return false;
}

return true;
};

Expand All @@ -21,14 +32,9 @@ const run = async (actions, options = {}) => {
logger.info(`Bots: ${pool.size * pool.population}`);
logger.info(`Life: ${bot.life / 1000} seconds`);

// Assume a private room if the server secret was configured
const private = api.secret || options.secret;

// Create the meeting if not created yet
if (private) {
const success = await util.create(options);
if (!success) return null;
}
// Make sure the meeting running
const success = await util.create(options);
if (!success) return null;

// Fetch the UI labels from locale
const locale = await util.locale(options);
Expand Down Expand Up @@ -79,7 +85,7 @@ const run = async (actions, options = {}) => {
}

await Promise.all(browsers).finally(async () => {
if (private && misc.meeting.end) await util.end(options);
if (misc.meeting.end) await util.end(options);
});
};

Expand Down
19 changes: 4 additions & 15 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,11 @@ const delay = async time => new Promise(resolve => setTimeout(resolve, time));
const timestamp = () => Math.floor(new Date() / 1000);
const random = collection => collection[Math.floor(Math.random() * collection.length)];

const getDemoJoinURL = (username, options) => {
const user = `${config.url.user.param}=${encodeURI(username)}`;
const moderator = `${config.url.moderator.param}=${options.moderator !== undefined ? options.moderator : config.url.moderator.value}`;
const meeting = `${config.url.meeting.param}=${encodeURI(options.room || config.url.meeting.name)}`;

return `${options.host || config.url.host}/${config.url.demo}&${user}&${moderator}&${meeting}`;
};

const getAPIJoinURL = (username, options) => {
return api.getJoinURL(username, options);
};

const url = (username, options) => {
if (config.api.secret || options.secret) return getAPIJoinURL(username, options);

return getDemoJoinURL(username, options);
};
const url = (username, options) => getAPIJoinURL(username, options);

const once = async (page, event, callback) => {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -240,11 +228,12 @@ module.exports = {
const { lang } = config.browser;
logger.info(`Fetching ${lang} locale`);
const host = options.host || config.url.host;
const version = options.version || config.url.version;
const client = `${host}/${config.url.basename}`;
const url = `${client}/locale?locale=${lang}`;
let locale;
await axios.get(url).then(async response => {
switch (config.url.version) {
switch (version) {
case '2.2':
const { messages } = response.data;
if (messages) {
Expand All @@ -263,7 +252,7 @@ module.exports = {
});
break;
default:
logger.error(`BigBlueButton's server version not configured`);
logger.error(`Invalid BigBlueButton's server version: ${version}`);
}
}).catch(error => {
logger.error(error);
Expand Down

0 comments on commit c8f1f11

Please sign in to comment.