Skip to content

Commit

Permalink
Merge pull request #889 from nazar-pc/refactor-internal
Browse files Browse the repository at this point in the history
Refactor internal
  • Loading branch information
nazar-pc authored Aug 22, 2022
2 parents b555e54 + ce598a0 commit 11f45ff
Show file tree
Hide file tree
Showing 77 changed files with 999 additions and 962 deletions.
8 changes: 4 additions & 4 deletions doc/closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Some considerations:
## JS router.close()

* Public API.
* Sends channel request `ROUTER_CLOSE`:
* Sends channel request `WORKER_CLOSE_ROUTER`:
- Processed by the C++ Worker.
- It removes the C++ Router from its map.
- It calls C++ `delete router`.
Expand All @@ -51,7 +51,7 @@ Some considerations:
## JS transport.close()

* Public API.
* Sends channel request `TRANSPORT_CLOSE`.
* Sends channel request `ROUTER_CLOSE_TRANSPORT`.
- Processed by the C++ Router.
- It calls C++ `transport->Close()` (so the C++ Transport will notify the C++ Router about closed Producers and Consumers in that Transport).
- It removes the C++ Transport from its map.
Expand Down Expand Up @@ -106,7 +106,7 @@ Some considerations:
## JS producer.close()

* Public API.
* Sends channel request `PRODUCER_CLOSE`.
* Sends channel request `TRANSPORT_CLOSE_PRODUCER`.
- Processed by the C++ Transport.
- Removes it from its map of Producers.
- Calls its `listener->OnTransportProducerClosed(this, producer)` (so the C++ Router cleans its maps and calls `consumer->ProducerClose()` on its associated Consumers).
Expand All @@ -125,7 +125,7 @@ Some considerations:
## JS consumer.close()

* Public API.
* Sends channel request `CONSUMER_CLOSE`.
* Sends channel request `TRANSPORT_CLOSE_CONSUMER`.
- Processed by the C++ Transport.
- Removes it from its map of Consumers.
- Calls its `listener->OnTransportConsumerClosed(this, consumer)` (so the C++ Router cleans its maps).
Expand Down
2 changes: 1 addition & 1 deletion node/lib/Channel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export declare class Channel extends EnhancedEventEmitter {
/**
* @private
*/
request(method: string, internal?: object, data?: any): Promise<any>;
request(method: string, handlerId?: string, data?: any): Promise<any>;
private processMessage;
}
//# sourceMappingURL=Channel.d.ts.map
2 changes: 1 addition & 1 deletion node/lib/Channel.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ class Channel extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* @private
*/
async request(method, internal, data) {
async request(method, handlerId, data) {
this.#nextId < 4294967295 ? ++this.#nextId : (this.#nextId = 1);
const id = this.#nextId;
logger.debug('request() [method:%s, id:%s]', method, id);
if (this.#closed)
throw new errors_1.InvalidStateError('Channel closed');
const request = { id, method, internal, data };
const request = { id, method, handlerId, data };
const payload = JSON.stringify(request);
if (Buffer.byteLength(payload) > MESSAGE_MAX_LEN)
throw new Error('Channel request too big');
Expand Down
2 changes: 1 addition & 1 deletion node/lib/Consumer.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions node/lib/Consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ class Consumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
// Remove notification subscriptions.
this.#channel.removeAllListeners(this.#internal.consumerId);
this.#payloadChannel.removeAllListeners(this.#internal.consumerId);
this.#channel.request('consumer.close', this.#internal)
const reqData = { consumerId: this.#internal.consumerId };
this.#channel.request('transport.closeConsumer', this.#internal.transportId, reqData)
.catch(() => { });
this.emit('@close');
// Emit observer event.
Expand Down Expand Up @@ -184,22 +185,22 @@ class Consumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
*/
async dump() {
logger.debug('dump()');
return this.#channel.request('consumer.dump', this.#internal);
return this.#channel.request('consumer.dump', this.#internal.consumerId);
}
/**
* Get Consumer stats.
*/
async getStats() {
logger.debug('getStats()');
return this.#channel.request('consumer.getStats', this.#internal);
return this.#channel.request('consumer.getStats', this.#internal.consumerId);
}
/**
* Pause the Consumer.
*/
async pause() {
logger.debug('pause()');
const wasPaused = this.#paused || this.#producerPaused;
await this.#channel.request('consumer.pause', this.#internal);
await this.#channel.request('consumer.pause', this.#internal.consumerId);
this.#paused = true;
// Emit observer event.
if (!wasPaused)
Expand All @@ -211,7 +212,7 @@ class Consumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
async resume() {
logger.debug('resume()');
const wasPaused = this.#paused || this.#producerPaused;
await this.#channel.request('consumer.resume', this.#internal);
await this.#channel.request('consumer.resume', this.#internal.consumerId);
this.#paused = false;
// Emit observer event.
if (wasPaused && !this.#producerPaused)
Expand All @@ -223,7 +224,7 @@ class Consumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
async setPreferredLayers({ spatialLayer, temporalLayer }) {
logger.debug('setPreferredLayers()');
const reqData = { spatialLayer, temporalLayer };
const data = await this.#channel.request('consumer.setPreferredLayers', this.#internal, reqData);
const data = await this.#channel.request('consumer.setPreferredLayers', this.#internal.consumerId, reqData);
this.#preferredLayers = data || undefined;
}
/**
Expand All @@ -232,7 +233,7 @@ class Consumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
async setPriority(priority) {
logger.debug('setPriority()');
const reqData = { priority };
const data = await this.#channel.request('consumer.setPriority', this.#internal, reqData);
const data = await this.#channel.request('consumer.setPriority', this.#internal.consumerId, reqData);
this.#priority = data.priority;
}
/**
Expand All @@ -241,23 +242,23 @@ class Consumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
async unsetPriority() {
logger.debug('unsetPriority()');
const reqData = { priority: 1 };
const data = await this.#channel.request('consumer.setPriority', this.#internal, reqData);
const data = await this.#channel.request('consumer.setPriority', this.#internal.consumerId, reqData);
this.#priority = data.priority;
}
/**
* Request a key frame to the Producer.
*/
async requestKeyFrame() {
logger.debug('requestKeyFrame()');
await this.#channel.request('consumer.requestKeyFrame', this.#internal);
await this.#channel.request('consumer.requestKeyFrame', this.#internal.consumerId);
}
/**
* Enable 'trace' event.
*/
async enableTraceEvent(types = []) {
logger.debug('enableTraceEvent()');
const reqData = { types };
await this.#channel.request('consumer.enableTraceEvent', this.#internal, reqData);
await this.#channel.request('consumer.enableTraceEvent', this.#internal.consumerId, reqData);
}
handleWorkerNotifications() {
this.#channel.on(this.#internal.consumerId, (event, data) => {
Expand Down
Loading

0 comments on commit 11f45ff

Please sign in to comment.