Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
///
///
import Wampy from 'wampy';
var ws = new Wampy('http://wamp.router.url', {realm: 'WAMPRealm'});
ws.options();
ws.options({
reconnectInterval: 1000,
maxRetries: 999,
onConnect: function () { console.log('Yahoo! We are online!'); },
onClose: function () { console.log('See you next time!'); },
onError: function () { console.log('Breakdown happened'); },
onReconnect: function () { console.log('Reconnecting...'); },
onReconnectSuccess: function () { console.log('Successfully reconnected!'); }
});
ws.connect();
ws.connect('/my-socket-path');
ws.connect('wss://socket.server.com:5000/ws');
url.protocol = 'ws:';
function RPCWrapper (handler) {
return (args) => [{}, handler(...args)];
}
// XXX: This is nasty. Happily it's also temporary.
let unblock;
const wait = new Promise(resolve => {
unblock = () => resolve(true);
});
export function waitFor() {
return wait;
}
const client = new Wampy(url.href, {
realm: 'realm1',
onConnect: () => {
Promise.all([
registerMock('alive', () => true),
// Register other mock rpcs.
registerMock('struct.page', pageFetcher),
registerMock('data.values.load', valueFetcher),
registerMock('data.values.save', valuePutter),
registerMock('provider.components.list', getFunctions),
registerMock('provider.components.pick', pickFunction),
registerMock('struct.dialog.cancel', dialogName =>
console.log('Canceling and closing', dialogName) // eslint-disable-line no-console
),
]).then(unblock);
}
});
function connect() {
let connection = new Wampy(config.WS_URL,
{
realm: config.REALM,
autoReconnect: true,
transportEncoding: 'msgpack',
msgpackCoder: new MsgpackSerializer(),
onConnect: () => {
console.log('WS: connected');
resolve({
connection
});
},
onClose: () => {
console.log('WS: connection closed');
},
onError: (err, details) => {
return new Promise((resolve, reject) => {
let url = new URL(getBaseUrl() + '/Composite/api/Router', location.href);
url.protocol = url.protocol.replace('http', 'ws');
const client = new Wampy(url.href, {
realm,
onConnect: () => {
currentClients[realm] = client;
resolve(client);
},
onError: err => reject(err)
});
});
}