mirror of
https://github.com/gundb/panic-server.git
synced 2026-01-15 00:08:05 -05:00
Exposed a function named "test" that takes an options object, with things like how many gun requests to fire in total, what data to send, where to put it, what peers to connect to, etc... Exposed a Browser constructor that opens up a new window and runs the test function with the options provided, returning an interface to the window. Added a patch function to validate the option input and provide defaults where there aren't any values.
38 lines
649 B
JavaScript
38 lines
649 B
JavaScript
/*globals Gun*/
|
|
/*
|
|
Expect an object like this:
|
|
|
|
|
|
var thing = {
|
|
interval: Number,
|
|
peers: Array,
|
|
amount: Number,
|
|
id: String,
|
|
key: String,
|
|
path: String,
|
|
data: *
|
|
};
|
|
|
|
*/
|
|
|
|
function patch(opt) {
|
|
'use strict';
|
|
if (!opt) {
|
|
throw new Error('No options provided');
|
|
}
|
|
if (!opt.id) {
|
|
throw new Error('No ID given');
|
|
}
|
|
var url = location.protocol + '//';
|
|
url += location.host;
|
|
url += '/gun';
|
|
|
|
opt.key = opt.key || 'panic/test/';
|
|
opt.interval = opt.interval || 20;
|
|
opt.peers = opt.peers || [url];
|
|
opt.amount = opt.amount || 1000;
|
|
opt.path = opt.path || Gun.text.random();
|
|
opt.data = opt.data || Gun.text.random();
|
|
return opt;
|
|
}
|