Compare commits
2 Commits
13cb96af14
...
1efec85494
Author | SHA1 | Date | |
---|---|---|---|
|
1efec85494 | ||
|
9a53fceaee |
22
sshChat.mjs
22
sshChat.mjs
@ -18,7 +18,7 @@ goodbye(() => swarm.destroy())
|
||||
const conns = []
|
||||
let USERPWD = "/"
|
||||
let DAPI_KEY = {}
|
||||
let USERNAME = "annon" + rand
|
||||
let USERNAME = "anon" + rand
|
||||
let LOGGEDIN = false
|
||||
|
||||
async function clearCursor() {
|
||||
@ -105,6 +105,10 @@ swarm.on('connection', conn => {
|
||||
})
|
||||
})
|
||||
|
||||
swarm.on('error', (err) => {
|
||||
console.log('Error connecting to peer:', err);
|
||||
});
|
||||
|
||||
// Use readline to accept input from the user
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
@ -145,6 +149,8 @@ rl.on('line', input => {
|
||||
}
|
||||
|
||||
const execute = input.startsWith(">")
|
||||
if (input.startsWith("/") || input.startsWith("!")) return
|
||||
|
||||
if (execute) {
|
||||
let inputdata = input.split(2)
|
||||
const cmdToRun = inputdata.join(" ").replace("> ", "").replace(">", "")
|
||||
@ -169,7 +175,6 @@ rl.on('line', input => {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const start = input.startsWith("/start")
|
||||
if (start) {
|
||||
startContainer(DAPI_KEY.key).then((data) => {
|
||||
@ -224,11 +229,20 @@ rl.on('line', input => {
|
||||
|
||||
// Join a common topic
|
||||
const topic = process.argv[2] ? b4a.from(process.argv[2], 'hex') : crypto.randomBytes(32)
|
||||
const discovery = swarm.join(topic, { client: true, server: true })
|
||||
|
||||
// The flushed promise will resolve when the topic has been fully announced to the DHT
|
||||
setTimeout(() => {
|
||||
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(() => {
|
||||
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('Want to login to the SSH.SURF API? Type "/login [APIKEY]" to login.\n\n')
|
||||
})
|
||||
}, 3000);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user