File tree Expand file tree Collapse file tree 1 file changed +30
-8
lines changed Expand file tree Collapse file tree 1 file changed +30
-8
lines changed Original file line number Diff line number Diff line change
1
+ import { CommandTimeout } from '@/config' ;
2
+ import { CommandTimedOutError } from '@/errors' ;
1
3
import { MumbleSocket } from '@/mumble-socket' ;
2
4
import { filterPacket } from '@/rxjs-operators/filter-packet' ;
3
5
import { PermissionQuery } from '@tf2pickup-org/mumble-protocol' ;
4
- import { filter , take } from 'rxjs' ;
6
+ import {
7
+ concatMap ,
8
+ filter ,
9
+ lastValueFrom ,
10
+ race ,
11
+ take ,
12
+ throwError ,
13
+ timer ,
14
+ } from 'rxjs' ;
5
15
6
16
export const fetchChannelPermissions = async (
7
17
socket : MumbleSocket ,
8
18
channelId : number ,
9
19
) : Promise < PermissionQuery > => {
10
- return new Promise ( resolve => {
11
- socket . packet
12
- . pipe (
20
+ const ret = lastValueFrom (
21
+ race (
22
+ socket . packet . pipe (
13
23
filterPacket ( PermissionQuery ) ,
14
24
filter ( permissionQuery => permissionQuery . channelId === channelId ) ,
15
25
take ( 1 ) ,
16
- )
17
- . subscribe ( resolve ) ;
18
- socket . send ( PermissionQuery , PermissionQuery . create ( { channelId } ) ) ;
19
- } ) ;
26
+ ) ,
27
+ timer ( CommandTimeout ) . pipe (
28
+ concatMap ( ( ) =>
29
+ throwError ( ( ) => new CommandTimedOutError ( 'fetchChannelPermissions' ) ) ,
30
+ ) ,
31
+ ) ,
32
+ ) ,
33
+ ) ;
34
+
35
+ // Send TWO PermissionQuery packets; if we send only one, the mumble server might not respond,
36
+ // causing the command to time out.
37
+ // I have no idea what is going on here, but I'm either dumb or mumble server is bugged as heck.
38
+ [ 0 , 1 ] . forEach ( ( ) =>
39
+ socket . send ( PermissionQuery , PermissionQuery . create ( { channelId } ) ) ,
40
+ ) ;
41
+ return ret ;
20
42
} ;
You can’t perform that action at this time.
0 commit comments