git ssb

1+

mixmix / scuttle-shell



Commit 6cc6e67e04f36d9fa92b14e5030d73797a24a90b

added API, added Example

andre alves garzia committed on 7/1/2018, 10:38:13 PM
Parent: 3679979ba56d151dcd46c62a817946d0f5ed53fe

Files changed

README.mdchanged
package.jsonchanged
server.jschanged
examples/launch_sbot.jsadded
README.mdView
@@ -17,11 +17,23 @@
1717 ```
1818 $ npm install -g
1919 ```
2020
21-
2221 You can run the app by executing `scuttleshell` on your terminal.
2322
23 +## Using it programmatically
24 +
25 +Right now, there is only one feature exported by the `scuttle-shell` module which is the ability to start a server. Example:
26 +
27 +```
28 +let scuttleshell = require("scuttle-shell")
29 +
30 +console.log("Starting sbot, quitting after 30 seconds")
31 +scuttleshell.start()
32 +
33 +setTimeout(scuttleshell.stop, 30000)
34 +```
35 +
2436 ## Setup
2537
2638 This application is built with [NodeJS](https://nodejs.org). To set it up run:
2739
package.jsonView
@@ -1,8 +1,8 @@
11 {
22 "name": "scuttle-shell",
33 "description": "A system tray app for running Secure Scuttlebutt on your local system",
4- "version": "0.0.2",
4 + "version": "0.0.3",
55 "author": {
66 "name": "Andre Alves Garzia",
77 "email": "andre@andregarzia.com",
88 "url": "http://andregarzia.com"
@@ -11,8 +11,9 @@
1111 "repository": {
1212 "type": "git",
1313 "url": "git://github.com/soapdog/scuttle-shell.git"
1414 },
15 + "main": "./server.js",
1516 "bin": {
1617 "scuttleshell": "./server.js"
1718 },
1819 "dependencies": {
@@ -55,5 +56,5 @@
5556 "eslint-config-standard": "^11.0.0-beta.0"
5657 },
5758 "peerDependencies": {},
5859 "license": "MIT"
59-}
60 +}
server.jsView
@@ -1,96 +1,110 @@
11 #! /usr/bin/env node
22
3-// const http = require('http')
4-// const serve = require('ecstatic')
53 const fs = require('fs')
64 const path = require('path')
75 const ssbKeys = require('ssb-keys')
86 const minimist = require('minimist')
97 const notifier = require('node-notifier')
108 const SysTray = require('systray').default
9 +let tray = {}
1110
12-let argv = process.argv.slice(2)
13-let i = argv.indexOf('--')
14-let conf = argv.slice(i + 1)
15-argv = ~i ? argv.slice(0, i) : argv
11 +function start(appname) {
1612
17-const config = require('ssb-config/inject')(process.env.ssb_appname, minimist(conf))
13 + let argv = process.argv.slice(2)
14 + let i = argv.indexOf('--')
15 + let conf = argv.slice(i + 1)
16 + argv = ~i ? argv.slice(0, i) : argv
17 + let ssb_appname = appname ? appname : process.env.ssb_appname
1818
19-const keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
20-if (keys.curve === 'k256') {
21- throw new Error('k256 curves are no longer supported,' +
22- 'please delete' + path.join(config.path, 'secret'))
23-}
19 + const config = require('ssb-config/inject')(ssb_appname, minimist(conf))
2420
25-const manifestFile = path.join(config.path, 'manifest.json')
21 + const keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
22 + if (keys.curve === 'k256') {
23 + throw new Error('k256 curves are no longer supported,' +
24 + 'please delete' + path.join(config.path, 'secret'))
25 + }
2626
27-const createSbot = require('scuttlebot')
28- // .use(require('scuttlebot/plugins/plugins'))
29- .use(require('scuttlebot/plugins/master'))
30- .use(require('scuttlebot/plugins/gossip'))
31- .use(require('scuttlebot/plugins/replicate'))
32- .use(require('scuttlebot/plugins/invite'))
33- .use(require('scuttlebot/plugins/local'))
34- .use(require('ssb-about'))
35- .use(require('ssb-backlinks'))
36- .use(require('ssb-blobs'))
37- .use(require('ssb-ebt'))
38- .use(require('ssb-chess-db'))
39- .use(require('ssb-friends'))
40- .use(require('ssb-meme'))
41- .use(require('ssb-names'))
42- .use(require('ssb-ooo'))
43- .use(require('ssb-private'))
44- .use(require('ssb-search'))
45- .use(require('ssb-query'))
46- .use(require('ssb-ws'))
27 + const manifestFile = path.join(config.path, 'manifest.json')
4728
48-// start server
29 + const createSbot = require('scuttlebot')
30 + // .use(require('scuttlebot/plugins/plugins'))
31 + .use(require('scuttlebot/plugins/master'))
32 + .use(require('scuttlebot/plugins/gossip'))
33 + .use(require('scuttlebot/plugins/replicate'))
34 + .use(require('scuttlebot/plugins/invite'))
35 + .use(require('scuttlebot/plugins/local'))
36 + .use(require('ssb-about'))
37 + .use(require('ssb-backlinks'))
38 + .use(require('ssb-blobs'))
39 + .use(require('ssb-ebt'))
40 + .use(require('ssb-chess-db'))
41 + .use(require('ssb-friends'))
42 + .use(require('ssb-meme'))
43 + .use(require('ssb-names'))
44 + .use(require('ssb-ooo'))
45 + .use(require('ssb-private'))
46 + .use(require('ssb-search'))
47 + .use(require('ssb-query'))
48 + .use(require('ssb-ws'))
4949
50-config.keys = keys
51-const server = createSbot(config)
50 + // start server
5251
53-// write RPC manifest to ~/.ssb/manifest.json
54-fs.writeFileSync(manifestFile, JSON.stringify(server.getManifest(), null, 2))
52 + config.keys = keys
53 + const server = createSbot(config)
5554
56-const icon = fs.readFileSync(path.join(__dirname, `icon.${process.platform === 'win32' ? 'ico' : 'png'}`))
57-const tray = new SysTray({
58- menu: {
59- icon: icon.toString('base64'),
60- title: 'Scuttle-Shell',
61- tooltip: 'Secure Scuttlebutt',
62- items: [
55 + // write RPC manifest to ~/.ssb/manifest.json
56 + fs.writeFileSync(manifestFile, JSON.stringify(server.getManifest(), null, 2))
6357
64- {
65- title: 'Quit',
66- tooltip: 'Stop sbot and quit tray application',
67- checked: false,
68- enabled: true
69- }
70- ]
71- },
72- debug: false,
73- copyDir: true,
74-})
58 + const icon = fs.readFileSync(path.join(__dirname, `icon.${process.platform === 'win32' ? 'ico' : 'png'}`))
59 + tray = new SysTray({
60 + menu: {
61 + icon: icon.toString('base64'),
62 + title: 'Scuttle-Shell',
63 + tooltip: 'Secure Scuttlebutt',
64 + items: [
7565
76-tray.onClick(action => {
77- switch (action.seq_id) {
78- case 0:
79- console.log("### EXITING IN TWO SECONDS ###")
66 + {
67 + title: 'Quit',
68 + tooltip: 'Stop sbot and quit tray application',
69 + checked: false,
70 + enabled: true
71 + }
72 + ]
73 + },
74 + debug: false,
75 + copyDir: true,
76 + })
8077
81- notifier.notify({
82- title: 'Secure Scuttlebutt',
83- message: `Secure Scuttlebutt will exit in two seconds...`,
84- icon: path.join(__dirname, "icon.png"),
85- wait: true,
86- id: 0,
87- })
78 + tray.onClick(action => {
79 + switch (action.seq_id) {
80 + case 0:
81 + console.log("### EXITING IN TWO SECONDS ###")
8882
89- tray.kill()
90- }
91-})
83 + notifier.notify({
84 + title: 'Secure Scuttlebutt',
85 + message: `Secure Scuttlebutt will exit in two seconds...`,
86 + icon: path.join(__dirname, "icon.png"),
87 + wait: true,
88 + id: 0,
89 + })
9290
93-tray.onExit((code, signal) => {
94- setTimeout(() =>
95- process.exit(0), 2000)
96-})
91 + tray.kill()
92 + }
93 + })
94 +
95 + tray.onExit((code, signal) => {
96 + setTimeout(() =>
97 + process.exit(0), 2000)
98 + })
99 +
100 +}
101 +
102 +function stop() {
103 + tray.kill()
104 +}
105 +
106 +module.exports = { start, stop }
107 +
108 +if (require.main === module) {
109 + var errorLevel = start()
110 +}
examples/launch_sbot.jsView
@@ -1,0 +1,6 @@
1 +let scuttleshell = require("../server")
2 +
3 +console.log("Starting sbot, quitting after 30 seconds")
4 +scuttleshell.start()
5 +
6 +setTimeout(scuttleshell.stop, 30000)

Built with git-ssb-web