Skip to content
Permalink
Browse files
Merge pull request #9867 from storybookjs/websocket-cyclic-support
Core: Use telejson for websockets channel
  • Loading branch information
shilman committed Feb 25, 2020
1 parent 57dd1e0 commit 7ab4626597bd25bd432e81dfb786a5090ba81cde
Showing with 5 additions and 10 deletions.
  1. +1 −1 lib/channel-websocket/package.json
  2. +4 −4 lib/channel-websocket/src/index.ts
  3. +0 −5 yarn.lock
@@ -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"
@@ -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;

@@ -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);
}

@@ -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 => {
@@ -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"

0 comments on commit 7ab4626

Please sign in to comment.