Skip to content

Commit

Permalink
Merge pull request #1589 from ably/1424-document-MessagePack-platform…
Browse files Browse the repository at this point in the history
…-default

[SDK-3816] Document platform-specific nature of `useBinaryProtocol` default
  • Loading branch information
lawrence-forooghian authored Jan 25, 2024
2 parents 3336b66 + 89bd9ce commit f463647
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ably.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,9 @@ declare namespace Types {
tlsPort?: number;

/**
* When `true`, the more efficient MsgPack binary encoding is used. When `false`, JSON text encoding is used. The default is `true`.
* When `true`, the more efficient MsgPack binary encoding is used. When `false`, JSON text encoding is used. The default is `true` for Node.js, and `false` for all other platforms.
*
* @defaultValue `true`
* @defaultValue `true` for Node.js, `false` for all other platforms
*/
useBinaryProtocol?: boolean;

Expand Down
2 changes: 1 addition & 1 deletion src/platform/nativescript/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var Config = {
createHmac: null,
msgpack: msgpack,
supportsBinary: typeof TextDecoder !== 'undefined' && TextDecoder,
preferBinary: false,
preferBinary: false, // Motivation as on web; see `preferBinary` comment there.
ArrayBuffer: ArrayBuffer,
atob: null,
nextTick: function (f) {
Expand Down
2 changes: 1 addition & 1 deletion src/platform/react-native/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Platform: IPlatformConfig = {
createHmac: null,
msgpack: msgpack,
supportsBinary: !!(typeof TextDecoder !== 'undefined' && TextDecoder),
preferBinary: false,
preferBinary: false, // Motivation as on web; see `preferBinary` comment there.
ArrayBuffer: typeof ArrayBuffer !== 'undefined' && ArrayBuffer,
atob: global.atob,
nextTick: function (f: Function) {
Expand Down
4 changes: 4 additions & 0 deletions src/platform/web/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const Config: IPlatformConfig = {
createHmac: null,
msgpack: msgpack,
supportsBinary: !!globalObject.TextDecoder,
/* Per Paddy (https://ably-real-time.slack.com/archives/CURL4U2FP/p1705674537763479) web intentionally prefers JSON to MessagePack:
*
* > browsers' support for binary types in general was historically poor, and JSON transport performance is significantly better in a browser than msgpack. In modern browsers then binary is supported consistently, but I'd still expect that JSON encode/decode performance is dramatically better than msgpack in a browser.
*/
preferBinary: false,
ArrayBuffer: globalObject.ArrayBuffer,
atob: globalObject.atob,
Expand Down

0 comments on commit f463647

Please sign in to comment.