view release on metacpan or search on metacpan
examples/chat/js/beekeeper.js view on Meta::CPAN
// Connect to MQTT broker using websockets
this.mqtt = mqtt.connect( args.url, {
username: args.username || 'guest',
password: args.password || 'guest',
clientId: this.client_id,
protocolVersion: 5,
clean: true,
keepalive: 60,
reconnectPeriod: 1000,
connectTimeout: 30 * 1000
});
this.mqtt.on('connect', function (connack) {
This.host = This.mqtt.options.host;
This._debug("Connected to MQTT broker at " + This.host);
This._create_response_topic();
if (args.on_connect) args.on_connect(connack.properties);
});
this.mqtt.on('reconnect', function () {
examples/chat/js/beekeeper.js view on Meta::CPAN
this.pending_req[req_id] = {
method: args.method,
on_success: args.on_success,
on_error: args.on_error,
timeout: null
};
const This = this;
this.pending_req[req_id].timeout = setTimeout( function() {
delete This.pending_req[req_id];
This._debug(`Call to ${args.method} timed out`);
const err_resp = { code: -32603, message: "Request timeout" };
if (args.on_error) {
try { args.on_error(err_resp) }
catch(e) { This._debug(`Uncaught exception into on_error callback of ${args.method}: ${e}`) }
}
else {
This._on_error(err_resp);
}
examples/chat/js/beekeeper.js view on Meta::CPAN
return;
}
// Incoming remote call response
const resp = jsonrpc;
const req = This.pending_req[resp.id];
delete This.pending_req[resp.id];
if (!req) return;
clearTimeout(req.timeout);
if ('result' in resp) {
if (req.on_success) {
try { req.on_success( resp.result, packet_prop ) }
catch(e) { This._debug(`Uncaught exception into on_success callback of ${req.method}: ${e}`) }
}
}
else {
This._debug(`Error response from ${req.method} call: ${resp.error.message}`);
if (req.on_error) {
examples/dashboard/js/dashboard.js view on Meta::CPAN
if (!ui.backend.is_connected()) return;
ui.backend.login( params, function(success) {
if (success) {
ui.overview.init();
ui.services.init();
ui.logs.init();
$('#overview_btn').click();
setTimeout(function() {
$('#auth').hide();
}, 100);
}
else {
$('#auth .login_error').removeClass('hidden');
}
});
}
});
},
examples/dashboard/js/dashboard.js view on Meta::CPAN
// Connect to MQTT broker using websockets
this.mqtt = mqtt.connect( args.url, {
username: args.username || 'guest',
password: args.password || 'guest',
clientId: this.client_id,
protocolVersion: 5,
clean: true,
keepalive: 60,
reconnectPeriod: 1000,
connectTimeout: 30 * 1000
});
this.mqtt.on('connect', function (connack) {
This.host = This.mqtt.options.host;
This._debug("Connected to MQTT broker at " + This.host);
This._create_response_topic();
if (args.on_connect) args.on_connect(connack.properties);
});
this.mqtt.on('reconnect', function () {
examples/dashboard/js/dashboard.js view on Meta::CPAN
this.pending_req[req_id] = {
method: args.method,
on_success: args.on_success,
on_error: args.on_error,
timeout: null
};
const This = this;
this.pending_req[req_id].timeout = setTimeout( function() {
delete This.pending_req[req_id];
This._debug(`Call to ${args.method} timed out`);
const err_resp = { code: -32603, message: "Request timeout" };
if (args.on_error) {
try { args.on_error(err_resp) }
catch(e) { This._debug(`Uncaught exception into on_error callback of ${args.method}: ${e}`) }
}
else {
This._on_error(err_resp);
}
examples/dashboard/js/dashboard.js view on Meta::CPAN
return;
}
// Incoming remote call response
const resp = jsonrpc;
const req = This.pending_req[resp.id];
delete This.pending_req[resp.id];
if (!req) return;
clearTimeout(req.timeout);
if ('result' in resp) {
if (req.on_success) {
try { req.on_success( resp.result, packet_prop ) }
catch(e) { This._debug(`Uncaught exception into on_success callback of ${req.method}: ${e}`) }
}
}
else {
This._debug(`Error response from ${req.method} call: ${resp.error.message}`);
if (req.on_error) {
examples/websocket/js/beekeeper.js view on Meta::CPAN
// Connect to MQTT broker using websockets
this.mqtt = mqtt.connect( args.url, {
username: args.username || 'guest',
password: args.password || 'guest',
clientId: this.client_id,
protocolVersion: 5,
clean: true,
keepalive: 60,
reconnectPeriod: 1000,
connectTimeout: 30 * 1000
});
this.mqtt.on('connect', function (connack) {
This.host = This.mqtt.options.host;
This._debug("Connected to MQTT broker at " + This.host);
This._create_response_topic();
if (args.on_connect) args.on_connect(connack.properties);
});
this.mqtt.on('reconnect', function () {
examples/websocket/js/beekeeper.js view on Meta::CPAN
this.pending_req[req_id] = {
method: args.method,
on_success: args.on_success,
on_error: args.on_error,
timeout: null
};
const This = this;
this.pending_req[req_id].timeout = setTimeout( function() {
delete This.pending_req[req_id];
This._debug(`Call to ${args.method} timed out`);
const err_resp = { code: -32603, message: "Request timeout" };
if (args.on_error) {
try { args.on_error(err_resp) }
catch(e) { This._debug(`Uncaught exception into on_error callback of ${args.method}: ${e}`) }
}
else {
This._on_error(err_resp);
}
examples/websocket/js/beekeeper.js view on Meta::CPAN
return;
}
// Incoming remote call response
const resp = jsonrpc;
const req = This.pending_req[resp.id];
delete This.pending_req[resp.id];
if (!req) return;
clearTimeout(req.timeout);
if ('result' in resp) {
if (req.on_success) {
try { req.on_success( resp.result, packet_prop ) }
catch(e) { This._debug(`Uncaught exception into on_success callback of ${req.method}: ${e}`) }
}
}
else {
This._debug(`Error response from ${req.method} call: ${resp.error.message}`);
if (req.on_error) {
t/lib/Tests/Basic.pm view on Meta::CPAN
# Invalid method
$resp = eval {
$cli->call_remote(
method => 'test.notfound',
);
};
is( $resp, undef );
like( $@, qr/Call to 'test.notfound' failed: -32601 Method not found at /);
# Timeout
$resp = eval {
$cli->call_remote(
method => 'test.sleep',
params => '0.1',
timeout => '0.01',
);
};
is( $resp, undef );
like( $@, qr/Call to 'test.sleep' failed: -31600 Request timeout at /);
t/lib/Tests/Basic.pm view on Meta::CPAN
$cb->send;
}
);
$cb->recv;
isa_ok( $resp, 'Beekeeper::JSONRPC::Error' );
is( $resp->success, 0 );
is( $resp->code, -32000);
is( $resp->message, "error message 821");
# Timeout
eval {
my $req = $cli->call_remote(
method => 'test.sleep',
params => '0.2',
timeout => '0.01',
);
$cli->wait_async_calls;
};