Skip to content

Commit

Permalink
Merge pull request #299 from ResultadosDigitais/remote-room-data
Browse files Browse the repository at this point in the history
add a remote room file option
  • Loading branch information
juliemar authored Apr 8, 2020
2 parents f2cfb82 + bdab66e commit 5771883
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The **#matrix** project has some environment variables that important to define.

- The **#matrix** needs to know, where it get rooms definitions:

ROOMS_SOURCE=ENVIRONMENT
ROOMS_SOURCE=ENVIRONMENT | REMOTE

- There is a config that define the rooms of The **#matrix**, If you want to customize your rooms or add and a new room, you have to configure a `ROOMS_SOURCE=ENVIRONMENT` and config `ROOMS_DATA` like the example:

Expand All @@ -109,6 +109,10 @@ The **#matrix** project has some environment variables that important to define.
}
]

Another option is to have a remote rooms config file (this file needs to be accessible via http/s). You can configure a `ROOMS_SOURCE=REMOTE` and config `ROOMS_DATA` like the example:

ROOMS_DATA=https://myfilelocation.io/myrooms_data.json


#### External Meet
The embeded meet is provided by [meet.jit.si](https://meet.jit.si) service, but you can change that in any room, using serices like [Meet](https://meet.google.com/) or [Zoom](https://zoom.us/). For that, you just need provide the parameter `externalMeetUrl` in your room config:
Expand Down
22 changes: 21 additions & 1 deletion backend/app/controllers/rooms.controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "fs";
import uuid from "uuid/v4";
import path from "path";
import request from "request";

const roomFilePath = "../file/matrix.room.web.json";

Expand Down Expand Up @@ -55,11 +56,30 @@ const fetchFromEnvironment = (env) => {
return new Promise(resolve => resolve(roomsDetail));
};

const fetchFromRemote = (env) => {

let url = env.ROOMS_DATA;

return new Promise(function(resolve, reject){
request(url, function (error, response, body) {
// in addition to parsing the value, deal with possible errors
if (error) return reject(error);
try {
// JSON.parse() can throw an exception if not valid JSON
resolve(JSON.parse(body));
} catch(e) {
reject(e);
}
});
});
};

const fetchRooms = (strategy) => {
switch (strategy) {
// TODO add suport to fetch from endpoint
case "ENVIRONMENT":
return fetchFromEnvironment(process.env);
case "REMOTE":
return fetchFromRemote(process.env);
default:
return fetchFromFile();
}
Expand Down

0 comments on commit 5771883

Please sign in to comment.