chore: moved outgoing message wrapper functions to MessagWrapper.ts
parent
cd122c7252
commit
816f29d682
@ -0,0 +1,41 @@
|
||||
import { SignalService } from '../../protobuf';
|
||||
|
||||
function wrapContentIntoEnvelope(
|
||||
type: SignalService.Envelope.Type,
|
||||
sskSource: string | undefined,
|
||||
timestamp: number,
|
||||
content: Uint8Array
|
||||
): SignalService.Envelope {
|
||||
let source: string | undefined;
|
||||
|
||||
if (type === SignalService.Envelope.Type.CLOSED_GROUP_MESSAGE) {
|
||||
source = sskSource;
|
||||
}
|
||||
|
||||
return SignalService.Envelope.create({
|
||||
type,
|
||||
source,
|
||||
timestamp,
|
||||
content,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* This is an outdated practice and we should probably just send the envelope data directly.
|
||||
* Something to think about in the future.
|
||||
*/
|
||||
function wrapEnvelopeInWebSocketMessage(envelope: SignalService.Envelope): Uint8Array {
|
||||
const request = SignalService.WebSocketRequestMessage.create({
|
||||
id: 0,
|
||||
body: SignalService.Envelope.encode(envelope).finish(),
|
||||
verb: 'PUT',
|
||||
path: '/api/v1/message',
|
||||
});
|
||||
|
||||
const websocket = SignalService.WebSocketMessage.create({
|
||||
type: SignalService.WebSocketMessage.Type.REQUEST,
|
||||
request,
|
||||
});
|
||||
return SignalService.WebSocketMessage.encode(websocket).finish();
|
||||
}
|
||||
|
||||
export const MessageWrapper = { wrapEnvelopeInWebSocketMessage, wrapContentIntoEnvelope };
|
Loading…
Reference in New Issue