-
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 createChannel() command (#20)
- Loading branch information
1 parent
77bfc59
commit df568d0
Showing
7 changed files
with
70 additions
and
39 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
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,36 @@ | ||
import { PermissionDeniedError } from '@/errors'; | ||
import { MumbleSocket } from '@/mumble-socket'; | ||
import { filterPacket } from '@/rxjs-operators/filter-packet'; | ||
import { ChannelState, PermissionDenied } from '@proto/Mumble'; | ||
import { filter, race, take } from 'rxjs'; | ||
|
||
export const createChannel = async ( | ||
socket: MumbleSocket, | ||
parentChannelId: number, | ||
channelName: string, | ||
): Promise<number> => | ||
new Promise((resolve, reject) => { | ||
race( | ||
socket.packet.pipe( | ||
filterPacket(ChannelState), | ||
filter( | ||
channelState => | ||
channelState.parent === parentChannelId && | ||
channelState.name === channelName, | ||
), | ||
take(1), | ||
), | ||
socket.packet.pipe(filterPacket(PermissionDenied), take(1)), | ||
).subscribe(packet => { | ||
if (PermissionDenied.is(packet)) { | ||
reject(new PermissionDeniedError(packet)); | ||
} else { | ||
resolve(packet.channelId as number); | ||
} | ||
}); | ||
|
||
socket.send( | ||
ChannelState, | ||
ChannelState.create({ parent: parentChannelId, name: channelName }), | ||
); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { createChannel } from './create-channel'; | ||
export { fetchChannelPermissions } from './fetch-channel-permissions'; | ||
export { linkChannels } from './link-channels'; | ||
export { unlinkChannels } from './unlink-channels'; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { ConnectionRejectedError } from './connection-rejected.error'; | ||
export { InsufficientPermissionsError } from './insufficient-permissions.error'; | ||
export { NoSuchChannelError } from './no-such-channel.error'; | ||
export { PermissionDeniedError } from './permission-denied.error'; |
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,11 @@ | ||
import { PermissionDenied } from '@proto/Mumble'; | ||
|
||
export class PermissionDeniedError extends Error { | ||
constructor(public readonly permissionDenied: PermissionDenied) { | ||
let reason = 'permission denied'; | ||
if (permissionDenied.reason) { | ||
reason = permissionDenied.reason; | ||
} | ||
super(reason); | ||
} | ||
} |