-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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[]; |
There was a problem hiding this comment.
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 string
s 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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 []
This PR adds a
protocol
option to thePeerOptions
, that users can use to for instance choose different versions of Peer servers, and more.