mirror of
https://github.com/lone-cloud/prism
synced 2026-06-03 19:54:44 -07:00
better socket connect
This commit is contained in:
parent
00b8e35570
commit
9af3c2afcf
3 changed files with 26 additions and 27 deletions
|
|
@ -22,6 +22,7 @@ RUN curl -L https://github.com/AsamK/signal-cli/releases/download/v${SIGNAL_CLI_
|
|||
COPY --from=builder /app/sup-server /usr/local/bin/sup-server
|
||||
|
||||
ENV PATH="/usr/local/signal-cli/bin:${PATH}"
|
||||
ENV LD_LIBRARY_PATH="/usr/local/signal-cli/lib:${LD_LIBRARY_PATH}"
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ export const API_KEY = Bun.env.API_KEY;
|
|||
export const VERBOSE = Bun.env.VERBOSE === 'true';
|
||||
|
||||
export const DEVICE_NAME = 'SUP';
|
||||
export const DAEMON_START_MAX_ATTEMPTS = 10;
|
||||
|
||||
export const SUP_ENDPOINT_PREFIX = `[${DEVICE_NAME}:`;
|
||||
export const LAUNCH_ENDPOINT_PREFIX = '[LAUNCH:';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { rm } from 'node:fs/promises';
|
||||
import { DAEMON_START_MAX_ATTEMPTS, DEVICE_NAME, VERBOSE } from '../constants/config';
|
||||
import { DEVICE_NAME, VERBOSE } from '../constants/config';
|
||||
import { SIGNAL_CLI, SIGNAL_CLI_DATA, SIGNAL_CLI_SOCKET } from '../constants/paths';
|
||||
import type { ListAccountsResult, StartLinkResult, UpdateGroupResult } from '../types';
|
||||
import { logError, logInfo, logSuccess, logVerbose, logWarn } from '../utils/log';
|
||||
|
|
@ -157,21 +157,20 @@ export async function startDaemon() {
|
|||
}
|
||||
})();
|
||||
|
||||
let attempts = 0;
|
||||
while (attempts < DAEMON_START_MAX_ATTEMPTS) {
|
||||
await Bun.sleep(3000);
|
||||
|
||||
try {
|
||||
const socket = await Bun.connect({
|
||||
unix: SIGNAL_CLI_SOCKET,
|
||||
socket: {
|
||||
data() {},
|
||||
error() {},
|
||||
},
|
||||
});
|
||||
socket.end();
|
||||
logSuccess('✓ signal-cli daemon started');
|
||||
return proc;
|
||||
} catch (_error) {
|
||||
if (authError && attempts > 5 && !cleaned) {
|
||||
} catch (error) {
|
||||
if (authError && !cleaned) {
|
||||
logWarn('⚠ Detected stale account data, cleaning up and retrying...');
|
||||
proc.kill();
|
||||
await unlinkDevice();
|
||||
|
|
@ -179,10 +178,10 @@ export async function startDaemon() {
|
|||
return startDaemon();
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
attempts++;
|
||||
logError('Failed to connect to signal-cli socket:', error);
|
||||
if (proc.exitCode !== null) {
|
||||
logError('signal-cli process exited with code:', proc.exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('Failed to start signal-cli daemon');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue