-
Notifications
You must be signed in to change notification settings - Fork 24.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
WebSocket API change to make room for other connection options (SSL pinning) #15334
Changes from 2 commits
a7d4b06
02fe031
865bfdf
92099ff
3e1b6ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,12 +93,26 @@ class WebSocket extends EventTarget(...WEBSOCKET_EVENTS) { | |
// `WebSocket.isAvailable` will return `false`, and WebSocket constructor will throw an error | ||
static isAvailable: boolean = !!WebSocketModule; | ||
|
||
constructor(url: string, protocols: ?string | ?Array<string>, options: ?{origin?: string}) { | ||
constructor(url: string, protocols: ?string | ?Array<string>, options: ?{ headers?: { origin?: string}}) { | ||
super(); | ||
if (typeof protocols === 'string') { | ||
protocols = [protocols]; | ||
} | ||
|
||
const { headers = {}, origin, ...unrecognized } = options || {}; | ||
|
||
// Preserve deprecated backwards compatibility for 'options.origin' | ||
if (origin && typeof origin === 'string') { | ||
console.warn(`Specifying "origin" as a WebSocket connection option is deprecated. Include it under "headers" instead.`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quotes: Strings must use singlequote. |
||
headers.origin = origin; | ||
} | ||
|
||
// Warn about and discard anything else | ||
if (Object.keys(unrecognized).length > 0) { | ||
console.warn(`Unrecognized WebSocket connection option(s) "${Object.keys(unrecognized).join(`", "`)}". ` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quotes: Strings must use singlequote. |
||
+ `Did you mean to put these under "headers"?`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quotes: Strings must use singlequote. |
||
} | ||
|
||
if (!Array.isArray(protocols)) { | ||
protocols = null; | ||
} | ||
|
@@ -111,7 +125,7 @@ class WebSocket extends EventTarget(...WEBSOCKET_EVENTS) { | |
this._eventEmitter = new NativeEventEmitter(WebSocketModule); | ||
this._socketId = nextWebSocketId++; | ||
this._registerEvents(); | ||
WebSocketModule.connect(url, protocols, options, this._socketId); | ||
WebSocketModule.connect(url, protocols, { headers }, this._socketId); | ||
} | ||
|
||
get binaryType(): ?BinaryType { | ||
|
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.
property
origin
Property not found in object typeThere 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.
npm run lint
doesn't have any problem with this.