Compare commits
2 Commits
13cb96af14
...
1efec85494
Author | SHA1 | Date | |
---|---|---|---|
|
1efec85494 | ||
|
9a53fceaee |
20
sshChat.mjs
20
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 = "annon" + rand
|
let USERNAME = "anon" + rand
|
||||||
let LOGGEDIN = false
|
let LOGGEDIN = false
|
||||||
|
|
||||||
async function clearCursor() {
|
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
|
// Use readline to accept input from the user
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
@ -145,6 +149,8 @@ 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(">", "")
|
||||||
@ -169,7 +175,6 @@ 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) => {
|
||||||
@ -224,7 +229,13 @@ 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(() => {
|
||||||
|
const discovery = swarm.join(topic, {
|
||||||
|
lookup: true,
|
||||||
|
announce: true
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
// The flushed promise will resolve when the topic has been fully announced to the DHT
|
// The flushed promise will resolve when the topic has been fully announced to the DHT
|
||||||
discovery.flushed().then(() => {
|
discovery.flushed().then(() => {
|
||||||
@ -232,3 +243,6 @@ discovery.flushed().then(() => {
|
|||||||
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