Skip to content

Commit

Permalink
remove events/EventEmitter && move Observer to ts (video-dev#2097)
Browse files Browse the repository at this point in the history
* remove events/EventEmitter && move Observer to ts

* disable node modules in webpack
  • Loading branch information
mad-gooze authored and johnBartos committed Feb 11, 2019
1 parent 0bbb9b8 commit 48f64de
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ design idea is pretty simple :
- main functionalities are split into several subsystems
- all subsystems are instantiated by the Hls instance.
- each subsystem heavily relies on events for internal/external communications.
- Events are handled using [EventEmitter](https://nodejs.org/api/events.html)
- Events are handled using [EventEmitter3](https://github.com/primus/eventemitter3)
- bundled for the browser by [webpack](https://webpack.js.org/)

## Code structure
Expand Down
2 changes: 1 addition & 1 deletion src/demux/demuxer-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DemuxerInline from '../demux/demuxer-inline';
import Event from '../events';
import { enableLogs } from '../utils/logger';

import { EventEmitter } from 'events';
import { EventEmitter } from 'eventemitter3';

let DemuxerWorker = function (self) {
// observer setup
Expand Down
2 changes: 1 addition & 1 deletion src/demux/demuxer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter } from 'events';
import { EventEmitter } from 'eventemitter3';
import * as work from 'webworkify-webpack';

import Event from '../events';
Expand Down
22 changes: 0 additions & 22 deletions src/observer.js

This file was deleted.

15 changes: 15 additions & 0 deletions src/observer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { EventEmitter } from 'eventemitter3';

/**
* Simple adapter sub-class of Nodejs-like EventEmitter.
*/
export class Observer extends EventEmitter {
/**
* We simply want to pass along the event-name itself
* in every call to a handler, which is the purpose of our `trigger` method
* extending the standard API.
*/
trigger (event: string, ...data: Array<any>): void {
this.emit(event, event, ...data);
}
}
2 changes: 1 addition & 1 deletion tests/unit/controller/eme-controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EMEController from '../../../src/controller/eme-controller';
import HlsMock from '../../mocks/hls.mock';
import EventEmitter from 'events';
import { EventEmitter } from 'eventemitter3';
import { ErrorDetails } from '../../../src/errors';

const sinon = require('sinon');
Expand Down
8 changes: 8 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ const baseConfig = {
}
}
]
},
node: {
global: false,
process: false,
__filename: false,
__dirname: false,
Buffer: false,
setImmediate: false
}
};

Expand Down

0 comments on commit 48f64de

Please sign in to comment.