Add support for defining WebSocket protocol to use with Peer instance#987
Add support for defining WebSocket protocol to use with Peer instance#987skoshx wants to merge 3 commits intopeers:masterfrom
protocol to use with Peer instance#987Conversation
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.
jonasgloning
left a comment
There was a problem hiding this comment.
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.
| config?: any; | ||
| secure?: boolean; | ||
| pingInterval?: number; | ||
| protocol?: string | string[]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
| path: string, | ||
| key: string, | ||
| private readonly pingInterval: number = 5000, | ||
| private readonly protocol: string | string[] | undefined = undefined, |
There was a problem hiding this comment.
Let's skip undefined and initialize this to []
This PR adds a
protocoloption to thePeerOptions, that users can use to for instance choose different versions of Peer servers, and more.