Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffb7f30133 | ||
|
|
8ee3386470 | ||
|
|
0d92343d55 | ||
|
|
efb7970ecb | ||
|
|
7e8a27e140 | ||
|
|
6ad97ac5c2 |
@@ -1,14 +0,0 @@
|
|||||||
.DS_Store
|
|
||||||
.git
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
scripts
|
|
||||||
pids
|
|
||||||
*.pid
|
|
||||||
*.seed
|
|
||||||
lib-cov
|
|
||||||
coverage
|
|
||||||
.grunt
|
|
||||||
.lock-wscript
|
|
||||||
build/Release
|
|
||||||
node_modules
|
|
||||||
19
Dockerfile
19
Dockerfile
@@ -1,19 +0,0 @@
|
|||||||
FROM spacedeck/docker-baseimage:latest
|
|
||||||
ENV NODE_ENV production
|
|
||||||
|
|
||||||
RUN mkdir -p /usr/src/app
|
|
||||||
WORKDIR /usr/src/app
|
|
||||||
|
|
||||||
COPY package.json /usr/src/app/
|
|
||||||
RUN npm install
|
|
||||||
RUN npm install gulp-rev-replace gulp-clean gulp-fingerprint gulp-rev gulp-rev-all gulp-rev-replace
|
|
||||||
RUN npm install -g --save-dev gulp
|
|
||||||
|
|
||||||
COPY . /usr/src/app
|
|
||||||
RUN gulp styles
|
|
||||||
RUN npm cache clean
|
|
||||||
|
|
||||||
CMD [ "npm", "start" ]
|
|
||||||
|
|
||||||
EXPOSE 9666
|
|
||||||
|
|
||||||
@@ -12,9 +12,10 @@ var uglify = require('gulp-uglify');
|
|||||||
var fingerprint = require('gulp-fingerprint');
|
var fingerprint = require('gulp-fingerprint');
|
||||||
var rev = require('gulp-rev');
|
var rev = require('gulp-rev');
|
||||||
|
|
||||||
var revAll = require('gulp-rev-all');
|
var RevAll = require('gulp-rev-all');
|
||||||
|
|
||||||
gulp.task('rev', () => {
|
gulp.task('rev', () => {
|
||||||
|
var revAll = new RevAll();
|
||||||
return gulp.src(['public/**'])
|
return gulp.src(['public/**'])
|
||||||
.pipe(gulp.dest('build/assets'))
|
.pipe(gulp.dest('build/assets'))
|
||||||
.pipe(revAll.revision())
|
.pipe(revAll.revision())
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -23,10 +23,10 @@ We appreciate filed issues, pull requests and general discussion.
|
|||||||
|
|
||||||
Spacedeck uses the following major building blocks:
|
Spacedeck uses the following major building blocks:
|
||||||
|
|
||||||
- Vue.js (Frontend)
|
|
||||||
- Node.js 7.x (Backend / API)
|
- Node.js 7.x (Backend / API)
|
||||||
- MongoDB 3.x (Datastore)
|
- MongoDB 3.x (Datastore)
|
||||||
- Redis 3.x (Datastore for realtime channels)
|
- Redis 3.x (Datastore for realtime channels)
|
||||||
|
- Vue.js (Frontend)
|
||||||
|
|
||||||
It also has some binary dependencies for media conversion and PDF export:
|
It also has some binary dependencies for media conversion and PDF export:
|
||||||
|
|
||||||
@@ -50,14 +50,8 @@ see: config/config.json
|
|||||||
|
|
||||||
export NODE_ENV=development
|
export NODE_ENV=development
|
||||||
npm start
|
npm start
|
||||||
open http://localhost:9666
|
|
||||||
|
|
||||||
# experimental docker(compose) support
|
open http://localhost:9000
|
||||||
|
|
||||||
We have a docker base image at https://github.com/spacedeck/docker-baseimage that includes all required binaries. Based on this image we can use Docker-Compose to bootstrap a Spacedeck including data storages.
|
|
||||||
|
|
||||||
docker-compose build
|
|
||||||
docker-compose run -e ENV=development -p 9666:9666 -e NODE_ENV=development spacedeck-open
|
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
|
|||||||
16
app.js
16
app.js
@@ -15,13 +15,16 @@ const favicon = require('serve-favicon');
|
|||||||
const logger = require('morgan');
|
const logger = require('morgan');
|
||||||
const cookieParser = require('cookie-parser');
|
const cookieParser = require('cookie-parser');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
|
|
||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
|
|
||||||
const swig = require('swig');
|
const swig = require('swig');
|
||||||
const i18n = require('i18n-2');
|
const i18n = require('i18n-2');
|
||||||
const helmet = require('helmet');
|
const helmet = require('helmet');
|
||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const app = express();
|
const app = express();
|
||||||
|
const serveStatic = require('serve-static');
|
||||||
|
|
||||||
const isProduction = app.get('env') === 'production';
|
const isProduction = app.get('env') === 'production';
|
||||||
|
|
||||||
@@ -47,7 +50,7 @@ swig.setFilter('cdn', function(input, idx) {
|
|||||||
app.engine('html', swig.renderFile);
|
app.engine('html', swig.renderFile);
|
||||||
app.set('view engine', 'html');
|
app.set('view engine', 'html');
|
||||||
|
|
||||||
if (isProduction) {
|
if (app.get('env') != 'development') {
|
||||||
app.set('views', path.join(__dirname, 'build', 'views'));
|
app.set('views', path.join(__dirname, 'build', 'views'));
|
||||||
app.use(favicon(path.join(__dirname, 'build', 'assets', 'images', 'favicon.png')));
|
app.use(favicon(path.join(__dirname, 'build', 'assets', 'images', 'favicon.png')));
|
||||||
app.use(express.static(path.join(__dirname, 'build', 'assets')));
|
app.use(express.static(path.join(__dirname, 'build', 'assets')));
|
||||||
@@ -67,7 +70,6 @@ app.use(bodyParser.urlencoded({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use(helmet.noCache())
|
|
||||||
app.use(helmet.frameguard())
|
app.use(helmet.frameguard())
|
||||||
app.use(helmet.xssFilter())
|
app.use(helmet.xssFilter())
|
||||||
app.use(helmet.hsts({
|
app.use(helmet.hsts({
|
||||||
@@ -109,6 +111,12 @@ app.use('/api/teams', require('./routes/api/teams'));
|
|||||||
app.use('/api/webgrabber', require('./routes/api/webgrabber'));
|
app.use('/api/webgrabber', require('./routes/api/webgrabber'));
|
||||||
app.use('/', require('./routes/root'));
|
app.use('/', require('./routes/root'));
|
||||||
|
|
||||||
|
if (config.get('storage_local_path')) {
|
||||||
|
app.use('/storage', serveStatic(config.get('storage_local_path')+"/"+config.get('storage_bucket'), {
|
||||||
|
maxAge: 24*3600
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
app.use(require('./middlewares/404'));
|
app.use(require('./middlewares/404'));
|
||||||
if (app.get('env') == 'development') {
|
if (app.get('env') == 'development') {
|
||||||
@@ -121,11 +129,11 @@ if (app.get('env') == 'development') {
|
|||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|
||||||
// CONNECT TO DATABASE
|
// CONNECT TO DATABASE
|
||||||
const mongoHost = process.env.MONGO_PORT_27017_TCP_ADDR || 'db';
|
const mongoHost = process.env.MONGO_PORT_27017_TCP_ADDR || 'localhost';
|
||||||
mongoose.connect('mongodb://' + mongoHost + '/spacedeck');
|
mongoose.connect('mongodb://' + mongoHost + '/spacedeck');
|
||||||
|
|
||||||
// START WEBSERVER
|
// START WEBSERVER
|
||||||
const port = 9666;
|
const port = 9000;
|
||||||
|
|
||||||
const server = http.Server(app).listen(port, () => {
|
const server = http.Server(app).listen(port, () => {
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"endpoint": "http://localhost:9666",
|
"endpoint": "http://localhost:9000",
|
||||||
"storage_bucket": "sdeck-development",
|
"storage_region": "eu-central-1",
|
||||||
"storage_cdn": "http://localhost:9123/sdeck-development",
|
"storage_bucket": "my_spacedeck_bucket",
|
||||||
"storage_endpoint": "http://storage:9000",
|
"storage_cdn": "/storage",
|
||||||
|
"storage_local_path": "./storage",
|
||||||
"google_access" : "",
|
"google_access" : "",
|
||||||
"google_secret" : "",
|
"google_secret" : "",
|
||||||
"admin_pass": "very_secret_admin_password",
|
"admin_pass": "very_secret_admin_password",
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
version: '2'
|
|
||||||
services:
|
|
||||||
sync:
|
|
||||||
image: redis
|
|
||||||
storage:
|
|
||||||
image: minio/minio
|
|
||||||
environment:
|
|
||||||
- MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
|
|
||||||
- MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|
|
||||||
ports:
|
|
||||||
- 9123:9000
|
|
||||||
command: server /export
|
|
||||||
db:
|
|
||||||
image: mongo
|
|
||||||
spacedeck-open:
|
|
||||||
environment:
|
|
||||||
- env=development
|
|
||||||
- MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
|
|
||||||
- MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|
|
||||||
build: .
|
|
||||||
volumes:
|
|
||||||
# - ./:/usr/src/app
|
|
||||||
- /usr/src/app/node_modules
|
|
||||||
command: npm start
|
|
||||||
ports:
|
|
||||||
- 9666:9666
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
- sync
|
|
||||||
- storage
|
|
||||||
links:
|
|
||||||
- storage
|
|
||||||
- db
|
|
||||||
- sync
|
|
||||||
@@ -7,6 +7,7 @@ const fs = require('fs');
|
|||||||
const Models = require('../models/schema');
|
const Models = require('../models/schema');
|
||||||
const uploader = require('../helpers/uploader');
|
const uploader = require('../helpers/uploader');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const os = require('os');
|
||||||
|
|
||||||
const fileExtensionMap = {
|
const fileExtensionMap = {
|
||||||
".amr" : "audio/AMR",
|
".amr" : "audio/AMR",
|
||||||
@@ -245,13 +246,12 @@ function resizeAndUpload(a, size, max, fileName, localFilePath, callback) {
|
|||||||
if (max>320 || size.width > max || size.height > max) {
|
if (max>320 || size.width > max || size.height > max) {
|
||||||
var resizedFileName = max + "_"+fileName;
|
var resizedFileName = max + "_"+fileName;
|
||||||
var s3Key = "s"+ a.space_id.toString() + "/a" + a._id.toString() + "/" + resizedFileName;
|
var s3Key = "s"+ a.space_id.toString() + "/a" + a._id.toString() + "/" + resizedFileName;
|
||||||
var localResizedFilePath = "/tmp/"+resizedFileName;
|
var localResizedFilePath = os.tmpdir()+"/"+resizedFileName;
|
||||||
gm(localFilePath).resize(max, max).autoOrient().write(localResizedFilePath, function (err) {
|
gm(localFilePath).resize(max, max).autoOrient().write(localResizedFilePath, function (err) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
uploader.uploadFile(s3Key, "image/jpeg", localResizedFilePath, function(err, url) {
|
uploader.uploadFile(s3Key, "image/jpeg", localResizedFilePath, function(err, url) {
|
||||||
if (err) callback(err);
|
if (err) callback(err);
|
||||||
else{
|
else{
|
||||||
console.log(localResizedFilePath);
|
|
||||||
fs.unlink(localResizedFilePath, function (err) {
|
fs.unlink(localResizedFilePath, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
@@ -32,9 +32,6 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
phantom.create({ path: require('phantomjs-prebuilt').path }, function (err, browser) {
|
phantom.create({ path: require('phantomjs-prebuilt').path }, function (err, browser) {
|
||||||
if(err){
|
|
||||||
console.log(err);
|
|
||||||
}else{
|
|
||||||
return browser.createPage(function (err, page) {
|
return browser.createPage(function (err, page) {
|
||||||
console.log("page created, opening ",space_url);
|
console.log("page created, opening ",space_url);
|
||||||
|
|
||||||
@@ -60,8 +57,6 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
onExit: on_exit
|
onExit: on_exit
|
||||||
});
|
});
|
||||||
|
|||||||
111
helpers/redis.js
111
helpers/redis.js
@@ -1,14 +1,104 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const RedisConnection = require('ioredis');
|
// this is a mock version of the Redis API,
|
||||||
const websockets = require('./websockets');
|
// emulating Redis if it is not available locally
|
||||||
|
var notRedis = {
|
||||||
|
state: {},
|
||||||
|
topics: {},
|
||||||
|
|
||||||
|
publish: function(topic, msg, cb) {
|
||||||
|
if (!this.topics[topic]) {
|
||||||
|
this.topics[topic] = {
|
||||||
|
subscribers: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var t=this.topics[topic];
|
||||||
|
for (var i=0; i<t.subscribers.length; i++) {
|
||||||
|
var s=t.subscribers[i];
|
||||||
|
if (s.handler) {
|
||||||
|
s.handler(topic, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cb) cb(null);
|
||||||
|
},
|
||||||
|
|
||||||
|
subscribe: function(topics, cb) {
|
||||||
|
var handle = {
|
||||||
|
handler: null,
|
||||||
|
on: function(evt, cb) {
|
||||||
|
if (evt == "message") {
|
||||||
|
this.handler = cb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i=0; i<topics.length; i++) {
|
||||||
|
var topic = topics[i];
|
||||||
|
if (!this.topics[topic]) {
|
||||||
|
this.topics[topic] = {
|
||||||
|
subscribers: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var t=this.topics[topic];
|
||||||
|
t.subscribers.push(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
cb(null, topics.length);
|
||||||
|
return handle;
|
||||||
|
},
|
||||||
|
|
||||||
|
get: function(key, cb) {
|
||||||
|
cb(null, this.state[key]);
|
||||||
|
return this.state[key];
|
||||||
|
},
|
||||||
|
|
||||||
|
set: function(key, val, cb) {
|
||||||
|
this.state[key] = val;
|
||||||
|
cb();
|
||||||
|
},
|
||||||
|
|
||||||
|
del: function(key, cb) {
|
||||||
|
delete this.state[key];
|
||||||
|
cb(null);
|
||||||
|
},
|
||||||
|
|
||||||
|
sadd: function(key, skey, cb) {
|
||||||
|
if (!this.state[key]) this.state[key] = {};
|
||||||
|
this.state[key][skey] = true;
|
||||||
|
cb(null);
|
||||||
|
},
|
||||||
|
|
||||||
|
srem: function(key, skey, cb) {
|
||||||
|
if (this.state[key]) {
|
||||||
|
delete this.state[key][skey];
|
||||||
|
}
|
||||||
|
cb(null);
|
||||||
|
},
|
||||||
|
|
||||||
|
smembers: function(key, cb) {
|
||||||
|
cb(null, Object.keys(this.state[key]));
|
||||||
|
},
|
||||||
|
|
||||||
|
incr: function(key, cb) {
|
||||||
|
if (!this.state[key]) this.state[key] = 0;
|
||||||
|
this.state[key]++;
|
||||||
|
cb(null, this.state[key]);
|
||||||
|
},
|
||||||
|
|
||||||
|
expire: function() {
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
connectRedis(){
|
connectRedis: function() {
|
||||||
const redisHost = process.env.REDIS_PORT_6379_TCP_ADDR || 'sync';
|
this.connection = notRedis;
|
||||||
this.connection = new RedisConnection(6379, redisHost);
|
|
||||||
},
|
},
|
||||||
sendMessage(action, model, attributes, channelId) {
|
getConnection: function() {
|
||||||
|
this.connectRedis();
|
||||||
|
return this.connection;
|
||||||
|
},
|
||||||
|
sendMessage: function(action, model, attributes, channelId) {
|
||||||
const data = JSON.stringify({
|
const data = JSON.stringify({
|
||||||
channel_id: channelId,
|
channel_id: channelId,
|
||||||
action: action,
|
action: action,
|
||||||
@@ -17,12 +107,12 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
this.connection.publish('updates', data);
|
this.connection.publish('updates', data);
|
||||||
},
|
},
|
||||||
logIp(ip, cb) {
|
logIp: function(ip, cb) {
|
||||||
this.connection.incr("ip_"+ ip, (err, socketCounter) => {
|
this.connection.incr("ip_"+ ip, (err, socketCounter) => {
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
rateLimit(namespace, ip, cb) {
|
rateLimit: function(namespace, ip, cb) {
|
||||||
const key = "limit_"+ namespace + "_"+ ip;
|
const key = "limit_"+ namespace + "_"+ ip;
|
||||||
const redis = this.connection;
|
const redis = this.connection;
|
||||||
|
|
||||||
@@ -47,7 +137,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
isOnlineInSpace(user, space, cb) {
|
isOnlineInSpace: function(user, space, cb) {
|
||||||
this.connection.smembers("space_" + space._id.toString(), function(err, list) {
|
this.connection.smembers("space_" + space._id.toString(), function(err, list) {
|
||||||
if (err) cb(err);
|
if (err) cb(err);
|
||||||
else {
|
else {
|
||||||
@@ -59,3 +149,6 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return module.exports;
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,22 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var AWS = require('aws-sdk');
|
|
||||||
AWS.config.region = 'eu-central-1';
|
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var config = require('config');
|
var config = require('config');
|
||||||
|
|
||||||
var cdn = config.get("storage_cdn");
|
// use AWS S3 or local folder depending on config
|
||||||
var storage_endpoint = config.get("storage_endpoint");
|
if (config.get("storage_local_path")) {
|
||||||
|
var AWS = require('mock-aws-s3');
|
||||||
const bucketName = "sdeck-fresh-development";
|
AWS.config.basePath = config.get("storage_local_path");
|
||||||
const ep = new AWS.Endpoint(storage_endpoint);
|
} else {
|
||||||
|
var AWS = require('aws-sdk');
|
||||||
AWS.config.update(new AWS.Config({
|
AWS.config.region = config.get("storage_region");
|
||||||
accessKeyId: process.env.MINIO_ACCESS_KEY,
|
}
|
||||||
secretAccessKey: process.env.MINIO_SECRET_KEY,
|
|
||||||
region: 'us-east-1',
|
|
||||||
s3ForcePathStyle: true,
|
|
||||||
signatureVersion: 'v4'
|
|
||||||
}));
|
|
||||||
|
|
||||||
const s3 = new AWS.S3({
|
|
||||||
endpoint: ep
|
|
||||||
});
|
|
||||||
|
|
||||||
s3.createBucket({
|
|
||||||
Bucket: config.get("storage_bucket"),
|
|
||||||
ACL: "public-read",
|
|
||||||
GrantRead: "*"
|
|
||||||
}, (err,res) => {
|
|
||||||
console.log("createBucket",err,res);
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
removeFile: (path, callback) => {
|
removeFile: (path, callback) => {
|
||||||
|
const s3 = new AWS.S3({
|
||||||
|
region: config.get("storage_region")
|
||||||
|
});
|
||||||
const bucket = config.get("storage_bucket");
|
const bucket = config.get("storage_bucket");
|
||||||
s3.deleteObject({
|
s3.deleteObject({
|
||||||
Bucket: bucket, Key: path
|
Bucket: bucket, Key: path
|
||||||
@@ -51,7 +34,7 @@ module.exports = {
|
|||||||
callback({error:"missing path"}, null);
|
callback({error:"missing path"}, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("[storage] uploading", localFilePath, " to ", fileName);
|
console.log("[s3] uploading", localFilePath, " to ", fileName);
|
||||||
|
|
||||||
const bucket = config.get("storage_bucket");
|
const bucket = config.get("storage_bucket");
|
||||||
const fileStream = fs.createReadStream(localFilePath);
|
const fileStream = fs.createReadStream(localFilePath);
|
||||||
@@ -62,6 +45,10 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
fileStream.on('open', function () {
|
fileStream.on('open', function () {
|
||||||
|
var s3 = new AWS.S3({
|
||||||
|
region: config.get("storage_region")
|
||||||
|
});
|
||||||
|
|
||||||
s3.putObject({
|
s3.putObject({
|
||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
Key: fileName,
|
Key: fileName,
|
||||||
@@ -72,7 +59,7 @@ module.exports = {
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
callback(err);
|
callback(err);
|
||||||
}else {
|
}else {
|
||||||
const url = cdn + "/" + fileName;
|
const url = config.get("storage_cdn") + "/" + fileName;
|
||||||
console.log("[s3]" + localFilePath + " to " + url);
|
console.log("[s3]" + localFilePath + " to " + url);
|
||||||
callback(null, url);
|
callback(null, url);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,17 @@ require('../models/schema');
|
|||||||
|
|
||||||
const WebSocketServer = require('ws').Server;
|
const WebSocketServer = require('ws').Server;
|
||||||
|
|
||||||
const RedisConnection = require('ioredis');
|
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const _ = require("underscore");
|
const _ = require("underscore");
|
||||||
const mongoose = require("mongoose");
|
const mongoose = require("mongoose");
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
var redis = require("./redis.js");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
startWebsockets: function(server) {
|
startWebsockets: function(server) {
|
||||||
this.setupSubscription();
|
this.setupSubscription();
|
||||||
this.state = new RedisConnection(6379, process.env.REDIS_PORT_6379_TCP_ADDR || 'sync');
|
this.state = redis.getConnection();
|
||||||
|
|
||||||
if(!this.current_websockets) {
|
if(!this.current_websockets) {
|
||||||
this.current_websockets = [];
|
this.current_websockets = [];
|
||||||
@@ -117,8 +118,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setupSubscription: function() {
|
setupSubscription: function() {
|
||||||
this.cursorSubscriber = new RedisConnection(6379, process.env.REDIS_PORT_6379_TCP_ADDR || 'sync');
|
this.cursorSubscriber = redis.getConnection().subscribe(['cursors', 'users', 'updates'], function (err, count) {
|
||||||
this.cursorSubscriber.subscribe(['cursors', 'users', 'updates'], function (err, count) {
|
|
||||||
console.log("[redis] websockets to " + count + " topics." );
|
console.log("[redis] websockets to " + count + " topics." );
|
||||||
});
|
});
|
||||||
this.cursorSubscriber.on('message', function (channel, rawMessage) {
|
this.cursorSubscriber.on('message', function (channel, rawMessage) {
|
||||||
@@ -206,7 +206,7 @@ module.exports = {
|
|||||||
console.log("websocket not found to remove");
|
console.log("websocket not found to remove");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state.del(ws.id, function(err, res) {
|
this.state.del(ws.id+"", function(err, res) {
|
||||||
if (err) console.error(err, res);
|
if (err) console.error(err, res);
|
||||||
else {
|
else {
|
||||||
this.removeUserInSpace(ws.space_id, ws, (err) => {
|
this.removeUserInSpace(ws.space_id, ws, (err) => {
|
||||||
@@ -221,7 +221,8 @@ module.exports = {
|
|||||||
|
|
||||||
addUserInSpace: function(username, space, ws, cb) {
|
addUserInSpace: function(username, space, ws, cb) {
|
||||||
console.log("[websockets] user "+username+" in "+space.access_mode +" space " + space._id + " with socket " + ws.id);
|
console.log("[websockets] user "+username+" in "+space.access_mode +" space " + space._id + " with socket " + ws.id);
|
||||||
this.state.set(ws.id, username, function(err, res) {
|
|
||||||
|
this.state.set(ws.id+"", username+"", function(err, res) {
|
||||||
if(err) console.error(err, res);
|
if(err) console.error(err, res);
|
||||||
else {
|
else {
|
||||||
this.state.sadd("space_" + space._id, ws.id, function(err, res) {
|
this.state.sadd("space_" + space._id, ws.id, function(err, res) {
|
||||||
@@ -238,7 +239,7 @@ module.exports = {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
removeUserInSpace: function(spaceId, ws, cb) {
|
removeUserInSpace: function(spaceId, ws, cb) {
|
||||||
this.state.srem("space_" + spaceId, ws.id, function(err, res) {
|
this.state.srem("space_" + spaceId, ws.id+"", function(err, res) {
|
||||||
if (err) cb(err);
|
if (err) cb(err);
|
||||||
else {
|
else {
|
||||||
console.log("[websockets] socket "+ ws.id + " went offline in space " + spaceId);
|
console.log("[websockets] socket "+ ws.id + " went offline in space " + spaceId);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ module.exports.teamSchema.index({
|
|||||||
|
|
||||||
module.exports.teamSchema.statics.getTeamForHost = (host, cb) => {
|
module.exports.teamSchema.statics.getTeamForHost = (host, cb) => {
|
||||||
|
|
||||||
if (host != "127.0.0.1:9666") { //phantomjs check
|
if (host != "127.0.0.1:9000") { //phantomjs check
|
||||||
let subDomainParts = host.split('.');
|
let subDomainParts = host.split('.');
|
||||||
|
|
||||||
if (subDomainParts.length > 2) {
|
if (subDomainParts.length > 2) {
|
||||||
|
|||||||
13
package.json
13
package.json
@@ -28,7 +28,6 @@
|
|||||||
"googleapis": "18.0.0",
|
"googleapis": "18.0.0",
|
||||||
"gulp": "^3.9.1",
|
"gulp": "^3.9.1",
|
||||||
"gulp-concat": "2.6.0",
|
"gulp-concat": "2.6.0",
|
||||||
"gulp-eslint": "*",
|
|
||||||
"gulp-express": "0.3.0",
|
"gulp-express": "0.3.0",
|
||||||
"gulp-nodemon": "*",
|
"gulp-nodemon": "*",
|
||||||
"gulp-sass": "^2.0.3",
|
"gulp-sass": "^2.0.3",
|
||||||
@@ -40,13 +39,13 @@
|
|||||||
"lodash": "^4.3.0",
|
"lodash": "^4.3.0",
|
||||||
"log-timestamp": "latest",
|
"log-timestamp": "latest",
|
||||||
"md5": "2.2.1",
|
"md5": "2.2.1",
|
||||||
|
"mock-aws-s3": "^2.6.0",
|
||||||
"moment": "2.18.1",
|
"moment": "2.18.1",
|
||||||
"mongoose": "4.9.3",
|
"mongoose": "4.9.3",
|
||||||
"morgan": "1.8.1",
|
"morgan": "1.8.1",
|
||||||
|
"node-phantom-simple": "2.2.4",
|
||||||
"node-sass-middleware": "0.11.0",
|
"node-sass-middleware": "0.11.0",
|
||||||
"pdfkit": "0.8.0",
|
"pdfkit": "0.8.0",
|
||||||
"validator": "7.0.0",
|
|
||||||
"node-phantom-simple": "2.2.4",
|
|
||||||
"phantomjs-prebuilt": "2.1.14",
|
"phantomjs-prebuilt": "2.1.14",
|
||||||
"pm2": "latest",
|
"pm2": "latest",
|
||||||
"qr-image": "3.2.0",
|
"qr-image": "3.2.0",
|
||||||
@@ -54,9 +53,11 @@
|
|||||||
"request": "2.81.0",
|
"request": "2.81.0",
|
||||||
"sanitize-html": "^1.11.1",
|
"sanitize-html": "^1.11.1",
|
||||||
"serve-favicon": "~2.4.2",
|
"serve-favicon": "~2.4.2",
|
||||||
"swig": "1.4.2",
|
"serve-static": "^1.13.1",
|
||||||
"slug": "0.9.1",
|
"slug": "0.9.1",
|
||||||
|
"swig": "1.4.2",
|
||||||
"underscore": "1.8.3",
|
"underscore": "1.8.3",
|
||||||
|
"validator": "7.0.0",
|
||||||
"weak": "1.0.1",
|
"weak": "1.0.1",
|
||||||
"ws": "2.2.3"
|
"ws": "2.2.3"
|
||||||
},
|
},
|
||||||
@@ -65,7 +66,6 @@
|
|||||||
"gulp": "^3.9.1",
|
"gulp": "^3.9.1",
|
||||||
"gulp-clean": "^0.3.2",
|
"gulp-clean": "^0.3.2",
|
||||||
"gulp-concat": "^2.6.0",
|
"gulp-concat": "^2.6.0",
|
||||||
"gulp-eslint": "^3.0.1",
|
|
||||||
"gulp-express": "^0.3.0",
|
"gulp-express": "^0.3.0",
|
||||||
"gulp-fingerprint": "^0.3.2",
|
"gulp-fingerprint": "^0.3.2",
|
||||||
"gulp-nodemon": "^2.0.4",
|
"gulp-nodemon": "^2.0.4",
|
||||||
@@ -81,8 +81,7 @@
|
|||||||
},
|
},
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "Gulpfile.js",
|
"main": "Gulpfile.js",
|
||||||
"directories": {
|
"directories": {},
|
||||||
},
|
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/spacedeck/spacedeck-open.git"
|
"url": "https://github.com/spacedeck/spacedeck-open.git"
|
||||||
|
|||||||
@@ -23,10 +23,10 @@
|
|||||||
{% if process.env.NODE_ENV != "production" %}
|
{% if process.env.NODE_ENV != "production" %}
|
||||||
var ENV = {
|
var ENV = {
|
||||||
name: 'development',
|
name: 'development',
|
||||||
webHost: "localhost:9666",
|
webHost: "localhost:9000",
|
||||||
webEndpoint:"http://localhost:9666",
|
webEndpoint:"http://localhost:9000",
|
||||||
apiEndpoint: "http://localhost:9666",
|
apiEndpoint: "http://localhost:9000",
|
||||||
websocketsEndpoint: "ws://localhost:9666"
|
websocketsEndpoint: "ws://localhost:9000"
|
||||||
};
|
};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user