You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
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 };
|