io.on('connection', function (socket) {
console.log('socket connection');
+ /**
+ * SocketEvent.FS_IMAGE_LIST_FROM = 'ws/fs/image/list/from'
+ */
socket.on(SocketEvent.FS_IMAGE_LIST_FROM, function (data) {
var msgData, fileList, targetDirectory;
socket.emit(SocketEvent.FS_IMAGE_LIST_TO, msgData);
});
+ /**
+ * SocketEvent.FS_IMAGE_ADD_FROM = 'ws/fs/image/add/from'
+ */
socket.on(SocketEvent.FS_IMAGE_ADD_FROM, function (data) {
Mic.create(data, io);
io.sockets.emit(SocketEvent.MIC_AVAILABLE_TO, Mic.isAvailable());
});
+ /**
+ * SocketEvent.FS_IMAGE_ADD_KILL = 'ws/fs/image/add/kill'
+ */
socket.on(SocketEvent.FS_IMAGE_ADD_KILL, function () {
Mic.kill();
io.sockets.emit(SocketEvent.MIC_AVAILABLE_TO, Mic.isAvailable());
});
- socket.on(SocketEvent.FS_IMAGE_DOWNLOAD_FROM, function (data) {
- console.log(data);
- // TODO: Implement or Remove
- });
-
+ /**
+ * SocketEvent.MIC_AVAILABLE_FROM = 'ws/mic/available/from'
+ */
socket.on(SocketEvent.MIC_AVAILABLE_FROM, function () {
console.log('mic available: ' + Mic.isAvailable());
io.sockets.emit(SocketEvent.MIC_AVAILABLE_TO, Mic.isAvailable());
});
+ /**
+ * SocketEvent.APP_CONFIG_FROM = 'ws/app/config/from'
+ */
+ socket.on(SocketEvent.APP_CONFIG_FROM, function () {
+ socket.emit(SocketEvent.APP_CONFIG_TO, Config);
+ });
+
socket.on('disconnect', function () {
console.log('socket disconnect');
+ // TODO
});
socket.on('message', function (msg) {
console.log('socket message');
+ // TODO
});
});
"PORT" : 8081
},
"TIC_CORE": {
- "PORT" : 8082
+ "PORT" : 8082,
+ "KS_OUT_DIR" : "/tmp/tic/ks/"
+ },
+ "MIC" : {
+ "OUT_DIR" : "/tmp/tic/images/"
}
}
\ No newline at end of file
) {
'use strict';
- var socket;
-
function init() {
console.log("main: init")
- /* client */
- socket = io.connect();
- }
-
- $(document).ready(function () {
- init();
-
- Image.initSocket(socket);
- Image.updateList(); // Image - the list of images
-
Util.showLoadingDialog(true);
Settings.updatePackage()
Util.showLoadingDialog(false);
Util.showAlertDialog('Failed to load package list.<br>Please check the tic-core.');
});
+ }
+
+ $(document).ready(function () {
+ init();
});
});
) {
'use strict';
+ var AppConfig = null;
+
// connected socket object
var client;
// template for the URL
var URL_EXPORTS = '<%= url %>/exports';
- // the path for ks
- var PATH_TIC_KS = '/tmp/tic/ks/';
-
- // the path for images
- var PATH_TIC_IMAGES = '/tmp/tic/images/';
-
// template
var IMAGE_LOG = '<p><%= log %></p>';
var IMAGE_ITEM = '<li class="list-group-item image-item">' +
'<a class="image-list-btndownload" href="<%= hrefPath %>" date-name="<%= fileName %>" download="download">Download</a>' +
'</li>';
- function initSocket(socket) {
+ function _initSocket(socket) {
client = socket;
client.emit('ws/mic/available/from');
-
client.on('ws/mic/available/to', function (data) {
$('#tic-image-create').prop('disabled', !data);
});
function updateList() {
var msgData = {
- path: PATH_TIC_IMAGES
+ path: AppConfig.MIC.OUT_DIR
};
client.emit('ws/fs/image/list/from', msgData);
}
}
$('#tic-image-create').prop('disabled', count === 0);
+ client.emit('ws/mic/available/from');
}
function confirmCreateImage() {
*/
var msgData = {
pathKsFile: pathKsFile,
- pathOutput: PATH_TIC_IMAGES
+ pathOutput: AppConfig.MIC.OUT_DIR
};
client.emit('ws/fs/image/add/from', msgData);
}
name: 'default'
},
packages: _.map(checkedPackagesList, 'name'),
- output: PATH_TIC_KS
+ output: AppConfig.TIC_CORE.KS_OUT_DIR
};
return Util.POST(getExportsUrl(), msgData)
.then(function (result) {
console.log('image: init');
_initWidgets();
+ _initSocket(Util.getWebSocket());
+
+ Util.getAppConfig()
+ .then(function (data) {
+ AppConfig = data;
+ updateList();
+ });
}
init();
return {
/**
- * Initialize listener of socket
- * @method initSocket
- */
- initSocket: initSocket,
- /**
* Update summary in image page
* @method updateSummary
*/
) {
'use strict';
+ var socket = null;
+
function setAnimateScroll() {
$('a.tic-page-scroll').bind('click', function(event) {
var body = $('html, body');
})
}
+ function getAppConfig() {
+ return new Promise(function (resolve, reject) {
+ socket.emit('ws/app/config/from');
+ socket.on('ws/app/config/to', function (data) {
+ resolve(data);
+ });
+ })
+ }
+
+ function getWebSocket() {
+ return socket;
+ }
+
+ function _init() {
+ socket = io.connect();
+ }
+
+ _init();
+
return {
/**
* Set smooth scrolling, one page websites
* @param {object} data - A plain object or string that is sent to the server with the request.
* @return {Promise}
*/
- POST: POST
+ POST: POST,
+
+ /**
+ * Get WebSocket client
+ * @method getWebSocket
+ * @return {object} socket
+ */
+ getWebSocket: getWebSocket,
+
+ /**
+ * Load app configuration from config.json of root
+ * @method getAppConfig
+ * @return {Promise}
+ */
+ getAppConfig: getAppConfig,
}
});
Mic.create = function (paramObj, io) {
console.log('MIC Create');
- var micCommand = 'sudo mic cr loop ' + paramObj.pathKsFile + util.format(' -A %s', 'x86_64') + util.format(' -o %s', paramObj.pathOutput);
+ var micCommand = 'sudo mic cr auto ' + paramObj.pathKsFile + util.format(' -A %s', 'x86_64') + util.format(' -o %s', paramObj.pathOutput);
function sendMsg(path, msg) {
io.sockets.emit(path, msg);
var SocketEvent = {};
+SocketEvent.APP_CONFIG_TO = 'ws/app/config/to';
+SocketEvent.APP_CONFIG_FROM = 'ws/app/config/from';
+
SocketEvent.MIC_AVAILABLE_TO = 'ws/mic/available/to';
SocketEvent.MIC_AVAILABLE_FROM = 'ws/mic/available/from';
SocketEvent.FS_IMAGE_LIST_TO = 'ws/fs/image/list/to';
SocketEvent.FS_IMAGE_LIST_FROM = 'ws/fs/image/list/from';
-SocketEvent.FS_IMAGE_DOWNLOAD_FROM = 'ws/fs/image/download/from';
SocketEvent.FS_IMAGE_ADD_TO = 'ws/fs/image/add/to';
SocketEvent.FS_IMAGE_ADD_FROM = 'ws/fs/image/add/from';