Skip to content

Commit

Permalink
more handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Jul 13, 2023
1 parent 5eb92d5 commit ba78890
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/handlers/Chrome111.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ export class Chrome111 extends HandlerInterface
}: HandlerRunOptions
): void
{
this.assertNotClosed();

logger.debug('run()');

this._direction = direction;
Expand Down Expand Up @@ -257,6 +259,8 @@ export class Chrome111 extends HandlerInterface

async restartIce(iceParameters: IceParameters): Promise<void>
{
this.assertNotClosed();

logger.debug('restartIce()');

// Provide the remote SDP handler with new remote ICE parameters.
Expand Down
47 changes: 47 additions & 0 deletions src/handlers/Chrome74.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as ortc from '../ortc';
import * as sdpCommonUtils from './sdp/commonUtils';
import * as sdpUnifiedPlanUtils from './sdp/unifiedPlanUtils';
import * as ortcUtils from './ortc/utils';
import { InvalidStateError } from '../errors';
import {
HandlerFactory,
HandlerInterface,
Expand Down Expand Up @@ -34,6 +35,8 @@ const SCTP_NUM_STREAMS = { OS: 1024, MIS: 1024 };

export class Chrome74 extends HandlerInterface
{
// Closed flag.
private _closed = false;
// Handler direction.
private _direction?: 'send' | 'recv';
// Remote SDP handler.
Expand Down Expand Up @@ -82,6 +85,13 @@ export class Chrome74 extends HandlerInterface
{
logger.debug('close()');

if (this._closed)
{
return;
}

this._closed = true;

// Close RTCPeerConnection.
if (this._pc)
{
Expand Down Expand Up @@ -238,6 +248,8 @@ export class Chrome74 extends HandlerInterface

async updateIceServers(iceServers: RTCIceServer[]): Promise<void>
{
this.assertNotClosed();

logger.debug('updateIceServers()');

const configuration = this._pc.getConfiguration();
Expand All @@ -249,6 +261,8 @@ export class Chrome74 extends HandlerInterface

async restartIce(iceParameters: IceParameters): Promise<void>
{
this.assertNotClosed();

logger.debug('restartIce()');

// Provide the remote SDP handler with new remote ICE parameters.
Expand Down Expand Up @@ -299,13 +313,16 @@ export class Chrome74 extends HandlerInterface

async getTransportStats(): Promise<RTCStatsReport>
{
this.assertNotClosed();

return this._pc.getStats();
}

async send(
{ track, encodings, codecOptions, codec }: HandlerSendOptions
): Promise<HandlerSendResult>
{
this.assertNotClosed();
this.assertSendDirection();

logger.debug('send() [kind:%s, track.id:%s]', track.kind, track.id);
Expand Down Expand Up @@ -486,6 +503,11 @@ export class Chrome74 extends HandlerInterface

logger.debug('stopSending() [localId:%s]', localId);

if (this._closed)
{
return;
}

const transceiver = this._mapMidTransceiver.get(localId);

if (!transceiver)
Expand Down Expand Up @@ -531,6 +553,7 @@ export class Chrome74 extends HandlerInterface

async pauseSending(localId: string): Promise<void>
{
this.assertNotClosed();
this.assertSendDirection();

logger.debug('pauseSending() [localId:%s]', localId);
Expand Down Expand Up @@ -564,6 +587,7 @@ export class Chrome74 extends HandlerInterface

async resumeSending(localId: string): Promise<void>
{
this.assertNotClosed();
this.assertSendDirection();

logger.debug('resumeSending() [localId:%s]', localId);
Expand Down Expand Up @@ -600,6 +624,7 @@ export class Chrome74 extends HandlerInterface
localId: string, track: MediaStreamTrack | null
): Promise<void>
{
this.assertNotClosed();
this.assertSendDirection();

if (track)
Expand All @@ -624,6 +649,7 @@ export class Chrome74 extends HandlerInterface

async setMaxSpatialLayer(localId: string, spatialLayer: number): Promise<void>
{
this.assertNotClosed();
this.assertSendDirection();

logger.debug(
Expand Down Expand Up @@ -674,6 +700,7 @@ export class Chrome74 extends HandlerInterface

async setRtpEncodingParameters(localId: string, params: any): Promise<void>
{
this.assertNotClosed();
this.assertSendDirection();

logger.debug(
Expand Down Expand Up @@ -717,6 +744,7 @@ export class Chrome74 extends HandlerInterface

async getSenderStats(localId: string): Promise<RTCStatsReport>
{
this.assertNotClosed();
this.assertSendDirection();

const transceiver = this._mapMidTransceiver.get(localId);
Expand All @@ -739,6 +767,7 @@ export class Chrome74 extends HandlerInterface
}: HandlerSendDataChannelOptions
): Promise<HandlerSendDataChannelResult>
{
this.assertNotClosed();
this.assertSendDirection();

const options =
Expand Down Expand Up @@ -811,6 +840,7 @@ export class Chrome74 extends HandlerInterface
optionsList: HandlerReceiveOptions[]
) : Promise<HandlerReceiveResult[]>
{
this.assertNotClosed();
this.assertRecvDirection();

const results: HandlerReceiveResult[] = [];
Expand Down Expand Up @@ -911,6 +941,11 @@ export class Chrome74 extends HandlerInterface
{
this.assertRecvDirection();

if (this._closed)
{
return;
}

for (const localId of localIds)
{
logger.debug('stopReceiving() [localId:%s]', localId);
Expand Down Expand Up @@ -949,6 +984,7 @@ export class Chrome74 extends HandlerInterface

async pauseReceiving(localIds: string[]): Promise<void>
{
this.assertNotClosed();
this.assertRecvDirection();

for (const localId of localIds)
Expand Down Expand Up @@ -985,6 +1021,7 @@ export class Chrome74 extends HandlerInterface

async resumeReceiving(localIds: string[]): Promise<void>
{
this.assertNotClosed();
this.assertRecvDirection();

for (const localId of localIds)
Expand Down Expand Up @@ -1021,6 +1058,7 @@ export class Chrome74 extends HandlerInterface

async getReceiverStats(localId: string): Promise<RTCStatsReport>
{
this.assertNotClosed();
this.assertRecvDirection();

const transceiver = this._mapMidTransceiver.get(localId);
Expand All @@ -1037,6 +1075,7 @@ export class Chrome74 extends HandlerInterface
{ sctpStreamParameters, label, protocol }: HandlerReceiveDataChannelOptions
): Promise<HandlerReceiveDataChannelResult>
{
this.assertNotClosed();
this.assertRecvDirection();

const {
Expand Down Expand Up @@ -1140,6 +1179,14 @@ export class Chrome74 extends HandlerInterface
this._transportReady = true;
}

private assertNotClosed(): void
{
if (this._closed)
{
throw new InvalidStateError('method called in a closed handler');
}
}

private assertSendDirection(): void
{
if (this._direction !== 'send')
Expand Down

0 comments on commit ba78890

Please sign in to comment.