Fix 'on' and 'once' memory leak

pull/437/head
Fabrizio Ruggeri 2020-04-02 16:11:54 +02:00
parent b7a36700f9
commit dd8aeec0dc
3 changed files with 9 additions and 51 deletions

View File

@ -589,14 +589,7 @@ export class Session implements EventDispatcher {
*/ */
on(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): EventDispatcher { on(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): EventDispatcher {
this.ee.on(type, event => { this.ee.on(type, handler);
if (event) {
console.info("Event '" + type + "' triggered by 'Session'", event);
} else {
console.info("Event '" + type + "' triggered by 'Session'");
}
handler(event);
});
if (type === 'publisherStartSpeaking') { if (type === 'publisherStartSpeaking') {
this.startSpeakingEventsEnabled = true; this.startSpeakingEventsEnabled = true;
@ -628,14 +621,7 @@ export class Session implements EventDispatcher {
*/ */
once(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): Session { once(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): Session {
this.ee.once(type, event => { this.ee.once(type, handler);
if (event) {
console.info("Event '" + type + "' triggered once by 'Session'", event);
} else {
console.info("Event '" + type + "' triggered once by 'Session'");
}
handler(event);
});
if (type === 'publisherStartSpeaking') { if (type === 'publisherStartSpeaking') {
this.startSpeakingEventsEnabledOnce = true; this.startSpeakingEventsEnabledOnce = true;
@ -669,7 +655,7 @@ export class Session implements EventDispatcher {
if (!handler) { if (!handler) {
this.ee.removeAllListeners(type); this.ee.removeAllListeners(type);
} else { } else {
this.ee.off(type, handler); this.ee.removeListener(type, handler);
} }
if (type === 'publisherStartSpeaking') { if (type === 'publisherStartSpeaking') {

View File

@ -265,14 +265,7 @@ export class Stream implements EventDispatcher {
* See [[EventDispatcher.on]] * See [[EventDispatcher.on]]
*/ */
on(type: string, handler: (event: Event) => void): EventDispatcher { on(type: string, handler: (event: Event) => void): EventDispatcher {
this.ee.on(type, event => { this.ee.on(type, handler);
if (event) {
console.info("Event '" + type + "' triggered by stream '" + this.streamId + "'", event);
} else {
console.info("Event '" + type + "' triggered by stream '" + this.streamId + "'");
}
handler(event);
});
return this; return this;
} }
@ -281,14 +274,7 @@ export class Stream implements EventDispatcher {
* See [[EventDispatcher.once]] * See [[EventDispatcher.once]]
*/ */
once(type: string, handler: (event: Event) => void): EventDispatcher { once(type: string, handler: (event: Event) => void): EventDispatcher {
this.ee.once(type, event => { this.ee.once(type, handler);
if (event) {
console.info("Event '" + type + "' triggered once by stream '" + this.streamId + "'", event);
} else {
console.info("Event '" + type + "' triggered once by stream '" + this.streamId + "'");
}
handler(event);
});
return this; return this;
} }
@ -1219,4 +1205,4 @@ export class Stream implements EventDispatcher {
(report.type === 'candidate-pair' && report.nominated && report.bytesSent > 0); (report.type === 'candidate-pair' && report.nominated && report.bytesSent > 0);
} }
} }

View File

@ -149,14 +149,7 @@ export class StreamManager implements EventDispatcher {
* See [[EventDispatcher.on]] * See [[EventDispatcher.on]]
*/ */
on(type: string, handler: (event: Event) => void): EventDispatcher { on(type: string, handler: (event: Event) => void): EventDispatcher {
this.ee.on(type, event => { this.ee.on(type, handler);
if (event) {
console.info("Event '" + type + "' triggered by '" + (this.remote ? 'Subscriber' : 'Publisher') + "'", event);
} else {
console.info("Event '" + type + "' triggered by '" + (this.remote ? 'Subscriber' : 'Publisher') + "'");
}
handler(event);
});
if (type === 'videoElementCreated') { if (type === 'videoElementCreated') {
if (!!this.stream && this.lazyLaunchVideoElementCreatedEvent) { if (!!this.stream && this.lazyLaunchVideoElementCreatedEvent) {
this.ee.emitEvent('videoElementCreated', [new VideoElementEvent(this.videos[0].video, this, 'videoElementCreated')]); this.ee.emitEvent('videoElementCreated', [new VideoElementEvent(this.videos[0].video, this, 'videoElementCreated')]);
@ -183,14 +176,7 @@ export class StreamManager implements EventDispatcher {
* See [[EventDispatcher.once]] * See [[EventDispatcher.once]]
*/ */
once(type: string, handler: (event: Event) => void): StreamManager { once(type: string, handler: (event: Event) => void): StreamManager {
this.ee.once(type, event => { this.ee.once(type, handler);
if (event) {
console.info("Event '" + type + "' triggered once by '" + (this.remote ? 'Subscriber' : 'Publisher') + "'", event);
} else {
console.info("Event '" + type + "' triggered once by '" + (this.remote ? 'Subscriber' : 'Publisher') + "'");
}
handler(event);
});
if (type === 'videoElementCreated') { if (type === 'videoElementCreated') {
if (!!this.stream && this.lazyLaunchVideoElementCreatedEvent) { if (!!this.stream && this.lazyLaunchVideoElementCreatedEvent) {
this.ee.emitEvent('videoElementCreated', [new VideoElementEvent(this.videos[0].video, this, 'videoElementCreated')]); this.ee.emitEvent('videoElementCreated', [new VideoElementEvent(this.videos[0].video, this, 'videoElementCreated')]);
@ -514,4 +500,4 @@ export class StreamManager implements EventDispatcher {
video.style.webkitTransform = 'unset'; video.style.webkitTransform = 'unset';
} }
} }