From 714cd6c1336b89f639e65842f7a967a3a76be359 Mon Sep 17 00:00:00 2001
From: Felipe Cecagno <fcecagno@gmail.com>
Date: Tue, 21 Aug 2018 14:23:17 -0300
Subject: [PATCH] add domain to webhooks events

---
 bbb-webhooks/Dockerfile              | 12 ++++++------
 bbb-webhooks/callback_emitter.js     |  8 +++++---
 bbb-webhooks/config_local.js.example |  1 +
 labs/docker/docker-compose.yml       |  1 +
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/bbb-webhooks/Dockerfile b/bbb-webhooks/Dockerfile
index 39d1b3dc31..afa9470fdc 100644
--- a/bbb-webhooks/Dockerfile
+++ b/bbb-webhooks/Dockerfile
@@ -1,16 +1,16 @@
 FROM node:8
 
-ADD . /source
-RUN cp /source/config_local.js.example /source/config_local.js
+ADD . app
+
+WORKDIR app
+
+RUN cp config_local.js.example config_local.js
 
 ENV NODE_ENV production
 
-RUN cd /source \
- && npm install \
+RUN npm install \
  && npm cache clear --force
 
-WORKDIR /source
-
 EXPOSE 3005
 
 CMD ["node", "app.js"]
diff --git a/bbb-webhooks/callback_emitter.js b/bbb-webhooks/callback_emitter.js
index b05e55b3e4..6ec7d55363 100644
--- a/bbb-webhooks/callback_emitter.js
+++ b/bbb-webhooks/callback_emitter.js
@@ -62,17 +62,19 @@ module.exports = class CallbackEmitter extends EventEmitter {
 
   _emitMessage(callback) {
     let data,requestOptions;
+    const serverDomain = process.env.SERVER_DOMAIN || config.bbb.serverDomain;
     const sharedSecret = process.env.SHARED_SECRET || config.bbb.sharedSecret;
-    const bearer_auth = process.env.BEARER_AUTH || config.bbb.auth2_0;
+    const bearerAuth = process.env.BEARER_AUTH || config.bbb.auth2_0;
 
     // data to be sent
     // note: keep keys in alphabetical order
     data = {
       event: "[" + this.message + "]",
-      timestamp: this.timestamp
+      timestamp: this.timestamp,
+      domain: serverDomain
     };
 
-    if (bearer_auth) {
+    if (bearerAuth) {
       const callbackURL = this.callbackURL;
 
       requestOptions = {
diff --git a/bbb-webhooks/config_local.js.example b/bbb-webhooks/config_local.js.example
index 0a64ac0d5f..0bebd13924 100644
--- a/bbb-webhooks/config_local.js.example
+++ b/bbb-webhooks/config_local.js.example
@@ -4,6 +4,7 @@ const config = {};
 
 // Shared secret of your BigBlueButton server.
 config.bbb = {};
+config.bbb.serverDomain = "myserver.com";
 config.bbb.sharedSecret = "mysharedsecret";
 // Whether to use Auth2.0 or not, Auth2.0 sends the sharedSecret whithin an Authorization header as a bearer
 config.bbb.auth2_0 = false;
diff --git a/labs/docker/docker-compose.yml b/labs/docker/docker-compose.yml
index fa0c49db4f..85310cab37 100644
--- a/labs/docker/docker-compose.yml
+++ b/labs/docker/docker-compose.yml
@@ -33,6 +33,7 @@ services:
       REDIS_HOST: redis
       SHARED_SECRET: ${SHARED_SECRET}
       BEARER_AUTH: 1
+      SERVER_DOMAIN: ${SERVER_DOMAIN}
     labels:
       - "traefik.backend=bbb-webhooks"
       - "traefik.frontend.rule=PathPrefix: /bigbluebutton/api/hooks"
-- 
GitLab