Skip to content

Commit cef8582

Browse files
committed
Refactor beam msg, remove rtc message for now
1 parent 0cfdcb8 commit cef8582

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

src/backend/beam.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const beam_event = (beam, chat, key) => {
133133
if (str === "Ping") return
134134
if (check_data_message(str, addr)) return
135135
let hash = str.substring(0,64)
136-
decrpyt_beam_message(str, msgKey)
136+
decrpyt_beam_message(str.substring(64), msgKey)
137137
})
138138

139139
beam.on('end', () => {

src/backend/messages.cjs

+2-9
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ const peer_dms = async () => {
208208
const contacts = await getConversations()
209209
for (const c of contacts) {
210210
const hashDerivation = await key_derivation_hash(c.chat)
211+
console.log("hashDerivation", hashDerivation)
211212
const beam = await new_beam(hashDerivation, c.chat + c.key, false)
212213
if (beam === "Error") continue
213214
if (!beam) continue
@@ -627,18 +628,10 @@ async function send_message(message, receiver, off_chain = false, group = false,
627628
//Offchain messages
628629
let random_key = randomKey()
629630
let sentMsg = Buffer.from(payload_hex, 'hex')
630-
let sendMsg = random_key + '99' + sentMsg
631-
let messageArray = []
632-
messageArray.push(sendMsg)
633-
messageArray.push(address)
634-
if (group) {
635-
messageArray.push('group')
636-
}
631+
let sendMsg = random_key + sentMsg
637632
if (beam_this) {
638633
send_beam_message(sendMsg, address, timestamp)
639634
return
640-
} else {
641-
Hugin.send('rtc_message', [messageArray])
642635
}
643636
//Do not save invite message.
644637
if (message.msg && 'invite' in message.msg) {

src/backend/swarm.cjs

+5-10
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,20 @@ const new_connection = (connection, topic, dht_keys, peer) => {
233233

234234
connection.on('error', () => {
235235
console.log("Got error connection signal")
236-
connection_closed(connection, topic)
236+
connection_closed(connection, topic, true)
237237
})
238238

239239
}
240240

241-
const connection_closed = (conn, topic) => {
241+
const connection_closed = (conn, topic, error = false) => {
242242
console.log("Closing connection...")
243243
const active = get_active_topic(topic)
244244
if (!active) return
245245
try {
246-
conn.end()
247-
conn.destroy()
246+
conn.end();
247+
conn.destroy();
248248
} catch (e) {
249-
console.log("failed close connection")
249+
console.log('failed close connection');
250250
}
251251
const user = active.connections.find(a => a.connection === conn)
252252
if (!user) return
@@ -337,11 +337,6 @@ const check_data_message = async (data, connection, topic, peer) => {
337337
return "Ban"
338338
}
339339

340-
if (con.joined) {
341-
//Connection is already joined
342-
return true
343-
}
344-
345340
if (Hugin.banned(data.address, topic)) {
346341
if (active.admin) admin_ban_user(data.address, active.key)
347342
else ban_user(data.address, topic)

0 commit comments

Comments
 (0)