@@ -98,6 +98,10 @@ frappe.Application = Class.extend({ | |||
}); | |||
dialog.get_close_btn().toggle(false); | |||
}); | |||
// listen to build errors | |||
this.setup_build_error_listener(); | |||
if (frappe.sys_defaults.email_user_password){ | |||
var email_list = frappe.sys_defaults.email_user_password.split(','); | |||
for (var u in email_list) { | |||
@@ -519,6 +523,14 @@ frappe.Application = Class.extend({ | |||
}); | |||
} | |||
}, | |||
setup_build_error_listener() { | |||
if (frappe.boot.developer_mode) { | |||
frappe.realtime.on('build_error', (data) => { | |||
console.log(data); | |||
}); | |||
} | |||
} | |||
}); | |||
frappe.get_module = function(m, default_module) { | |||
@@ -0,0 +1,47 @@ | |||
const fs = require('fs'); | |||
const path = require('path'); | |||
const redis = require('redis'); | |||
const bench_path = path.resolve(__dirname, '..', '..'); | |||
function get_conf() { | |||
// defaults | |||
var conf = { | |||
redis_async_broker_port: 12311, | |||
socketio_port: 3000 | |||
}; | |||
var read_config = function (file_path) { | |||
const full_path = path.resolve(bench_path, file_path); | |||
if (fs.existsSync(full_path)) { | |||
var bench_config = JSON.parse(fs.readFileSync(full_path)); | |||
for (var key in bench_config) { | |||
if (bench_config[key]) { | |||
conf[key] = bench_config[key]; | |||
} | |||
} | |||
} | |||
} | |||
// get ports from bench/config.json | |||
read_config('config.json'); | |||
read_config('sites/common_site_config.json'); | |||
// detect current site | |||
if (fs.existsSync('sites/currentsite.txt')) { | |||
conf.default_site = fs.readFileSync('sites/currentsite.txt').toString().trim(); | |||
} | |||
return conf; | |||
} | |||
function get_redis_subscriber() { | |||
const conf = get_conf(); | |||
const host = conf.redis_socketio || conf.redis_async_broker_port; | |||
return redis.createClient(host); | |||
} | |||
module.exports = { | |||
get_conf, | |||
get_redis_subscriber | |||
} |
@@ -10,6 +10,9 @@ const { | |||
get_options_for | |||
} = require('./config'); | |||
const { get_redis_subscriber } = require('../node_utils'); | |||
const subscriber = get_redis_subscriber(); | |||
watch_assets(); | |||
function watch_assets() { | |||
@@ -79,4 +82,17 @@ function log_error(error) { | |||
if (error.frame) { | |||
log(chalk.red(error.frame)); | |||
} | |||
// notify redis which in turns tells socketio to publish this to browser | |||
const payload = { | |||
event: 'build_error', | |||
message: ` | |||
Error in: ${error.id} | |||
${error.toString()} | |||
${error.frame ? error.frame : ''} | |||
` | |||
} | |||
subscriber.publish('events', JSON.stringify(payload)); | |||
} |
@@ -4,8 +4,8 @@ var io = require('socket.io')(server); | |||
var cookie = require('cookie') | |||
var fs = require('fs'); | |||
var path = require('path'); | |||
var redis = require("redis"); | |||
var request = require('superagent'); | |||
var { get_conf, get_redis_subscriber } = require('./node_utils'); | |||
var conf = get_conf(); | |||
var flags = {}; | |||
@@ -19,7 +19,7 @@ var files_struct = { | |||
is_private: 0 | |||
}; | |||
var subscriber = redis.createClient(conf.redis_socketio || conf.redis_async_broker_port); | |||
var subscriber = get_redis_subscriber(); | |||
// serve socketio | |||
server.listen(conf.socketio_port, function () { | |||
@@ -88,7 +88,7 @@ io.on('connection', function (socket) { | |||
socket.join(get_site_room(socket)); | |||
} | |||
}); | |||
socket.on('disconnect', function () { | |||
delete socket.files; | |||
}) | |||
@@ -207,7 +207,12 @@ io.on('connection', function (socket) { | |||
subscriber.on("message", function (channel, message, room) { | |||
message = JSON.parse(message); | |||
io.to(message.room).emit(message.event, message.message); | |||
if (message.room) { | |||
io.to(message.room).emit(message.event, message.message); | |||
} else { | |||
io.emit(message.event, message.message); | |||
} | |||
}); | |||
@@ -345,33 +350,3 @@ function send_viewers(args) { | |||
viewers: viewers | |||
}); | |||
} | |||
function get_conf() { | |||
// defaults | |||
var conf = { | |||
redis_async_broker_port: 12311, | |||
socketio_port: 3000 | |||
}; | |||
var read_config = function (path) { | |||
if (fs.existsSync(path)) { | |||
var bench_config = JSON.parse(fs.readFileSync(path)); | |||
for (var key in bench_config) { | |||
if (bench_config[key]) { | |||
conf[key] = bench_config[key]; | |||
} | |||
} | |||
} | |||
} | |||
// get ports from bench/config.json | |||
read_config('config.json'); | |||
read_config('sites/common_site_config.json'); | |||
// detect current site | |||
if (fs.existsSync('sites/currentsite.txt')) { | |||
conf.default_site = fs.readFileSync('sites/currentsite.txt').toString().trim(); | |||
} | |||
return conf; | |||
} |