Skip to content

Commit

Permalink
create local json to store questionID and responses
Browse files Browse the repository at this point in the history
  • Loading branch information
chensivan committed Dec 8, 2015
1 parent 11e69e9 commit 1811d3c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 10 deletions.
84 changes: 74 additions & 10 deletions lib/voice-assist.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,66 @@
var EventEmitter = require('events').EventEmitter;
var fse = require('fs-extra');
var fsp = require('fs-plus');
var fs = require('fs');
var jsonfile = require('jsonfile');
var util = require('util');
var path = require('path');
var RecordingBarView = require('./RecordingBarView');
var STORAGE_DIRECTORY = __dirname + '/recordings/';
var STORAGE_DIRECTORY = path.join(__dirname,'recordings');

var CompositeDisposable, Notification, Notifications, ref;
ref = require('atom'), Notification = ref.Notification, CompositeDisposable = ref.CompositeDisposable;


// var io = require('socket.io')(3000);
//
// io.sockets.emit('an event sent to all connected clients');
// io.emit('an event sent to all connected clients');
//

var client = require('socket.io-client');
var socket = client.connect('http://localhost:3000');
socket.on('responses', function(msg) {
console.log("client connected"+msg);
atom.notifications.addSuccess("Success: "+msg);
//
//TODO: 2 conditions logic

// if (this is the first time trigger this package)
// 1) check any updated responses
// 2) set socket on addNotification
// else if (this is not the first time trigger this package)
// 1) listen as always


// if (there is a data.json file)
// open file
// load all the question objectsID, and their last response timestamp
// send the object ID and

var file = path.join(STORAGE_DIRECTORY,'data.json');



socket.on('addNotification', function(data) {
console.log("client connected: ");
console.log(data);
//read file and see if the q-id is here

var questionID;
var message;
console.log(" fewafew");
var obj = new Object();
fs.stat(file, function(err, stat){
if (err == null){
obj = JSON.parse(fs.readFileSync(file, 'utf8'));
obj[uid].response = data.msg;
console.log(" hi fewafew");
jsonfile.writeFile(file, obj, function (err) {
console.error(err)
})
atom.notifications.addSuccess("You received one response for this question:\n "+data.id
+"\n the response is: "+data.msg);

}
});



// var question = msg[0];
// var answer = msg[1];

});


Expand Down Expand Up @@ -117,6 +159,28 @@ var cwd;

recorder.on('start', function() {
uid = guid();

var obj = new Object();
fs.stat(file, function(err, stat){
console.log(err);
if (err == null){
obj = JSON.parse(fs.readFileSync(file, 'utf8'));
obj[uid] = true;
jsonfile.writeFile(file, obj, function (err) {
console.error(err)
})
}else if(err.code === 'ENOENT') {
obj[uid] = true;
console.log("ok");
jsonfile.writeFile(file, obj, function (err) {
console.error(err)
})
}else{
console.log(" some thing wrong");
}
})


cwd = workspaceSnapshot.start(uid);
voiceRecorder.start(uid);
editorRecorder.start(uid, cwd);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"fs-extra": "latest",
"fs-plus": "^2.6.0",
"jquery": "latest",
"jsonfile": "^2.2.3",
"marked": "^0.3.5",
"recordrtc": "5.1.0",
"request": "latest",
Expand Down

0 comments on commit 1811d3c

Please sign in to comment.