Skip to content

Commit

Permalink
Initial commit from private branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-allen-89 committed Jan 31, 2023
1 parent ec1717d commit ca6c78b
Show file tree
Hide file tree
Showing 21 changed files with 4,944 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions .rebuild-ui
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 4 additions & 0 deletions adapt-authoring.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
{
"module": true,
"documentation": {
"enable": true
}
}
6 changes: 3 additions & 3 deletions conf/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"isTemplate": {
"websocketURL": {
"description": "Whether this module is a template",
"type": "boolean",
"default": true
"type": "string",
"default": "ws://localhost:3000"
}
}
}
2 changes: 0 additions & 2 deletions docs/template-doc.md

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './lib/TemplateModule.js';
export { default } from "./lib/CollaborationModule.js";
3 changes: 0 additions & 3 deletions lang/en.json

This file was deleted.

70 changes: 70 additions & 0 deletions lib/CollaborationModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { AbstractModule } from "adapt-authoring-core";
import path from "path";
import WebSocket from "ws";
import express from "express";
import * as http from "http";

/**
* Module to implement Totara connect API
* @extends {AbstractModule}
*/
class CollaborationModule extends AbstractModule {
/** @override */

async init() {
// do custom initialisation here
const server = await this.app.waitForModule("server");
const PORT = 5000;
const app = express();
// const server = http.createServer(app);
const wsServer = new WebSocket.Server({
server: server
});

wsServer.on("connection", function connection(ws) {
ws.send("Welcome New Client!");

ws.on("message", function incoming(message) {
wsServer.clients.forEach(function each(client) {
if (client !== ws && client.readyState === WebSocket.OPEN) {
client.send(message);
}
});
});
});

app.get("/", (req, res) => res.send("Hello World!"));

server.listen(3000, () => console.log(`Lisening on port :3000`));

await this.initRouter();
const ui = await this.app.waitForModule("ui");
ui.addUiPlugin(path.resolve(this.rootDir, "plugins"));
}

async initRouter() {
const [auth, server] = await this.app.waitForModule("auth", "server");
const router = server.api.createChildRouter("adaptcollab");
[
{
route: "/getUser",
handlers: { get: this.returnUser.bind(this) }
}
].forEach((r) => {
router.addRoute({ route: r.route, handlers: r.handlers });
Object.entries(r.handlers).forEach(([method]) => {
const scopes =
method === "get" ? ["read:adaptcollab"] : ["write:adaptcollab"];
auth.secureRoute(`${router.path}${r.route}`, method, scopes);
});
});
}

async returnUser(req, res, next) {
const users = await this.app.waitForModule("users");
const currentUSer = await users.find({ _id: req.auth.user._id });
res.json(currentUSer);
}
}

export default CollaborationModule;
8 changes: 0 additions & 8 deletions lib/TemplateModule.js

This file was deleted.

Loading

0 comments on commit ca6c78b

Please sign in to comment.