Pratik Jaiswal
Pratik Jaiswal

Reputation: 390

How to write error message object of videoJS on server

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



});

});

Upvotes: 0

Views: 9127

Answers (3)

user3072843
user3072843

Reputation: 298

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.'!';
  }
}

Upvotes: 1

Pratik Jaiswal
Pratik Jaiswal

Reputation: 390

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);
});         

Upvotes: 12

jlmcdonald
jlmcdonald

Reputation: 13667

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));

Upvotes: 0

Related Questions