Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(*): fix fetchChannelPermissions command timeout #42

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions src/commands/fetch-channel-permissions.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
import { CommandTimeout } from '@/config';
import { CommandTimedOutError } from '@/errors';
import { MumbleSocket } from '@/mumble-socket';
import { filterPacket } from '@/rxjs-operators/filter-packet';
import { PermissionQuery } from '@tf2pickup-org/mumble-protocol';
import { filter, take } from 'rxjs';
import {
concatMap,
filter,
lastValueFrom,
race,
take,
throwError,
timer,
} from 'rxjs';

export const fetchChannelPermissions = async (
socket: MumbleSocket,
channelId: number,
): Promise<PermissionQuery> => {
return new Promise(resolve => {
socket.packet
.pipe(
const ret = lastValueFrom(
race(
socket.packet.pipe(
filterPacket(PermissionQuery),
filter(permissionQuery => permissionQuery.channelId === channelId),
take(1),
)
.subscribe(resolve);
socket.send(PermissionQuery, PermissionQuery.create({ channelId }));
});
),
timer(CommandTimeout).pipe(
concatMap(() =>
throwError(() => new CommandTimedOutError('fetchChannelPermissions')),
),
),
),
);

// Send TWO PermissionQuery packets; if we send only one, the mumble server might not respond,
// causing the command to time out.
// I have no idea what is going on here, but I'm either dumb or mumble server is bugged as heck.
[0, 1].forEach(() =>
socket.send(PermissionQuery, PermissionQuery.create({ channelId })),
);
return ret;
};