How to write error message object of videoJS on server

8.9k views Asked by At

I am using videojs for my video play. I want to log error message on the server. In browser console i am able to get the message , but i am not getting the error object which i can send to the server . Need assistance . test code will be highly helpful .

 player=videojs("myvideo", { "controls": true,  "techOrder": ["html5", "flash"]}, function(){
    console.log("here");


    var err =this.on('error', function(e){
    console.log("Error n caught" +this.error());
    console.log(this.error());  // Is not printing anything



});

});
3

There are 3 answers

0
Pratik Jaiswal On BEST ANSWER

I found the answer :

   this.player().on('error', function(e) {
      console.log(e);
       e.stopImmediatePropagation();
        var error = this.player().error();
        console.log('error!', error.code, error.type , error.message);
});         
0
jlmcdonald On

I think the problem lies in the anonymous function within your error handler, that would have no ability to access the value of 'this.' See if binding 'this' works:

var err =this.on('error', function(e){
  console.log("Error n caught" +this.error());
  console.log(this.error());  // Is not printing anything
}.bind(this));
0
user3072843 On

No, in order to send anything to the server the server needs to have an interface for that.

What does your server side look like?

In my logging function I am using jquery on the client side to post log and error messages to the server:

$.post( your_url_to_the_server, { entry: your_log_error_data }, function(data){ /* do something after the message was sent */}); 

On the server side you could use PHP for instance, that can be reached under the given URL (see "your_url_to_the_server" in the client code example):

if (isset($_POST['entry'])) {
 write_log($_POST['entry']);
}

//
function write_log($message) {
 $logfile= "my-log-file.log";
  // Append to the log file
  if($fd = @fopen($logfile, "a")) {
    $result = fputs($fd, $message);
    fclose($fd);

    if($result > 0)
      return true;  
    else
      return 'Unable to write to '.$logfile.'!';
  }
  else {
    return 'Unable to open log '.$logfile.'!';
  }
}