dcp-client 4.4.7 → 4.4.9-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,53 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <!-- @file simple-bravojs-worker.html
4
- --
5
- -- Sample web page showing how to implement a trivial DCP worker, using the
6
- -- dcp-client bundle from BravoJS.
7
- --
8
- -- @author Wes Garland, wes@kingsds.network
9
- -- @date Aug 2019
10
- --
11
- -->
12
- <head><meta charset="utf-8">
13
- <script src="../../../bravojs/bravo.js"></script>
14
- <script src="https://scheduler.distributed.computer/etc/dcp-config.js"></script>
15
- <script>
16
- require.paths.unshift('/' + (window.location.hostname + window.location.pathname).replace(/\/examples.*/,'')) /* defines location of bundle */
17
-
18
- module.declare([require.paths[0] + '/dcp-client'], function mainModuleWrapper(require, exports, module) {
19
- let numberOfWorkers = 2
20
- let supervisor
21
-
22
- exports.main = function main() {
23
- let compute = require('dcp/compute')
24
- supervisor = compute.work(numberOfWorkers, 0x1234)
25
- supervisor.on('readystatechange', function(ev) {
26
- console.log('rsc', ev, this)
27
- })
28
- supervisor.on('payment', function(ev) {
29
- console.log('dcc', ev, this)
30
- })
31
- supervisor.on('sandbox', function(sandbox) {
32
- console.log(`Supervisor launched sandbox ${sandbox.serial}`, sandbox)
33
- sandbox.on('ready', function(ev) {
34
- console.log('sandbox ready', ev, this)
35
- })
36
- sandbox.on('taskStart', function(task) {
37
- console.log('START', task)
38
- console.log(`Started task ${task.serial} for job ${task.job.publicName||""} ${task.job.publicDescription||""} ${task.job.publicLink||""}`)
39
- })
40
- sandbox.on('progress', function(ev) {
41
- console.log('progress', ev, this)
42
- })
43
- })
44
- }
45
-
46
- exports.start = function start() {
47
- require('dcp-client').init().then(exports.main)
48
- }
49
- })
50
- </script>
51
- </head>
52
- <body onload="module.main.start()">Simple BravoJS Worker</body>
53
- </html>
@@ -1,174 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
- <title>Client Modals Test</title>
8
- <script src="https://scheduler.distributed.computer/dcp-client/dcp-client.js"></script>
9
-
10
- <style>
11
- body {
12
- font-family: 'Courier New', Courier, monospace;
13
- }
14
- button {
15
- background-color: #1aa473;
16
- color: white;
17
- padding: 10px;
18
- font-size: 20px;
19
- font-weight: bold;
20
- border: none;
21
- }
22
- button:hover {
23
- background-color: #6fc495;
24
- cursor: pointer;
25
- }
26
- .flex {
27
- display: flex;
28
- justify-content: center;
29
- }
30
- #top {
31
- text-align: center;
32
- }
33
- #middle {
34
- margin-top: 50px;
35
- column-gap: 100px;
36
- }
37
- #bottom {
38
- padding: 0 15vw;
39
- }
40
- #bottom p {
41
- flex: 2;
42
- padding-left: 50px;
43
- }
44
- #bottom div {
45
- flex: 1;
46
- }
47
- #unlock-btn {
48
- visibility:hidden;
49
- }
50
- </style>
51
- </head>
52
- <body>
53
- <div id="top">
54
- <h1>Client Modals Test</h1>
55
- <p>Refresh page to restart.</p>
56
- <h2>Flow: <span id="flow-text">Keystore Upload</span></h2>
57
- <button onclick="toggleFlow()">Toggle Flow</button>
58
- </div>
59
- <div id="middle" class="flex">
60
- <div>
61
- <p><strong>This calls wallet.get().</strong></p>
62
- <button onclick="fetchKeystore()">Fetch Keystore</button>
63
- <button id="unlock-btn" onclick="unlockKeystore()">Unlock Keystore</button>
64
- </div>
65
- <div>
66
- <p><strong>This launches a job.</strong></p>
67
- <button onclick="launchJob()">Launch Job</button>
68
- </div>
69
- </div>
70
- <div id="bottom" class="flex">
71
- <p id="keystore-log"></p>
72
- <p id="job-log"></p>
73
- </div>
74
- <script>
75
- let { wallet, compute } = dcp;
76
- // get client modal flow
77
- let isOauth = JSON.parse(localStorage.getItem('env'));
78
- let text = document.getElementById('flow-text');
79
-
80
- // update front-end
81
- if (isOauth)
82
- {
83
- isOauth = isOauth['dcp-wallet-oauth-integration'];
84
- text.innerText = isOauth ? 'OAuth' : 'Keystore Upload';
85
- }
86
- else
87
- {
88
- isOauth = false;
89
- text.innerText = 'Keystore Upload';
90
- }
91
-
92
- // toggle dcp-wallet-oauth-intergration flow
93
- function toggleFlow()
94
- {
95
- if (isOauth)
96
- {
97
- text.innerText = 'Keystore Upload';
98
- localStorage.setItem('env', '{"dcp-wallet-oauth-integration": false}');
99
- }
100
- else
101
- {
102
- text.innerText = 'OAuth';
103
- localStorage.setItem('env', '{"dcp-wallet-oauth-integration": true}');
104
- }
105
-
106
- isOauth = !isOauth;
107
- }
108
-
109
- let keystore;
110
- let log = document.getElementById('keystore-log');
111
-
112
- async function fetchKeystore()
113
- {
114
- try
115
- {
116
- // get keystore
117
- keystore = await wallet.get(); // triggers client modal
118
- log.innerHTML = `Successfully Loaded: <br>${keystore.label} ${keystore.address.address}`;
119
-
120
- let unlockBtn = document.getElementById('unlock-btn');
121
- unlockBtn.style.visibility = 'visible';
122
- }
123
- catch (error)
124
- {
125
- console.error(error);
126
- log.textContent = error.toString();
127
- }
128
- }
129
-
130
- async function unlockKeystore()
131
- {
132
- try
133
- {
134
- // unlock keystore
135
- await keystore.unlock(); // triggers client modal
136
- log.innerHTML += '<br><br>Successfully Unlocked :)';
137
- }
138
- catch (error)
139
- {
140
- console.error(error);
141
- log.textContent = error.toString();
142
- }
143
- }
144
-
145
- async function launchJob()
146
- {
147
- let log = document.getElementById('job-log');
148
- try
149
- {
150
- // create job
151
- let job = compute.for(['success'], (s) => s.toUpperCase());
152
- // update front-end log
153
- job.on('readystatechange', (ev) => {
154
- log.innerHTML += `<br>${ev}`;
155
- });
156
- job.on('result', (ev) => {
157
- log.innerHTML += `<br>${ev}`;
158
- })
159
- job.on('error', (ev) => {
160
- throw new Error(ev);
161
- })
162
- // exec
163
- let res = await job.exec(); // triggers client modal
164
- log.innerHTML += `<br><br>Job finished successfully :)`;
165
- }
166
- catch (error)
167
- {
168
- console.error(error);
169
- log.textContent = error.toString();
170
- }
171
- }
172
- </script>
173
- </body>
174
- </html>
@@ -1,29 +0,0 @@
1
- /** @file events.css
2
- * Support for events.html
3
- * @author Wes Garland, wes@kingsds.network
4
- * @date Aug 2019
5
- */
6
- HTML, BODY {
7
- font-family: Arial, Helvetica;
8
- font-size: 16px;
9
- }
10
-
11
- DIV#pretty {
12
- border: 1px solid #333;
13
- width: 30em;
14
- height: 30em;
15
- display: flex;
16
- margin: auto;
17
- top: 1em;
18
- right: 1em;
19
- background: white;
20
- }
21
-
22
- DIV#pretty > DIV {
23
- color: white;
24
- position: absolute;
25
- top: 50%;
26
- left: 50%;
27
- transform: translate(-50%, -50%);
28
- }
29
-
@@ -1,94 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <!-- @file events.html
4
- -
5
- - Sample web page showing how to deploy a DCP job whilst receiving
6
- - events describing the current state of the job, processing results
7
- - as they are received, and so on.
8
- -
9
- - https://jsfiddle.net/KingsDistributedSystems/58e6up4b/
10
- -
11
- - @author Wes Garland, wes@kingsds.network
12
- - @date Aug 2019, April 2020
13
- -
14
- -->
15
- <head version='1c1e62d32e1b6da4ced32b7d0e7ff9180abc21fb'><meta charset="utf-8">
16
- <link rel="stylesheet" type="text/css" href="./events.css">
17
- <script src="https://scheduler.distributed.computer/dcp-client/dcp-client.js"></script>
18
- <script>
19
- async function start() {
20
- const { compute } = dcp;
21
- let job, results, startTime;
22
-
23
- let el = document.getElementById('eventList');
24
- let pretty = document.getElementById('pretty');
25
-
26
- job = compute.for(["red", "green", "yellow", "blue", "brown", "orange", "pink"],
27
- function(colour) {
28
- progress(0);
29
- let sum = 0;
30
- for (let i =0; i < 10000000; i++) {
31
- sum += Math.random();
32
- progress(i/10000000);
33
- }
34
- return colour;
35
- }
36
- )
37
-
38
- job.on('accepted',
39
- function(ev) {
40
- console.log(`job ${this.id} accepted by scheduler`);
41
- el.innerHTML += `<li>Job accepted by scheduler, waiting for results</li>`;
42
- el.innerHTML += `<li>Job has id <tt>${this.id}</tt></li>`;
43
- startTime = Date.now();
44
- }
45
- )
46
-
47
- job.on('complete',
48
- function(ev) {
49
- console.log('job finished running', ev);
50
- el.innerHTML += `<li>Job Finished, total runtime = ${Math.round((Date.now() - startTime) / 100)/10}s </li>`;
51
- pretty.style.backgroundColor = '';
52
- }
53
- )
54
-
55
- job.on('readystatechange',
56
- function(arg) {
57
- if (this.id)
58
- console.log(`job ${this.id} entered ready state ${arg}; is currently in ready state ${this.readyState}`);
59
- else
60
- console.log(`new job entered ready state ${arg}; is currently in ready state ${this.readyState}`);
61
- rsl.innerHTML += '<li>' + arg + '</li>';
62
- }
63
- )
64
-
65
- job.on('result',
66
- function(ev) {
67
- el.innerHTML += `<li>Received result for slice ${ev.sliceNumber} at ${Math.round((Date.now() - startTime) / 100)/10}s </li>`;
68
- pretty.style.backgroundColor = ev.result;
69
- console.log('received result', ev);
70
- }
71
- )
72
-
73
- job.public = {
74
- name: 'events example, vanilla-web',
75
- description: 'dcp-client sample code examples/vanilla-web/events.html',
76
- link: 'https://www.npmjs.com/package/dcp-client'
77
- }
78
-
79
- el.innerHTML += '<li>Executing job<ul id="readyStateList"></ul></li>';
80
- rsl = document.getElementById('readyStateList');
81
- await job.exec(compute.marketValue);
82
- }
83
- </script>
84
- </head>
85
- <body onload="start()">
86
- <h2>This is a vanilla web dcp-client example which uses events.</h2>
87
- <div style="width: 100%;">
88
- <div id="pretty"><div>ooooh, pretty!</div></div>
89
- </div>
90
- <div id="eventDiv">
91
- <ul id="eventList"></ul>
92
- </div>
93
- </body>
94
- </html>
@@ -1,42 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <!-- @file minimal.html
4
- --
5
- -- Sample web page showing how to deploy a minimal DCP job.
6
- --
7
- -- https://jsfiddle.net/KingsDistributedSystems/9dbtycpn/
8
- --
9
- -- @author Wes Garland, wes@kingsds.network
10
- -- @date Aug 2019, April 2020
11
- --
12
- -->
13
- <head version='1c1e62d32e1b6da4ced32b7d0e7ff9180abc21fb'><meta charset="utf-8">
14
- <script src="https://scheduler.distributed.computer/dcp-client/dcp-client.js"></script>
15
- <script>
16
- async function start() {
17
- const { compute } = dcp;
18
- let job = compute.for(1, 10,
19
- function(i) {
20
- progress(0);
21
- let sum = 0;
22
- for (let i =0; i < 10000000; i++) {
23
- sum += Math.random();
24
- progress(i/10000000);
25
- }
26
- return i*3
27
- }
28
- )
29
-
30
- job.on('result',function(ev) {
31
- console.log('received result', ev.result);
32
- })
33
-
34
- job.public.name = 'minimal example, vanilla-web';
35
- await job.exec(compute.marketValue);
36
- }
37
- </script>
38
- </head>
39
- <body onload="start()">
40
- This is a minimal vanilla web dcp-client example. Look in your browser's console for output.
41
- </body>
42
- </html>