Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint-disable */
import { configure, setAddon } from '@storybook/react'
import { setOptions } from '@storybook/addon-options'
import JSXAddon from 'storybook-addon-jsx'
import params from '../params'
if (
typeof window === 'object' &&
window.navigator &&
/node\.js/i.test(window.navigator.userAgent)
) {
var addons = require('@storybook/addons').default
var Channel = require('@storybook/channels').default
addons.setChannel(
new Channel({
transport: {
setHandler: function() {},
send: function() {},
},
})
)
}
setOptions({
downPanelInRight: true,
hierarchySeparator: /\./,
name: params.projectName,
url: params.projectUrl,
})
setAddon(JSXAddon)
this._asyncStorage = params.asyncStorage;
}
const onDeviceUI = params.onDeviceUI !== false;
const { initialSelection, shouldPersistSelection } = params;
try {
channel = addons.getChannel();
} catch (e) {
// getChannel throws if the channel is not defined,
// which is fine in this case (we will define it below)
}
if (!channel || params.resetStorybook) {
if (onDeviceUI && params.disableWebsockets) {
channel = new Channel({ async: true });
this._setInitialStory(initialSelection, shouldPersistSelection);
} else {
const host = getHost(params.host || 'localhost');
const port = `:${params.port || 7007}`;
const query = params.query || '';
const { secured } = params;
const websocketType = secured ? 'wss' : 'ws';
const httpType = secured ? 'https' : 'http';
const url = `${websocketType}://${host}${port}/${query}`;
webUrl = `${httpType}://${host}${port}`;
channel = createChannel({
url,
async: onDeviceUI,
onError: () => {
export default function createChannel({ page }: Config): Channel {
const transport = new PostmsgTransport({ page });
return new Channel({ transport });
}
export function mockChannel() {
const transport = {
setHandler: () => {},
send: () => {},
};
return new Channel({ transport });
}
export default function createChannel({ url, async, onError }: CreateChannelArgs) {
const transport = new WebsocketTransport({ url, onError });
return new Channel({ transport, async });
}