Skip to content

Commit ac69e11

Browse files
committed
Fix websocket view typing & tweak cleanup button slightly
1 parent 98e1368 commit ac69e11

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

src/components/view/http/http-details-pane.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { action, computed } from 'mobx';
44
import { observer, inject } from 'mobx-react';
55
import * as portals from 'react-reverse-portal';
66

7-
import { CollectedEvent, HtkResponse, HttpExchange, HttpExchangeView } from '../../../types';
7+
import { CollectedEvent, HtkResponse, HttpExchangeView } from '../../../types';
88
import { styled } from '../../../styles';
99
import { logError } from '../../../errors';
1010

@@ -15,7 +15,7 @@ import { ApiExchange } from '../../../model/api/api-interfaces';
1515
import { buildRuleFromRequest } from '../../../model/rules/rule-creation';
1616
import { findItem } from '../../../model/rules/rules-structure';
1717
import { HtkRule, getRulePartKey } from '../../../model/rules/rules';
18-
import { WebSocketStream } from '../../../model/websockets/websocket-stream';
18+
import { WebSocketView } from '../../../model/websockets/websocket-views';
1919
import { tagsToErrorType } from '../../../model/http/error-types';
2020

2121
import { PaneScrollContainer } from '../view-details-pane';
@@ -448,7 +448,7 @@ export class HttpDetailsPane extends React.Component<{
448448
/>;
449449
}
450450

451-
private renderWebSocketMessages(exchange: WebSocketStream) {
451+
private renderWebSocketMessages(exchange: WebSocketView) {
452452
const urlParts = exchange.request.url.split('/');
453453
const domain = urlParts[2].split(':')[0];
454454
const baseName = urlParts.length >= 2 ? urlParts[urlParts.length - 1] : undefined;
@@ -469,7 +469,7 @@ export class HttpDetailsPane extends React.Component<{
469469
isPaidUser={this.props.accountStore!.isPaidUser}
470470
filenamePrefix={filenamePrefix}
471471
messages={exchange.messages}
472-
onClearMessages={() => exchange.downstream.cleanupMessages()}
472+
onClearMessages={this.clearMessages}
473473
/>;
474474
}
475475

@@ -542,4 +542,11 @@ export class HttpDetailsPane extends React.Component<{
542542
exchange.hideErrors = true;
543543
}
544544

545+
@action.bound
546+
private clearMessages() {
547+
const { exchange } = this.props;
548+
if (!exchange.isWebSocket()) return;
549+
exchange.downstream.clearMessages();
550+
}
551+
545552
};

src/components/view/stream-message-list-card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class StreamMessageListCard extends React.Component<ExpandableCardProps &
4343
streamId: string,
4444
streamType: StreamType,
4545
streamLabel?: string,
46-
messages: Array<StreamMessage>,
46+
messages: ReadonlyArray<StreamMessage>,
4747
editorNode: portals.HtmlPortalNode<typeof SelfSizedEditor>
4848
onClearMessages?: () => void,
4949
}> {
@@ -96,7 +96,7 @@ export class StreamMessageListCard extends React.Component<ExpandableCardProps &
9696
/>
9797
{ onClearMessages &&
9898
<IconButton
99-
icon={['fas', 'ban']}
99+
icon={['far', 'trash-alt']}
100100
title="Clear all messages"
101101
onClick={onClearMessages}
102102
/> }

src/model/events/event-base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {
44
FailedTlsConnection,
55
TlsTunnel,
66
HttpExchangeView,
7+
WebSocketView,
78
RTCConnection,
89
RTCDataChannel,
9-
RTCMediaTrack,
10-
WebSocketStream
10+
RTCMediaTrack
1111
} from '../../types';
1212

1313
import { getEventCategory } from './categorization';
@@ -18,7 +18,7 @@ export abstract class HTKEventBase {
1818

1919
// These can be overriden by subclasses to allow easy type narrowing:
2020
isHttp(): this is HttpExchangeView { return false; }
21-
isWebSocket(): this is WebSocketStream { return false; }
21+
isWebSocket(): this is WebSocketView { return false; }
2222

2323
isTlsFailure(): this is FailedTlsConnection { return false; }
2424
isTlsTunnel(): this is TlsTunnel { return false; }

src/model/websockets/websocket-stream.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ export class WebSocketStream extends HttpExchange implements WebSocketView {
128128
}
129129

130130
@action
131-
cleanupMessages() {
131+
clearMessages() {
132132
// Clear all websocket message data too
133133
this.messages.forEach(msg => msg.cleanup());
134134
this.messages.length = 0;
135135
}
136136

137137
cleanup() {
138138
super.cleanup();
139-
this.cleanupMessages();
139+
this.clearMessages();
140140
}
141141
}

src/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type { HttpExchange, HttpVersion } from './model/http/http-exchange';
3939
import type { HttpExchangeView } from './model/http/http-exchange-views';
4040

4141
import type { WebSocketStream } from './model/websockets/websocket-stream';
42+
import type { WebSocketView } from './model/websockets/websocket-views';
4243
import type { RTCConnection } from './model/webrtc/rtc-connection';
4344
import type { RTCDataChannel } from './model/webrtc/rtc-data-channel';
4445
import type { RTCMediaTrack } from './model/webrtc/rtc-media-track';
@@ -227,6 +228,7 @@ export type {
227228
HttpExchange,
228229
HttpExchangeView,
229230
WebSocketStream,
231+
WebSocketView,
230232
RTCConnection,
231233
RTCDataChannel,
232234
RTCMediaTrack

0 commit comments

Comments
 (0)