relita

an encrypted, decentralized, peer-to-peer social network
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/relita

commit 69cf6c596bb80b3ef95b97154ca0a926bef955b8
parent 659fc8588ea7ad6600f0e0c7713180a780b1ad29
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun,  9 Apr 2017 18:03:08 +0200

Add(Scuttlebot): Add server creation on start

Diffstat:
Mmain.js | 79++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
Mpackage.json | 10+++++++++-
2 files changed, 65 insertions(+), 24 deletions(-)

diff --git a/main.js b/main.js @@ -1,38 +1,71 @@ -const electron = require('electron') -const app = electron.app -const BrowserWindow = electron.BrowserWindow +const electron = require('electron') +const app = electron.app +const BrowserWindow = electron.BrowserWindow -const path = require('path') -const url = require('url') -const sbot = require('scuttlebot') +const path = require('path') +const url = require('url') +const fs = require('fs') +const ssbKeys = require('ssb-keys') +const config = require('ssb-config/inject')(process.env.ssb_appname) +const keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret')) +const sbot = require('scuttlebot') + .use(require('scuttlebot/plugins/master')) + .use(require('scuttlebot/plugins/gossip')) + .use(require('scuttlebot/plugins/friends')) + .use(require('scuttlebot/plugins/replicate')) + .use(require('ssb-blobs')) + .use(require('scuttlebot/plugins/invite')) + .use(require('scuttlebot/plugins/block')) + .use(require('scuttlebot/plugins/local')) + .use(require('scuttlebot/plugins/logging')) + +const default_port = 6666; +const default_name = "Relita" let mainWindow -function createWindow () { - mainWindow = new BrowserWindow({width: 800, height: 600}) +function launch_sbot_server() { + config.keys = keys + manifestFile = path.join(config.path, 'manifest.json') + config.port = default_port; + + var server = sbot(config) + // write RPC manifest to ~/.ssb/manifest.json + fs.writeFileSync(manifestFile, JSON.stringify(server.getManifest(), null, 2)) + console.log("Scuttlebot server created !") +} + +function create_window() { + /* Create the scuttlebot server */ + launch_sbot_server(); - mainWindow.loadURL(url.format({ - pathname: path.join(__dirname, 'index.html'), - protocol: 'file:', - slashes: true - })) + mainWindow = new BrowserWindow({ + width: 800, + height: 600, + title: default_name + }) + mainWindow.loadURL(url.format({ + pathname: path.join(__dirname, 'index.html'), + protocol: 'file:', + slashes: true + })) - mainWindow.on('closed', function () { - mainWindow = null - }) + mainWindow.on('closed', function () { + mainWindow = null + }) } -app.on('ready', createWindow) +app.on('ready', create_window) app.on('window-all-closed', function () { - if (process.platform !== 'darwin') { - app.quit() - } + if (process.platform !== 'darwin') { + app.quit() + } }) app.on('activate', function () { - if (mainWindow === null) { - createWindow() - } + if (mainWindow === null) { + create_window(); + } }) diff --git a/package.json b/package.json @@ -12,7 +12,15 @@ "author": "Ne02ptzero", "license": "GPL", "dependencies": { - "scuttlebot": "github:ssbc/scuttlebot#a53ebda4b34c959188ff6de955f55a348fe47251" + "scuttlebot": "github:ssbc/scuttlebot#a53ebda4b34c959188ff6de955f55a348fe47251", + "ssb-avatar": "^0.2.0", + "ssb-blobs": "~0.1.7", + "ssb-keys": "~7.0.0", + "ssb-mentions": "^0.1.1", + "ssb-msgs": "^5.2.0", + "ssb-query": "~0.1.1", + "ssb-ref": "~2.6.2", + "ssb-sort": "^1.0.0" }, "devDependencies": { "electron": "~1.6.2",