Skip to content

Commit 9e3715a

Browse files
committed
Change how step definitions for manual rule building are exposed
If you're using the rule chaining API this won't affect you. If you're building custom rules though (set/addRulesFromDefinitions()) then you'll need to migrate. Steps and matchers are now exposed as 'steps' and 'matchers' (instead of HandleStepDefinitions and MatcherDefinitions) and the individual classes have all lost their Definition suffix (e.g. EchoStepDefinition is now just EchoStep). This aligns with equivalent changes in Mockttp v4.
1 parent f41f1b2 commit 9e3715a

11 files changed

Lines changed: 159 additions & 158 deletions

src/handling/handler-builder.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55

66
import {
77
type HandlerStepDefinition,
8-
PeerProxyStepDefinition,
9-
CreateChannelStepDefinition,
10-
SendStepDefinition,
11-
DynamicProxyStepDefinition,
12-
WaitForChannelStepDefinition,
13-
WaitForMessageStepDefinition,
14-
WaitForDurationStepDefinition,
15-
CloseStepDefinition,
16-
EchoStepDefinition,
17-
WaitForTrackStepDefinition,
18-
WaitForMediaStepDefinition
8+
PeerProxyStep,
9+
CreateChannelStep,
10+
SendStep,
11+
DynamicProxyStep,
12+
WaitForChannelStep,
13+
WaitForMessageStep,
14+
WaitForDurationStep,
15+
CloseStep,
16+
EchoStep,
17+
WaitForTrackStep,
18+
WaitForMediaStep
1919
} from "./handler-step-definitions";
2020

2121
/**
@@ -37,7 +37,7 @@ export class MockRTCHandlerBuilder<R> {
3737
* @category Steps
3838
*/
3939
sleep(duration: number): MockRTCHandlerBuilder<R> {
40-
this.handlerSteps.push(new WaitForDurationStepDefinition(duration));
40+
this.handlerSteps.push(new WaitForDurationStep(duration));
4141
return this;
4242
}
4343

@@ -47,7 +47,7 @@ export class MockRTCHandlerBuilder<R> {
4747
* @category Steps
4848
*/
4949
waitForChannel(channelLabel?: string): MockRTCHandlerBuilder<R> {
50-
this.handlerSteps.push(new WaitForChannelStepDefinition(channelLabel));
50+
this.handlerSteps.push(new WaitForChannelStep(channelLabel));
5151
return this;
5252
}
5353

@@ -57,7 +57,7 @@ export class MockRTCHandlerBuilder<R> {
5757
* @category Steps
5858
*/
5959
waitForTrack(): MockRTCHandlerBuilder<R> {
60-
this.handlerSteps.push(new WaitForTrackStepDefinition());
60+
this.handlerSteps.push(new WaitForTrackStep());
6161
return this;
6262
}
6363

@@ -70,7 +70,7 @@ export class MockRTCHandlerBuilder<R> {
7070
* @category Steps
7171
*/
7272
waitForNextMessage(): MockRTCHandlerBuilder<R> {
73-
this.handlerSteps.push(new WaitForMessageStepDefinition());
73+
this.handlerSteps.push(new WaitForMessageStep());
7474
return this;
7575
}
7676

@@ -82,7 +82,7 @@ export class MockRTCHandlerBuilder<R> {
8282
* @category Steps
8383
*/
8484
waitForNextMedia(): MockRTCHandlerBuilder<R> {
85-
this.handlerSteps.push(new WaitForMediaStepDefinition());
85+
this.handlerSteps.push(new WaitForMediaStep());
8686
return this;
8787
}
8888

@@ -95,7 +95,7 @@ export class MockRTCHandlerBuilder<R> {
9595
* @category Steps
9696
*/
9797
waitForNextMessageOnChannel(channelLabel: string): MockRTCHandlerBuilder<R> {
98-
this.handlerSteps.push(new WaitForMessageStepDefinition(channelLabel));
98+
this.handlerSteps.push(new WaitForMessageStep(channelLabel));
9999
return this;
100100
}
101101

@@ -106,7 +106,7 @@ export class MockRTCHandlerBuilder<R> {
106106
* @category Steps
107107
*/
108108
createDataChannel(channelLabel: string): MockRTCHandlerBuilder<R> {
109-
this.handlerSteps.push(new CreateChannelStepDefinition(channelLabel));
109+
this.handlerSteps.push(new CreateChannelStep(channelLabel));
110110
return this;
111111
}
112112

@@ -128,10 +128,10 @@ export class MockRTCHandlerBuilder<R> {
128128
send(...args: [string | undefined, string | Buffer] | [string | Buffer]): MockRTCHandlerBuilder<R> {
129129
if (args[1] !== undefined) {
130130
const [channel, message] = args as [string, string | Buffer];
131-
this.handlerSteps.push(new SendStepDefinition(channel, message));
131+
this.handlerSteps.push(new SendStep(channel, message));
132132
} else {
133133
const [message] = args as [string | Buffer];
134-
this.handlerSteps.push(new SendStepDefinition(undefined, message));
134+
this.handlerSteps.push(new SendStep(undefined, message));
135135
}
136136
return this;
137137
}
@@ -146,7 +146,7 @@ export class MockRTCHandlerBuilder<R> {
146146
* @category Final Steps
147147
*/
148148
thenClose(): Promise<R> {
149-
this.handlerSteps.push(new CloseStepDefinition());
149+
this.handlerSteps.push(new CloseStep());
150150
return this.buildCallback(this.handlerSteps);
151151
}
152152

@@ -179,7 +179,7 @@ export class MockRTCHandlerBuilder<R> {
179179
* @category Final Steps
180180
*/
181181
thenEcho(): Promise<R> {
182-
this.handlerSteps.push(new EchoStepDefinition());
182+
this.handlerSteps.push(new EchoStep());
183183
return this.buildCallback(this.handlerSteps);
184184
}
185185

@@ -195,7 +195,7 @@ export class MockRTCHandlerBuilder<R> {
195195
* @category Final Steps
196196
*/
197197
thenForwardTo(peer: RTCPeerConnection): Promise<R> {
198-
this.handlerSteps.push(new PeerProxyStepDefinition(peer));
198+
this.handlerSteps.push(new PeerProxyStep(peer));
199199
return this.buildCallback(this.handlerSteps);
200200
}
201201

@@ -220,7 +220,7 @@ export class MockRTCHandlerBuilder<R> {
220220
* @category Final Steps
221221
*/
222222
thenPassThrough(): Promise<R> {
223-
this.handlerSteps.push(new DynamicProxyStepDefinition());
223+
this.handlerSteps.push(new DynamicProxyStep());
224224
return this.buildCallback(this.handlerSteps);
225225
}
226226

src/handling/handler-step-definitions.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as PluggableAdmin from 'mockttp/dist/pluggable-admin-api/pluggable-admin.browser';
77

88
import { MockRTCSessionDescription } from '../mockrtc';
9+
import type { RTCConnection } from '../webrtc/rtc-connection';
910

1011
export type Serializable = PluggableAdmin.Serialization.Serializable;
1112
export const { Serializable } = PluggableAdmin.Serialization;
@@ -15,7 +16,7 @@ export interface HandlerStepDefinition extends Serializable {
1516
readonly type: keyof typeof StepDefinitionLookup;
1617
}
1718

18-
export class WaitForDurationStepDefinition extends Serializable implements HandlerStepDefinition {
19+
export class WaitForDurationStep extends Serializable implements HandlerStepDefinition {
1920

2021
readonly type = 'wait-for-duration';
2122
static readonly isFinal = false;
@@ -32,7 +33,7 @@ export class WaitForDurationStepDefinition extends Serializable implements Handl
3233

3334
}
3435

35-
export class WaitForChannelStepDefinition extends Serializable implements HandlerStepDefinition {
36+
export class WaitForChannelStep extends Serializable implements HandlerStepDefinition {
3637

3738
readonly type = 'wait-for-rtc-data-channel';
3839
static readonly isFinal = false;
@@ -49,7 +50,7 @@ export class WaitForChannelStepDefinition extends Serializable implements Handle
4950

5051
}
5152

52-
export class WaitForMessageStepDefinition extends Serializable implements HandlerStepDefinition {
53+
export class WaitForMessageStep extends Serializable implements HandlerStepDefinition {
5354

5455
readonly type = 'wait-for-rtc-message';
5556
static readonly isFinal = false;
@@ -66,7 +67,7 @@ export class WaitForMessageStepDefinition extends Serializable implements Handle
6667

6768
}
6869

69-
export class WaitForTrackStepDefinition extends Serializable implements HandlerStepDefinition {
70+
export class WaitForTrackStep extends Serializable implements HandlerStepDefinition {
7071

7172
readonly type = 'wait-for-rtc-track';
7273
static readonly isFinal = false;
@@ -77,7 +78,7 @@ export class WaitForTrackStepDefinition extends Serializable implements HandlerS
7778

7879
}
7980

80-
export class WaitForMediaStepDefinition extends Serializable implements HandlerStepDefinition {
81+
export class WaitForMediaStep extends Serializable implements HandlerStepDefinition {
8182

8283
readonly type = 'wait-for-rtc-media';
8384
static readonly isFinal = false;
@@ -88,7 +89,7 @@ export class WaitForMediaStepDefinition extends Serializable implements HandlerS
8889

8990
}
9091

91-
export class CreateChannelStepDefinition extends Serializable implements HandlerStepDefinition {
92+
export class CreateChannelStep extends Serializable implements HandlerStepDefinition {
9293

9394
readonly type = 'create-rtc-data-channel';
9495
static readonly isFinal = false;
@@ -105,7 +106,7 @@ export class CreateChannelStepDefinition extends Serializable implements Handler
105106

106107
}
107108

108-
export class SendStepDefinition extends Serializable implements HandlerStepDefinition {
109+
export class SendStep extends Serializable implements HandlerStepDefinition {
109110

110111
readonly type = 'send-rtc-data-message';
111112
static readonly isFinal = false;
@@ -123,7 +124,7 @@ export class SendStepDefinition extends Serializable implements HandlerStepDefin
123124

124125
}
125126

126-
export class CloseStepDefinition extends Serializable implements HandlerStepDefinition {
127+
export class CloseStep extends Serializable implements HandlerStepDefinition {
127128

128129
readonly type = 'close-rtc-connection';
129130
static readonly isFinal = true;
@@ -134,7 +135,7 @@ export class CloseStepDefinition extends Serializable implements HandlerStepDefi
134135

135136
}
136137

137-
export class EchoStepDefinition extends Serializable implements HandlerStepDefinition {
138+
export class EchoStep extends Serializable implements HandlerStepDefinition {
138139

139140
readonly type = 'echo-rtc';
140141
static readonly isFinal = true;
@@ -145,11 +146,13 @@ export class EchoStepDefinition extends Serializable implements HandlerStepDefin
145146

146147
}
147148

148-
export class PeerProxyStepDefinition extends Serializable implements HandlerStepDefinition {
149+
export class PeerProxyStep extends Serializable implements HandlerStepDefinition {
149150

150151
readonly type = 'rtc-peer-proxy';
151152
static readonly isFinal = true;
152153

154+
protected externalConnections: RTCConnection[] = []; // Set here so it can be used in impl subclass
155+
153156
protected getAnswer: (offer: MockRTCSessionDescription) => Promise<RTCSessionDescriptionInit>;
154157

155158
constructor(
@@ -187,27 +190,29 @@ export class PeerProxyStepDefinition extends Serializable implements HandlerStep
187190

188191
}
189192

190-
export class DynamicProxyStepDefinition extends Serializable implements HandlerStepDefinition {
193+
export class DynamicProxyStep extends Serializable implements HandlerStepDefinition {
191194

192195
readonly type = 'rtc-dynamic-proxy';
193196
static readonly isFinal = true;
194197

198+
protected externalConnections: RTCConnection[] = []; // Set here so it can be used in impl subclass
199+
195200
explain() {
196201
return `proxy the RTC connection to a remote peer`;
197202
}
198203

199204
}
200205

201206
export const StepDefinitionLookup = {
202-
'wait-for-duration': WaitForDurationStepDefinition,
203-
'wait-for-rtc-data-channel': WaitForChannelStepDefinition,
204-
'wait-for-rtc-track': WaitForTrackStepDefinition,
205-
'wait-for-rtc-media': WaitForMediaStepDefinition,
206-
'wait-for-rtc-message': WaitForMessageStepDefinition,
207-
'create-rtc-data-channel': CreateChannelStepDefinition,
208-
'send-rtc-data-message': SendStepDefinition,
209-
'close-rtc-connection': CloseStepDefinition,
210-
'echo-rtc': EchoStepDefinition,
211-
'rtc-peer-proxy': PeerProxyStepDefinition,
212-
'rtc-dynamic-proxy': DynamicProxyStepDefinition
207+
'wait-for-duration': WaitForDurationStep,
208+
'wait-for-rtc-data-channel': WaitForChannelStep,
209+
'wait-for-rtc-track': WaitForTrackStep,
210+
'wait-for-rtc-media': WaitForMediaStep,
211+
'wait-for-rtc-message': WaitForMessageStep,
212+
'create-rtc-data-channel': CreateChannelStep,
213+
'send-rtc-data-message': SendStep,
214+
'close-rtc-connection': CloseStep,
215+
'echo-rtc': EchoStep,
216+
'rtc-peer-proxy': PeerProxyStep,
217+
'rtc-dynamic-proxy': DynamicProxyStep
213218
};

0 commit comments

Comments
 (0)