main: monitor session changes and update clients that are using the same session file
This commit is contained in:
parent
433aefccb6
commit
b84d6777ab
3 changed files with 61 additions and 3 deletions
|
|
@ -3,7 +3,11 @@ var vm = require('vm'),
|
|||
fs = require('fs'),
|
||||
settings = require('./settings'),
|
||||
osc = require('./osc'),
|
||||
ipc = require('./server').ipc
|
||||
ipc = require('./server').ipc,
|
||||
chokidar = require('chokidar')
|
||||
|
||||
var openedSessions = {},
|
||||
lastSavingClient
|
||||
|
||||
module.exports = {
|
||||
|
||||
|
|
@ -69,13 +73,65 @@ module.exports = {
|
|||
if (!session) error= 'No session object returned'
|
||||
|
||||
if (!error) {
|
||||
if (data.path) this.sessionAddToHistory(data.path)
|
||||
|
||||
ipc.send('sessionOpen',JSON.stringify(session),clientId)
|
||||
|
||||
|
||||
for (var i in openedSessions) {
|
||||
if (openedSessions[i].indexOf(clientId) != -1) {
|
||||
openedSessions[i].splice(openedSessions[i].indexOf(clientId), 1)
|
||||
}
|
||||
}
|
||||
|
||||
if (data.path) {
|
||||
|
||||
this.sessionAddToHistory(data.path)
|
||||
|
||||
fs.lstat(data.path, (err, stats)=>{
|
||||
|
||||
if (err || !stats.isFile()) return
|
||||
|
||||
|
||||
if (!openedSessions[data.path]) {
|
||||
|
||||
openedSessions[data.path] = []
|
||||
|
||||
var watchFile = ()=>{
|
||||
var watcher = chokidar.watch(data.path)
|
||||
watcher.on('change',()=>{
|
||||
for (var k in openedSessions[data.path]) {
|
||||
if (openedSessions[data.path][k] != lastSavingClient) {
|
||||
module.exports.sessionOpen({path:data.path}, openedSessions[data.path][k])
|
||||
}
|
||||
}
|
||||
watcher.close()
|
||||
watchFile()
|
||||
})
|
||||
}
|
||||
watchFile()
|
||||
|
||||
|
||||
}
|
||||
|
||||
openedSessions[data.path].push(clientId)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
ipc.send('error',{title:'Error: invalid session file',text:'<p>'+error+'</p>'})
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
savingSession: function(data, clientId) {
|
||||
|
||||
lastSavingClient = clientId
|
||||
|
||||
},
|
||||
|
||||
sendOsc: function(data) {
|
||||
|
||||
if (data.syncOnly) return
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@
|
|||
"socket.io": "1.7.2",
|
||||
"socketio-wildcard": "0.3.0",
|
||||
"express": "4.14.0",
|
||||
"jquery-slim": "3.0.0"
|
||||
"jquery-slim": "3.0.0",
|
||||
"chokidar": "1.6.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "electron ."
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ module.exports = {
|
|||
down.attr('href', window.URL.createObjectURL(blob))
|
||||
var event = new MouseEvent("click")
|
||||
down[0].dispatchEvent(event)
|
||||
ipc.send('savingSession')
|
||||
},
|
||||
|
||||
editorEnable: function(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue