generally generalized, version updated to 1.2

This commit is contained in:
Josh Burman 2019-12-20 16:52:14 -05:00
parent 5c095c23ad
commit 60562c3139
8 changed files with 14 additions and 19 deletions

View File

@ -1,4 +1,4 @@
# BRAID v1.0.8
# BRAID v1.2
> Websocket server for the Measure platform
[![Build Status](https://semaphoreci.com/api/v1/projects/7767f0f3-4da6-4c84-9167-4db5402a3262/2573412/badge.svg)](https://semaphoreci.com/yardstick/braid)
@ -47,10 +47,10 @@ braid:
hmac_secret = "test"
payload = {
:data => {
:client => 'client name (mhs is only one implemented currently)',
:client_type => 'site (only one in use rite now)',
:channel_type => 'public/private/custom',
:client_type => 'public/private/custom',
:user_id => (yardstick user id),
:user_type => '(teacher/user)',
:user_roles => and array with any combination of broadcaster/receiver/super,
:channel => 'desired channel name'
},
:sub => 'Braid JWT',

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "braid",
"version": "1.0.0",
"version": "1.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "braid",
"version": "1.0.0",
"version": "1.2",
"description": "",
"main": "index.js",
"scripts": {

View File

@ -6,7 +6,7 @@ var logger = require('../../logger');
class PrivateChannel extends ChannelBase {
broadcastMessage(from: PrivateClient, message: any) {
for (let client of this.clients) {
if (client != from && client.data.user_type != from.data.user_type) {
if (client != from && client.roles.includes('receiver') && from.roles.includes('broadcaster')) {
console.log('sending message: ' + JSON.stringify(message))
client.ws.send(JSON.stringify(message));
logger.accessLog.info(`sent to ${client.id}`, { data: { message: message }});

View File

@ -14,6 +14,7 @@ class ClientBase {
channel: ChannelBase|Private|null;
clientManager: ClientManager;
channelManager: ChannelManager;
roles: Array<string>;
constructor(data: any, ws: WebSocket, channelManager: ChannelManager, clientManager: ClientManager) {
this.ws = ws;
@ -22,6 +23,7 @@ class ClientBase {
this.channel = null;
this.clientManager = clientManager;
this.channelManager = channelManager;
this.roles = ['receiver']
}
getData() {

View File

@ -3,11 +3,13 @@ import ClientBase from '../clientBase';
import ClientManager from '../../clientManager';
import ChannelManager from '../../channelManager';
var logger = require('../logger');
var logger = require('../../logger');
class PrivateClient extends ClientBase {
constructor(data: any, ws: WebSocket, channelManager: ChannelManager, clientManager: ClientManager) {
super(data, ws, channelManager, clientManager);
this.roles = data.user_roles
logger.accessLog.info('Private Client Created', {data: data});
}
};

View File

@ -1,5 +1,5 @@
module.exports = {
version : '1.0.8',
version : '1.2',
whitelist : (process.env.WHITELIST || "http://admin.localhost").split(','),
secret : process.env.SECRET || "test",
devToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImNsaWVudCI6InRlc3QiLCJjbGllbnRfdHlwZSI6InNpdGUiLCJ1c2VyX3R5cGUiOiJ1c2VyIiwidXNlcl9pZCI6MjAwLCJjaGFubmVsIjoidGVzdF9jaGFubmVsIn0sImF1ZCI6ImludGVybmFsIiwiaXNzIjoiWWFyZHN0aWNrIFNvZnR3YXJlIiwic3ViIjoiQnJhaWQgSldUIn0.5KNCov_EW1cycT4Ay0oSvk4Z4PHFedd3bWOyqkHHTBQ',

View File

@ -5,20 +5,11 @@ var app = require('./config/app');
let schema = {
message_type: Joi.string().valid(app.messageTypes).insensitive().required(),
current_index: Joi.number().integer(),
total_questions: Joi.number().integer(),
total_questions_answered: Joi.number().integer(),
time_elapsed: Joi.number(),
time_left: Joi.any(),
status: Joi.string(),
channel: Joi.string(),
channel_type: Joi.string(),
client_type: Joi.string(),
user_id: Joi.number().integer(),
user_exam_id: Joi.number().integer(),
user_name: Joi.string(),
exam_title: Joi.string(),
message: Joi.string(),
message: Joi.alternatives().try(Joi.string(), Joi.object()),
};
module.exports = {