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

Add support for defining WebSocket protocol to use with Peer instance #987

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

skoshx
Copy link

@skoshx skoshx commented Jul 24, 2022

This PR adds a protocol option to the PeerOptions, that users can use to for instance choose different versions of Peer servers, and more.

skoshx added 3 commits July 24, 2022 17:57
This commit adds support for defining which WebSocket protocol a Peer instance should use.

This makes it possible to for instance use versioning for Peer servers, and much more.
Copy link
Member

@jonasgloning jonasgloning left a comment

Choose a reason for hiding this comment

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

Good idea!
Out of curiosity, what protocol do you want to set for your application?

I'm hesitant about allowing user protocols without prefixes because PeerJS might want to set its own in the future.
We could also reserve the peerjs- prefix for us, but I don't know how to express this in typescript.

@@ -28,6 +28,7 @@ class PeerOptions implements PeerJSOption {
config?: any;
secure?: boolean;
pingInterval?: number;
protocol?: string | string[];
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer this only accepts strings starting with a prefix.
What do you think about the type: x-${Lowercase<string>}?

That way PeerJS can still set its own protocols without interference from user-protocols.

Copy link
Author

Choose a reason for hiding this comment

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

But then this would force the hands of users to either (1) use protcols named x-${Lowercase<string>}, which would not always be possible, since the user might be using a WebSocket server not controlled by then, and that WebSocket server might have a protocol name that doesn't confine to the above types...

@@ -22,6 +22,7 @@ export class Socket extends EventEmitter {
path: string,
key: string,
private readonly pingInterval: number = 5000,
private readonly protocol: string | string[] | undefined = undefined,
Copy link
Member

Choose a reason for hiding this comment

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

Let's skip undefined and initialize this to []

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.

2 participants