-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(*): add setSelfDeaf command (#48)
- Loading branch information
1 parent
fc88c95
commit e4c1ce7
Showing
5 changed files
with
75 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { Client } from '@'; | ||
import { waitABit } from './utils/wait-a-bit'; | ||
|
||
describe('Sets self-deaf (e2e)', () => { | ||
let client: Client; | ||
|
||
beforeAll(async () => { | ||
client = new Client({ | ||
host: 'localhost', | ||
port: 64738, | ||
username: 'tester', | ||
rejectUnauthorized: false, | ||
}); | ||
await client.connect(); | ||
await waitABit(1000); | ||
}); | ||
|
||
afterAll(async () => { | ||
await waitABit(1000); | ||
client.disconnect(); | ||
}); | ||
|
||
it('should set self deaf', async () => { | ||
expect(client.user).toBeTruthy(); | ||
await client.user!.setSelfDeaf(true); | ||
expect(client.user!.selfDeaf).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { CommandTimeout } from '@/config'; | ||
import { CommandTimedOutError } from '@/errors'; | ||
import { MumbleSocket } from '@/mumble-socket'; | ||
import { filterPacket } from '@/rxjs-operators/filter-packet'; | ||
import { UserState } from '@tf2pickup-org/mumble-protocol'; | ||
import { filter, lastValueFrom, map, take, throwError, timeout } from 'rxjs'; | ||
|
||
export const setSelfDeaf = async ( | ||
socket: MumbleSocket, | ||
userSession: number, | ||
selfDeaf: boolean, | ||
): Promise<boolean> => { | ||
const ret = lastValueFrom( | ||
socket.packet.pipe( | ||
filterPacket(UserState), | ||
filter(userState => userState.session === userSession), | ||
filter(userState => userState.selfDeaf !== undefined), | ||
take(1), | ||
map(userState => userState.selfDeaf as boolean), | ||
timeout({ | ||
first: CommandTimeout, | ||
with: () => throwError(() => new CommandTimedOutError('setSelfDeaf')), | ||
}), | ||
), | ||
); | ||
socket.send(UserState, UserState.create({ session: userSession, selfDeaf })); | ||
return ret; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters