Skip to content
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

Core: Use telejson for websockets channel #9867

Merged
merged 2 commits into from Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/channel-websocket/package.json
Expand Up @@ -30,7 +30,7 @@
"@storybook/channels": "6.0.0-alpha.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