-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
140 lines (132 loc) · 3.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
var _ = require('lodash');
const ssbClient = require('ssb-client')
const ssbKeys = require('ssb-keys')
const default_settings = {
manifest:
{
auth: 'async',
address: 'sync',
manifest: 'sync',
multiserver: { parse: 'sync', address: 'sync' },
multiserverNet: {},
get: 'async',
createFeedStream: 'source',
createLogStream: 'source',
messagesByType: 'source',
createHistoryStream: 'source',
createUserStream: 'source',
createWriteStream: 'sink',
links: 'source',
add: 'async',
publish: 'async',
getAddress: 'sync',
getLatest: 'async',
latest: 'source',
latestSequence: 'async',
whoami: 'sync',
progress: 'sync',
status: 'sync',
getVectorClock: 'async',
version: 'sync',
seq: 'async',
usage: 'sync',
clock: 'async',
plugins:
{ install: 'source',
uninstall: 'source',
enable: 'async',
disable: 'async' },
gossip:
{ add: 'sync',
remove: 'sync',
connect: 'async',
disconnect: 'async',
changes: 'source',
reconnect: 'sync',
disable: 'sync',
enable: 'sync',
ping: 'duplex',
get: 'sync',
peers: 'sync' },
replicate:
{ changes: 'source',
upto: 'source',
request: 'sync',
block: 'sync' },
friends:
{ hopStream: 'source',
onEdge: 'sync',
isFollowing: 'async',
isBlocking: 'async',
hops: 'async',
help: 'sync',
get: 'async',
createFriendStream: 'source',
stream: 'source' },
backlinks: { read: 'source' },
query: { read: 'source', explain: 'sync' },
blobs:
{ get: 'source',
getSlice: 'source',
add: 'sink',
rm: 'async',
ls: 'source',
has: 'async',
size: 'async',
meta: 'async',
want: 'async',
push: 'async',
changes: 'source',
createWants: 'source' },
links2: { read: 'source' },
ws: {},
ebt:
{ replicate: 'duplex',
request: 'sync',
block: 'sync',
peerStatus: 'sync' },
ooo: { stream: 'duplex', get: 'async' }
},
caps: {
shs: '1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=' // main ssb network
}
}
export default {
install (Vue, options) {
const settings_with_defaults = _.merge( default_settings, options )
// Hosts to attempt to connect to
var possible_remotes = [ settings_with_defaults.remote ]
// var possible_remotes = [ "ws://192.168.0.109:8989~shs:5NWaVfaBIWV9fnXuI8xx+mVRf19m8XlCZkeMwxPyilk=", settings_with_defaults.remote ]
var keys = {}
// Generate keys if they are missing
keys = ssbKeys.loadOrCreateSync("keys")
Vue.prototype.$ssb = new Promise((resolve, reject) => {
// Try each remote in turn
for (var i = possible_remotes.length - 1; i >= 0; i--) {
var remote = possible_remotes[i]
settings_with_defaults.remote = remote
ssbClient(keys, settings_with_defaults, (err, ssb_inst) => {
if(err)
{
if(err.message === "could not connect to sbot")
{
// do nothing, try next
console.log("unable to connect sbot at: ", remote)
}
else
{
console.log("Connected, but found some other error: ", err)
// throw(err)
}
}
else
{
console.log("<<Connected>> to:", remote)
resolve(ssb_inst)
// break
}
})
}
})
}
}