mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
Send outgoing messages as raw bytes (Uint8Array) and moved recipient & ttl to header
This commit is contained in:
parent
6d84eb69e7
commit
6fe70b9b85
3 changed files with 9143 additions and 9145 deletions
|
@ -30,21 +30,18 @@ function initialize({ url }) {
|
|||
|
||||
log.info(options.type, options.url);
|
||||
|
||||
const body = JSON.stringify({
|
||||
pub_key,
|
||||
message: data,
|
||||
ttl,
|
||||
});
|
||||
|
||||
const fetchOptions = {
|
||||
method: options.type,
|
||||
body,
|
||||
headers: { 'X-Loki-Messenger-Agent': 'OWD' },
|
||||
body: data,
|
||||
headers: {
|
||||
'X-Loki-ttl': ttl,
|
||||
'X-Loki-recipient': pub_key,
|
||||
'Content-Length': data.byteLength,
|
||||
},
|
||||
timeout: options.timeout,
|
||||
};
|
||||
|
||||
fetchOptions.headers['Content-Type'] = 'application/json; charset=utf-8';
|
||||
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(options.url, fetchOptions);
|
||||
|
|
|
@ -36121,7 +36121,8 @@ SessionCipher.prototype = {
|
|||
preKeyMsg.signedPreKeyId = session.pendingPreKey.signedKeyId;
|
||||
|
||||
preKeyMsg.message = message;
|
||||
var result = String.fromCharCode((3 << 4) | 3) + util.toString(preKeyMsg.encode());
|
||||
//var result = String.fromCharCode((3 << 4) | 3) + util.toString(preKeyMsg.encode());
|
||||
var result = new Uint8Array(preKeyMsg.encode().buffer);
|
||||
return {
|
||||
type : 3,
|
||||
body : result,
|
||||
|
@ -36131,7 +36132,7 @@ SessionCipher.prototype = {
|
|||
} else {
|
||||
return {
|
||||
type : 1,
|
||||
body : util.toString(message),
|
||||
body : message, //util.toString(message),
|
||||
registrationId : session.registrationId
|
||||
};
|
||||
}
|
||||
|
|
|
@ -150,11 +150,11 @@ OutgoingMessage.prototype = {
|
|||
return promise;
|
||||
},
|
||||
|
||||
async transmitMessage(number, jsonData, timestamp) {
|
||||
async transmitMessage(number, data, timestamp) {
|
||||
const pubKey = number;
|
||||
const ttl = 2 * 24 * 60 * 60;
|
||||
try {
|
||||
const [response, status] = await this.lokiserver.sendMessage(pubKey, JSON.stringify(jsonData), ttl);
|
||||
const [response, status] = await this.lokiserver.sendMessage(pubKey, data, ttl);
|
||||
return response;
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -259,7 +259,7 @@ OutgoingMessage.prototype = {
|
|||
|
||||
return {
|
||||
type : 6, //friend request
|
||||
body : new dcodeIO.ByteBuffer.wrap(ivAndCiphertext).toString('binary'),
|
||||
body : ivAndCiphertext,
|
||||
registrationId : null
|
||||
};
|
||||
}
|
||||
|
@ -280,8 +280,7 @@ OutgoingMessage.prototype = {
|
|||
address: address,
|
||||
destinationDeviceId: address.getDeviceId(),
|
||||
destinationRegistrationId: ciphertext.registrationId,
|
||||
// TODO: simplify the binary -> string -> binary here
|
||||
content: dcodeIO.ByteBuffer.wrap(ciphertext.body,'binary').toArrayBuffer(),
|
||||
content: ciphertext.body,
|
||||
}));
|
||||
})
|
||||
)
|
||||
|
@ -290,7 +289,8 @@ OutgoingMessage.prototype = {
|
|||
outgoingObjects.forEach(outgoingObject => {
|
||||
promises.push(this.wrapInWebsocketMessage(outgoingObject));
|
||||
});
|
||||
const socketMessages = await Promise.all(promises);
|
||||
// TODO: handle multiple devices/messages per transmit
|
||||
const socketMessages = await promises[0];
|
||||
await this.transmitMessage(number, socketMessages, this.timestamp);
|
||||
this.successfulNumbers[this.successfulNumbers.length] = number;
|
||||
this.numberCompleted();
|
||||
|
|
Loading…
Reference in a new issue