Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

fromEvent not working, native event binding is

I’m building a video-player library for angular. Currently working on a Streamable integration.

I’ve recreated the situation in a StackBlitz, where you can see a console.warn for player.on('ready', ...) but not for fromEvent(player, 'ready').subscribe(...)

const player = new playerjs.Player(iframe);

player.on('ready', () => console.warn('player.on(ready)'));
fromEvent(player, 'ready').subscribe(() => console.warn('fromEvent ready'));

Does anyone know why fromEvent doesn’t work in this situation?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Similar examples (also using on):

I have to note that the same does actually work for Vidyard.

>Solution :

You could try to use the fromEventPattern function, which allows you to specify custom add and remove handler functions.

Example;

const addHandler = (handler) => player.on('ready', handler);
const removeHandler = (handler) => player.off('ready', handler);

fromEventPattern(addHandler, removeHandler).subscribe(() => console.warn('fromEventPattern ready'));

From the above, I use addHandler to adds a handler for the ‘ready’ event, and removeHandler that removes a handler. fromEventPattern uses these functions to create an Observable that emits events whenever the ‘ready’ event is fired.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading