Skip to content

Commit

Permalink
AudioPlayer: Logging when changing playback or queue
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Apr 11, 2023
1 parent 5574b08 commit ea2083c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
48 changes: 37 additions & 11 deletions ts/state/ducks/audioPlayer.ts
Expand Up @@ -311,19 +311,19 @@ export function reducer(
}

const { playbackRate, startPosition, ...content } = payload;
log.info(
`audioPlayer/SET_MESSAGE_AUDIO: Starting playback for conversation ${content.conversationId}`
);
return {
...state,
active:
payload === undefined
? undefined
: {
currentTime: 0,
duration: undefined,
playing: true,
playbackRate,
content,
startPosition,
},
active: {
currentTime: 0,
duration: undefined,
playing: true,
playbackRate,
content,
startPosition,
},
};
}

Expand Down Expand Up @@ -446,8 +446,14 @@ export function reducer(
// insert a new voice note
if (voiceNote) {
if (idx === -1) {
log.info(
`audioPlayer/MESSAGES_ADDED: Adding voice note ${voiceNote.messageIdForLogging} to end of queue`
);
updatedQueue.push(voiceNote);
} else {
log.info(
`audioPlayer/MESSAGES_ADDED: Adding voice note ${voiceNote.messageIdForLogging} to queue at index ${idx}`
);
updatedQueue.splice(idx, 0, voiceNote);
}
}
Expand Down Expand Up @@ -480,6 +486,9 @@ export function reducer(
}

if (AudioPlayerContent.isDraft(content)) {
log.info(
'audioPlayer/MESSAGE_AUDIO_ENDED: Voice note was draft, stopping playback'
);
return {
...state,
active: undefined,
Expand All @@ -491,6 +500,9 @@ export function reducer(
const [nextVoiceNote, ...newQueue] = queue;

if (nextVoiceNote) {
log.info(
`audioPlayer/MESSAGE_AUDIO_ENDED: Starting next voice note ${nextVoiceNote.messageIdForLogging}`
);
return {
...state,
active: {
Expand All @@ -506,6 +518,7 @@ export function reducer(
};
}

log.info('audioPlayer/MESSAGE_AUDIO_ENDED: Stopping playback');
return {
...state,
active: undefined,
Expand Down Expand Up @@ -535,12 +548,18 @@ export function reducer(
const [next, ...rest] = content.queue;

if (!next) {
log.info(
'audioPlayer/MESSAGE_DELETED: Removed currently-playing message, stopping playback'
);
return {
...state,
active: undefined,
};
}

log.info(
'audioPlayer/MESSAGE_DELETED: Removed currently-playing message, moving to next in queue'
);
return {
...state,
active: {
Expand All @@ -558,6 +577,7 @@ export function reducer(
// just update the queue
const message = content.queue.find(el => el.id === id);
if (message) {
log.info('audioPlayer/MESSAGE_DELETED: Removed message from the queue');
return {
...state,
active: {
Expand Down Expand Up @@ -611,6 +631,9 @@ export function reducer(
content.current.url === undefined &&
data.id
) {
log.info(
'audioPlayer/MESSAGE_CHANGED: Adding content url to current-playing message'
);
return {
...state,
active: {
Expand All @@ -629,6 +652,9 @@ export function reducer(
// if it's in the queue
const idx = content.queue.findIndex(v => v.id === id);
if (idx !== -1) {
log.info(
'audioPlayer/MESSAGE_CHANGED: Adding content url to message in queue'
);
const updatedQueue = [...content.queue];
updatedQueue[idx] = {
...updatedQueue[idx],
Expand Down
4 changes: 4 additions & 0 deletions ts/util/sendReceipts.ts
Expand Up @@ -55,6 +55,8 @@ export async function sendReceipts({
return;
}

log.info(`Starting receipt send of type ${type}`);

const receiptsBySenderId: Map<string, Array<Receipt>> = receipts.reduce(
(result, receipt) => {
const { senderE164, senderUuid } = receipt;
Expand Down Expand Up @@ -116,6 +118,8 @@ export async function sendReceipts({
return;
}

log.info(`Sending receipt of type ${type} to ${sender.idForLogging()}`);

const sendOptions = await getSendOptions(sender.attributes);

const batches = chunk(receiptsForSender, CHUNK_SIZE);
Expand Down

0 comments on commit ea2083c

Please sign in to comment.