0

I have a logs that are displaying to client live using socket.io now there is requirement where user can record logs according to their requirement in particular,so i want user to have ability to get logs using socket.io and log into file so it should start recording when user click on record and stop recording and save when user click on stop.How can we append data to file that is being listen on socket.io ?

main.html

<div class="col-md-9" style="height: 600px; width: 1000px; overflow: scroll">
  <ul>
    <li ng-repeat="message in event track by $index">{{message}}</li>
  </ul>
</div>

<button type="button" class="btn btn-success" ng-click="recordLogs()"><a href="" id="a">record</a></button>
<button type="button" class="btn btn-success" ng-click="stopLogs()">stop</button>

ctrl.js

$scope.event = [];
socket.on('ditConsumer', function(data) {
    $scope.event.push(data);
});

Here once user click on recordLogs() i want to create a file and start logging messages that are coming after invoking recordLogs()to a file.

$scope.recordLogs = function() {
  //create a file and start logging from this point to a file
}

server.js

io.sockets.on('connection',function(){
   // Producer.startProducer();
    ditconsumer.start(function(value){
        io.emit('ditConsumer',value)
    });
});
hussain
  • 6,587
  • 18
  • 79
  • 152
  • Are you trying to record to a local file from JS? That isn't really possible across all browsers from what I've seen http://stackoverflow.com/questions/13405129/javascript-create-and-save-file You could generate a file and send it to server that just sends it back for download purposes but in terms of appending to a file I think your only option really is to use local storage or session storage depending on the needs. – shaunhusain Jul 19 '16 at 18:09
  • 1
    You asked this same question yesterday. Nothing has changed in browser security since then to allow you to write directly to local file – charlietfl Jul 19 '16 at 18:09
  • Can you show your server side websocket handlers? – Seth Jul 19 '16 at 18:10
  • I know asked this question yesterday but tags are different today i am trying to see if we can do something with socket.io. – hussain Jul 19 '16 at 18:11
  • @Seth added server side – hussain Jul 19 '16 at 18:13
  • Oh.. you want this locally :/ I skimmed over it and missed that part. As others pointed out it's very possible. – Seth Jul 19 '16 at 18:15
  • dont know how it is duplicate , i am not asking to access local fileSystem this is completely different scenario to save file once i have data using socket.io – hussain Jul 19 '16 at 18:16
  • 1
    What you can do is have that function emit back to your channel telling it to start writing everything to a tmp file on your server. Then the user can then download the file from your server to their computer when they're ready. when they choose to download the log, you stop writing to that file and delete it. – Seth Jul 19 '16 at 18:17
  • If you just want to facilitate the ability for a user to gain the logs for their websocket connection, then I advise you specify that in your question and vote to reopen. I'll also vote to reopen if you do this. – Seth Jul 19 '16 at 18:18
  • And read [ask]. You started this all out with pretty much the same as the other question and were not very specific about process flow you had in mind that differed this time – charlietfl Jul 19 '16 at 18:20
  • Agreed. There was not a very clear distinction between the proposed duplicate and this. Reword, vote to reopen, and you just might get your answer @hussain! – Seth Jul 19 '16 at 18:23
  • Reworded the question but i am not authorize to vote to re-open a question i think you need 250 rep. – hussain Jul 19 '16 at 18:33
  • @hussain you already know you need to write this at server. Question is still pretty vague and Seth explained basically what you would want to do....did you even try it? You should really be more specific about where you have problems based on what you have already learned. *" is it possible"* is not a proper question – charlietfl Jul 19 '16 at 19:18

0 Answers0