Compare commits
No commits in common. "1efec854943ec285617431ad0683512b9fbcaa10" and "13cb96af14b0350336f2de30e4a5b310ba8e9d54" have entirely different histories.
1efec85494
...
13cb96af14
22
sshChat.mjs
22
sshChat.mjs
@ -18,7 +18,7 @@ goodbye(() => swarm.destroy())
|
|||||||
const conns = []
|
const conns = []
|
||||||
let USERPWD = "/"
|
let USERPWD = "/"
|
||||||
let DAPI_KEY = {}
|
let DAPI_KEY = {}
|
||||||
let USERNAME = "anon" + rand
|
let USERNAME = "annon" + rand
|
||||||
let LOGGEDIN = false
|
let LOGGEDIN = false
|
||||||
|
|
||||||
async function clearCursor() {
|
async function clearCursor() {
|
||||||
@ -105,10 +105,6 @@ swarm.on('connection', conn => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
swarm.on('error', (err) => {
|
|
||||||
console.log('Error connecting to peer:', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Use readline to accept input from the user
|
// Use readline to accept input from the user
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
@ -149,8 +145,6 @@ rl.on('line', input => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const execute = input.startsWith(">")
|
const execute = input.startsWith(">")
|
||||||
if (input.startsWith("/") || input.startsWith("!")) return
|
|
||||||
|
|
||||||
if (execute) {
|
if (execute) {
|
||||||
let inputdata = input.split(2)
|
let inputdata = input.split(2)
|
||||||
const cmdToRun = inputdata.join(" ").replace("> ", "").replace(">", "")
|
const cmdToRun = inputdata.join(" ").replace("> ", "").replace(">", "")
|
||||||
@ -175,6 +169,7 @@ rl.on('line', input => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const start = input.startsWith("/start")
|
const start = input.startsWith("/start")
|
||||||
if (start) {
|
if (start) {
|
||||||
startContainer(DAPI_KEY.key).then((data) => {
|
startContainer(DAPI_KEY.key).then((data) => {
|
||||||
@ -229,20 +224,11 @@ rl.on('line', input => {
|
|||||||
|
|
||||||
// Join a common topic
|
// Join a common topic
|
||||||
const topic = process.argv[2] ? b4a.from(process.argv[2], 'hex') : crypto.randomBytes(32)
|
const topic = process.argv[2] ? b4a.from(process.argv[2], 'hex') : crypto.randomBytes(32)
|
||||||
|
const discovery = swarm.join(topic, { client: true, server: true })
|
||||||
|
|
||||||
setTimeout(() => {
|
// The flushed promise will resolve when the topic has been fully announced to the DHT
|
||||||
const discovery = swarm.join(topic, {
|
|
||||||
lookup: true,
|
|
||||||
announce: true
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// The flushed promise will resolve when the topic has been fully announced to the DHT
|
|
||||||
discovery.flushed().then(() => {
|
discovery.flushed().then(() => {
|
||||||
console.log(`joined topic: ${b4a.toString(topic, 'hex')}\n(Share this key to others so they may join.)`)
|
console.log(`joined topic: ${b4a.toString(topic, 'hex')}\n(Share this key to others so they may join.)`)
|
||||||
console.log('You are now in a chatroom for your topic, feel free to chat.\n')
|
console.log('You are now in a chatroom for your topic, feel free to chat.\n')
|
||||||
console.log('Want to login to the SSH.SURF API? Type "/login [APIKEY]" to login.\n\n')
|
console.log('Want to login to the SSH.SURF API? Type "/login [APIKEY]" to login.\n\n')
|
||||||
})
|
})
|
||||||
}, 3000);
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user