Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vjs.Component.trigger does not pass the event object to the registered listeners #1298

Closed
bceacuna opened this issue Jun 17, 2014 · 4 comments

Comments

@bceacuna
Copy link

I was trying to use the player component as the "event bus/emitter" in my application and pass an event object from Plugin A to Plugin B. So I did the following:

//Plugin A
var myEventObject = {..... };
player.trigger("bccVideoLoaded", myEventObject));


//Plugin B
onVideoLoaded = function (event){
        //event brings the video js reference instead of myEventObject
    };

//set event listener 
  player.on("bccVideoLoaded", onVideoLoaded);

If you look to the videojs source code, it seemed like the event object is dropped when calling vjs.trigger. see snipped below.

vjs.trigger = function(elem, event) {......


vjs.Component.prototype.trigger = function(type, event){
//vjs.trigger signature has only two arguments. Not sure if this was done intentionally
  vjs.trigger(this.el_, type, event);
  return this;
};
@bceacuna
Copy link
Author

This seems to solve the problem in my development environment.

vjs.Component.prototype.trigger = function(type, event){
  if (event){    
   event.type = type;
   vjs.trigger(this.el_, event);      
  } else {
    vjs.trigger(this.el_, type, event);
  }
  return this;
};

@mmcc mmcc added the question label Jun 17, 2014
@heff
Copy link
Member

heff commented Jun 23, 2014

component.trigger passing three arguments to a function that takes two is definitely wrong. What vjs.trigger expects is for the second argument to either be a string (the event type) or an event object with a type attribute. There's no cases where both a type string and an event object should be needed.

What should happen here is that type argument of component.trigger should be removed, leaving only event, which will then represent either the string or object, like vjs.trigger expects.

Does that make sense, and would that clear up your issue? If so would you want to make a quick pull request to fix that?

@heff heff added bug and removed question labels Jun 23, 2014
@bceacuna
Copy link
Author

Done! I just fixed it and submitted a pull request.

@mmcc
Copy link
Member

mmcc commented Jul 28, 2014

Fixed via #1310. Thanks for the PR!

@mmcc mmcc closed this as completed Jul 28, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants