Skip to content

Commit

Permalink
Merge pull request #9867 from storybookjs/websocket-cyclic-support
Browse files Browse the repository at this point in the history
Core: Use telejson for websockets channel
  • Loading branch information
shilman committed Feb 25, 2020
1 parent 57dd1e0 commit 7ab4626
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/channel-websocket/package.json
Expand Up @@ -31,7 +31,7 @@
"@storybook/channels": "5.3.13",
"core-js": "^3.0.1",
"global": "^4.3.2",
"json-fn": "^1.1.1"
"telejson": "^3.2.0"
},
"publishConfig": {
"access": "public"
Expand Down
8 changes: 4 additions & 4 deletions lib/channel-websocket/src/index.ts
@@ -1,6 +1,6 @@
import { WebSocket } from 'global';
import JSON from 'json-fn';
import { Channel, ChannelHandler } from '@storybook/channels';
import { isJSON, parse, stringify } from 'telejson';

type OnError = (message: Event) => void;

Expand Down Expand Up @@ -45,7 +45,7 @@ export class WebsocketTransport {
}

private sendNow(event: any) {
const data = JSON.stringify(event);
const data = stringify(event, { maxDepth: 15, allowFunction: true });
this.socket.send(data);
}

Expand All @@ -61,8 +61,8 @@ export class WebsocketTransport {
this.isReady = true;
this.flush();
};
this.socket.onmessage = e => {
const event = JSON.parse(e.data);
this.socket.onmessage = ({ data }) => {
const event = typeof data === 'string' && isJSON(data) ? parse(data) : data;
this.handler(event);
};
this.socket.onerror = e => {
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Expand Up @@ -19828,11 +19828,6 @@ json-buffer@3.0.0:
resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.0.tgz#5b1f397afc75d677bde8bcfc0e47e1f9a3d9a898"
integrity sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=

json-fn@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/json-fn/-/json-fn-1.1.1.tgz#4293c9198a482d6697d334a6e32cd0d221121e80"
integrity sha1-QpPJGYpILWaX0zSm4yzQ0iESHoA=

json-parse-better-errors@^1.0.0, json-parse-better-errors@^1.0.1, json-parse-better-errors@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
Expand Down

0 comments on commit 7ab4626

Please sign in to comment.