Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(WebSocket): exports client connection protocol, transport, renames types #509

Merged
merged 6 commits into from
Feb 18, 2024

Conversation

kettanaito
Copy link
Member

No description provided.

import { WebSocketMessageListener } from './WebSocketOverride'
import { bindEvent } from './utils/bindEvent'
import { CloseEvent } from './utils/events'
import { uuidv4 } from '../../utils/uuid'

const kEmitter = Symbol('kEmitter')

export interface WebSocketClientConnectionProtocol {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exporting this protocol means that other consumers, like MSW, can implement custom client connection-like classes. For example, to support .clients in the browser, MSW creates virtual connection objects that use BroadcastChannel to implement methods like send() (signal other clients from other runtimes that they should now receive data).

/**
* The WebSocket client instance represents an incoming
* client connection. The user can control the connection,
* send and receive events.
*/
export class WebSocketClientConnection {
export class WebSocketClientConnection
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extending this class itself to implement connection-like objects is inefficient. It requires to provide a bunch of irrelevant properties, like kEmitter, socket, and transport. Those are internal details of this class but extending it means providing those internal details also.

@kettanaito kettanaito merged commit 2fbadc8 into main Feb 18, 2024
1 check passed
@kettanaito kettanaito deleted the fix/ws-improvements branch February 18, 2024 18:13
@kettanaito
Copy link
Member Author

Released: v0.26.5 🎉

This has been released in v0.26.5!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant