-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/cm-ide-proxy' into feature/JRD-342-mc-aciona-auth
- Loading branch information
Showing
3 changed files
with
67 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,41 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @todo Get cm from user context | ||
*/ | ||
module.exports = function (app) { | ||
|
||
this.create = function (socket) { | ||
/** | ||
* On connection, register listeners to commands that the client (IDE) may | ||
* emit to the code machine, and re-emits them to the CM connection. | ||
*/ | ||
this.registerCommands = function (socket) { | ||
if (!app.cm) { | ||
console.log('No instance of Code Machine found!'); | ||
return; | ||
} | ||
socket.on('create', function () { | ||
var file = app.cm.create(); | ||
socket.emit('created', file); | ||
}); | ||
}; | ||
|
||
this.list = function (socket) { | ||
if (!app.cm) { | ||
return; | ||
} | ||
socket.on('list', function () { | ||
var list = app.cm.list(); | ||
socket.emit('listed', list); | ||
app.cm.commands.forEach(function (cmd) { | ||
socket.on(cmd, app.cm.emit.bind(app.cm, cmd)); | ||
}); | ||
}; | ||
|
||
this.delete = function (socket) { | ||
/** | ||
* On connection, register listeners to events that the code machine may | ||
* emit, and re-emits them to the socket with client (IDE). | ||
*/ | ||
this.registerEvents = function (socket) { | ||
if (!app.cm) { | ||
console.log('No instance of Code Machine found!'); | ||
return; | ||
} | ||
socket.on('delete', function () { | ||
var res = app.cm.del(); | ||
socket.emit('deleted', res); | ||
}); | ||
}; | ||
|
||
this.apNode = function (socket) { | ||
if (!app.cm) { | ||
return; | ||
} | ||
socket.on('apNode', function () { | ||
var node = app.cm.apNode(); | ||
socket.emit('added', node); | ||
}); | ||
}; | ||
app.cm.events.forEach(function (ev) { | ||
var listener = socket.emit.bind(socket, ev); | ||
|
||
this.rmNode = function (socket) { | ||
if (!app.cm) { | ||
return; | ||
} | ||
socket.on('rmNode', function () { | ||
var res = app.cm.rmNode(); | ||
socket.emit('removed', res); | ||
app.cm.on(ev, listener); | ||
socket.on('disconnect', function () { | ||
app.cm.removeListener(ev, listener); | ||
}); | ||
}); | ||
}; | ||
|
||
this.edNodeAtt = function (socket) { | ||
if (!app.cm) { | ||
return; | ||
} | ||
socket.on('edNodeAtt', function () { | ||
var res = app.cm.edNodeAtt(); | ||
socket.emit('changed', res); | ||
}); | ||
}; | ||
return this; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters