Use websocket for all chat service requests
This commit is contained in:
parent
fbf39a36fb
commit
b517bb817f
6 changed files with 24 additions and 71 deletions
8
package-lock.json
generated
8
package-lock.json
generated
|
@ -127,7 +127,7 @@
|
|||
"@indutny/rezip-electron": "1.3.2",
|
||||
"@indutny/symbolicate-mac": "2.3.0",
|
||||
"@napi-rs/canvas": "0.1.58",
|
||||
"@signalapp/mock-server": "9.0.2",
|
||||
"@signalapp/mock-server": "9.1.0",
|
||||
"@storybook/addon-a11y": "8.1.11",
|
||||
"@storybook/addon-actions": "8.1.11",
|
||||
"@storybook/addon-controls": "8.1.11",
|
||||
|
@ -7481,9 +7481,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@signalapp/mock-server": {
|
||||
"version": "9.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@signalapp/mock-server/-/mock-server-9.0.2.tgz",
|
||||
"integrity": "sha512-QMfzA4mOZi1wagq6uGLEGDdbawyr9VG8ASAofbA/+HYDNE9n/12kzwuUs2fGpIRfs+86LDw/3iYF9ONfRDFxGQ==",
|
||||
"version": "9.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@signalapp/mock-server/-/mock-server-9.1.0.tgz",
|
||||
"integrity": "sha512-wv1Ze6qa2Eb3GgW+HgRLaI9y+HLskCZ0ORB0i5M5MKB91iLYpxY+WBscoQsflDK/cCcuBS1UfkC8PllVeo7MOQ==",
|
||||
"dev": true,
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
|
|
|
@ -214,7 +214,7 @@
|
|||
"@indutny/rezip-electron": "1.3.2",
|
||||
"@indutny/symbolicate-mac": "2.3.0",
|
||||
"@napi-rs/canvas": "0.1.58",
|
||||
"@signalapp/mock-server": "9.0.2",
|
||||
"@signalapp/mock-server": "9.1.0",
|
||||
"@storybook/addon-a11y": "8.1.11",
|
||||
"@storybook/addon-actions": "8.1.11",
|
||||
"@storybook/addon-controls": "8.1.11",
|
||||
|
|
|
@ -1484,15 +1484,6 @@ export async function startApp(): Promise<void> {
|
|||
|
||||
strictAssert(server !== undefined, 'WebAPI not ready');
|
||||
|
||||
// Once this resolves it will trigger `online` event and cause
|
||||
// `connect()`, but with `firstRun` set to `false`. Thus it is important
|
||||
// not to await it and let execution fall through.
|
||||
drop(
|
||||
server.authenticate(
|
||||
window.textsecure.storage.user.getWebAPICredentials()
|
||||
)
|
||||
);
|
||||
|
||||
// Cancel throttled calls to refreshRemoteConfig since our auth changed.
|
||||
window.Signal.RemoteConfig.maybeRefreshRemoteConfig.cancel();
|
||||
drop(window.Signal.RemoteConfig.maybeRefreshRemoteConfig(server));
|
||||
|
|
|
@ -1146,6 +1146,8 @@ export default class AccountManager extends EventTarget {
|
|||
password,
|
||||
});
|
||||
|
||||
await this.server.authenticate(storage.user.getWebAPICredentials());
|
||||
|
||||
// This needs to be done very early, because it changes how things are saved in the
|
||||
// database. Your identity, for example, in the saveIdentityWithAttributes call
|
||||
// below.
|
||||
|
|
|
@ -672,55 +672,8 @@ const URL_CALLS = {
|
|||
whoami: 'v1/accounts/whoami',
|
||||
};
|
||||
|
||||
const WEBSOCKET_CALLS = new Set<keyof typeof URL_CALLS>([
|
||||
// MessageController
|
||||
'messages',
|
||||
'multiRecipient',
|
||||
'reportMessage',
|
||||
|
||||
// ProfileController
|
||||
'profile',
|
||||
|
||||
// AttachmentControllerV3
|
||||
'attachmentUploadForm',
|
||||
|
||||
// RemoteConfigController
|
||||
'config',
|
||||
|
||||
// Certificate
|
||||
'deliveryCert',
|
||||
'getGroupCredentials',
|
||||
|
||||
// Devices
|
||||
'devices',
|
||||
'linkDevice',
|
||||
'registerCapabilities',
|
||||
'transferArchive',
|
||||
|
||||
// Directory
|
||||
'directoryAuthV2',
|
||||
|
||||
// Storage
|
||||
'storageToken',
|
||||
|
||||
// Account V2
|
||||
'phoneNumberDiscoverability',
|
||||
|
||||
// Backups
|
||||
'getBackupCredentials',
|
||||
'getBackupCDNCredentials',
|
||||
'getBackupMediaUploadForm',
|
||||
'getBackupUploadForm',
|
||||
'backup',
|
||||
'backupMedia',
|
||||
'backupMediaBatch',
|
||||
'backupMediaDelete',
|
||||
'setBackupId',
|
||||
'setBackupSignatureKey',
|
||||
]);
|
||||
|
||||
type InitializeOptionsType = {
|
||||
url: string;
|
||||
chatServiceUrl: string;
|
||||
storageUrl: string;
|
||||
updatesUrl: string;
|
||||
resourcesUrl: string;
|
||||
|
@ -1623,7 +1576,7 @@ type InflightCallback = (error: Error) => unknown;
|
|||
|
||||
// We first set up the data that won't change during this session of the app
|
||||
export function initialize({
|
||||
url,
|
||||
chatServiceUrl,
|
||||
storageUrl,
|
||||
updatesUrl,
|
||||
resourcesUrl,
|
||||
|
@ -1635,8 +1588,8 @@ export function initialize({
|
|||
version,
|
||||
disableIPv6,
|
||||
}: InitializeOptionsType): WebAPIConnectType {
|
||||
if (!isString(url)) {
|
||||
throw new Error('WebAPI.initialize: Invalid server url');
|
||||
if (!isString(chatServiceUrl)) {
|
||||
throw new Error('WebAPI.initialize: Invalid chatServiceUrl');
|
||||
}
|
||||
if (!isString(storageUrl)) {
|
||||
throw new Error('WebAPI.initialize: Invalid storageUrl');
|
||||
|
@ -1676,7 +1629,11 @@ export function initialize({
|
|||
// for providing network layer API and related functionality.
|
||||
// It's important to have a single instance of this class as it holds
|
||||
// resources that are shared across all other use cases.
|
||||
const libsignalNet = resolveLibsignalNet(url, version, certificateAuthority);
|
||||
const libsignalNet = resolveLibsignalNet(
|
||||
chatServiceUrl,
|
||||
version,
|
||||
certificateAuthority
|
||||
);
|
||||
libsignalNet.setIpv6Enabled(!disableIPv6);
|
||||
|
||||
// Thanks to function-hoisting, we can put this return statement before all of the
|
||||
|
@ -1703,7 +1660,7 @@ export function initialize({
|
|||
let activeRegistration: ExplodePromiseResultType<void> | undefined;
|
||||
|
||||
const socketManager = new SocketManager(libsignalNet, {
|
||||
url,
|
||||
url: chatServiceUrl,
|
||||
certificateAuthority,
|
||||
version,
|
||||
proxyUrl,
|
||||
|
@ -1931,8 +1888,11 @@ export function initialize({
|
|||
param.urlParameters = '';
|
||||
}
|
||||
|
||||
// When host is not provided, assume chat service
|
||||
const host = param.host || chatServiceUrl;
|
||||
const useWebSocketForEndpoint =
|
||||
useWebSocket && WEBSOCKET_CALLS.has(param.call);
|
||||
useWebSocket &&
|
||||
(!param.host || (host === chatServiceUrl && !isMockServer(host)));
|
||||
|
||||
const outerParams = {
|
||||
socketManager: useWebSocketForEndpoint ? socketManager : undefined,
|
||||
|
@ -1943,7 +1903,7 @@ export function initialize({
|
|||
param.data ||
|
||||
(param.jsonData ? JSON.stringify(param.jsonData) : undefined),
|
||||
headers: param.headers,
|
||||
host: param.host || url,
|
||||
host,
|
||||
password: param.password ?? password,
|
||||
path: URL_CALLS[param.call] + param.urlParameters,
|
||||
proxyUrl,
|
||||
|
@ -1952,7 +1912,7 @@ export function initialize({
|
|||
type: param.httpType,
|
||||
user: param.username ?? username,
|
||||
redactUrl: param.redactUrl,
|
||||
serverUrl: url,
|
||||
serverUrl: chatServiceUrl,
|
||||
validateResponse: param.validateResponse,
|
||||
version,
|
||||
unauthenticated: param.unauthenticated,
|
||||
|
|
|
@ -23,7 +23,7 @@ window.textsecure = textsecure;
|
|||
const { config } = window.SignalContext;
|
||||
|
||||
window.WebAPI = window.textsecure.WebAPI.initialize({
|
||||
url: config.serverUrl,
|
||||
chatServiceUrl: config.serverUrl,
|
||||
storageUrl: config.storageUrl,
|
||||
updatesUrl: config.updatesUrl,
|
||||
resourcesUrl: config.resourcesUrl,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue