signal-desktop/libtextsecure/protobufs.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-07-21 21:51:20 +00:00
/* global window, dcodeIO, textsecure */
// eslint-disable-next-line func-names
2018-05-02 16:51:22 +00:00
(function() {
window.textsecure = window.textsecure || {};
window.textsecure.protobuf = {};
2018-05-02 16:51:22 +00:00
function loadProtoBufs(filename) {
return dcodeIO.ProtoBuf.loadProtoFile(
{ root: window.PROTO_ROOT, file: filename },
2018-07-21 21:51:20 +00:00
(error, result) => {
2018-05-02 16:51:22 +00:00
if (error) {
2018-07-21 21:51:20 +00:00
const text = `Error loading protos from ${filename} (root: ${
window.PROTO_ROOT
}) ${error && error.stack ? error.stack : error}`;
window.log.error(text);
2018-05-02 16:51:22 +00:00
throw error;
}
2018-07-21 21:51:20 +00:00
const protos = result.build('signalservice');
2018-05-02 16:51:22 +00:00
if (!protos) {
2020-01-08 17:44:54 +00:00
const text = `Error loading protos from ${filename} (root: ${window.PROTO_ROOT})`;
window.log.error(text);
2018-05-02 16:51:22 +00:00
throw new Error(text);
}
2018-07-21 21:51:20 +00:00
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const protoName in protos) {
2018-05-02 16:51:22 +00:00
textsecure.protobuf[protoName] = protos[protoName];
}
}
);
}
2018-05-02 16:51:22 +00:00
loadProtoBufs('SignalService.proto');
loadProtoBufs('SubProtocol.proto');
loadProtoBufs('DeviceMessages.proto');
loadProtoBufs('Stickers.proto');
// Just for encrypting device names
loadProtoBufs('DeviceName.proto');
// Metadata-specific protos
loadProtoBufs('UnidentifiedDelivery.proto');
})();