You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Event-driven architecture with full TypeScript support
Automatic keep-alive pinging
Installation
npm i @tf2pickup-org/mumble-client
Quick start
import{Client}from'@tf2pickup-org/mumble-client';constclient=newClient({host: 'mumble.example.com',port: 64738,username: 'my-bot',rejectUnauthorized: false,});awaitclient.connect();console.log(`Connected! Welcome message: ${client.welcomeText}`);console.log(`Logged in as ${client.self?.name}`);// ... do work ...client.disconnect();
// by nameconstlobby=client.channels.byName('Lobby');// by path (from root)constredTeam=client.channels.byPath('Match 1','RED');// by custom predicateconsttempChannels=client.channels.findAll(ch=>ch.temporary);
Create and manage channels
constroot=client.channels.root;// create a sub-channel under rootconstmatchChannel=awaitroot.createSubChannel('Match 1');// create team channelsconstred=awaitmatchChannel.createSubChannel('RED');constblu=awaitmatchChannel.createSubChannel('BLU');// link two channels togetherawaitred.link(blu);// unlink themawaitred.unlink(blu);// remove a channel (and all its sub-channels)awaitmatchChannel.remove();
// register the currently logged-in userawaitclient.self.register();// fetch all registered users from the serverconstregisteredUsers=awaitclient.fetchRegisteredUsers();for(constuserofregisteredUsers){console.log(`${user.userId}: ${user.name}`);}// rename a registered user (does not need to be online)awaitclient.renameRegisteredUser(userId,'NewName');// deregister a user (does not need to be online)awaitclient.deregisterUser(userId);
// user connectedclient.on('userCreate',user=>{console.log(`${user.name} connected`);});// user disconnectedclient.on('userRemove',user=>{console.log(`${user.name} disconnected`);});// user state changed (e.g. moved channel, muted, etc.)client.on('userUpdate',(user,changes)=>{if(changes.channelId){constfrom=client.channels.byId(changes.channelId.previousValue);constto=client.channels.byId(changes.channelId.currentValue);console.log(`${user.name} moved from ${from?.name} to ${to?.name}`);}});// channel createdclient.on('channelCreate',channel=>{console.log(`Channel created: ${channel.name}`);});// channel removedclient.on('channelRemove',channel=>{console.log(`Channel removed: ${channel.name}`);});// speaking state changesclient.on('speakingStateChange',({ user, speaking })=>{console.log(`${user.name}${speaking ? 'started' : 'stopped'} speaking`);});// disconnected from serverclient.on('disconnect',payload=>{console.log(`Disconnected: ${payload?.reason??'unknown reason'}`);});
Error handling
import{Client,ConnectionRejectedError,PermissionDeniedError,NoSuchChannelError,}from'@tf2pickup-org/mumble-client';try{awaitclient.connect();}catch(error){if(errorinstanceofConnectionRejectedError){console.error('Connection rejected by server');}}try{awaitclient.channels.root.createSubChannel('test');}catch(error){if(errorinstanceofPermissionDeniedError){console.error('Insufficient permissions to create channel');}}
API overview
Client
The main entry point. Connects to the server and provides access to channels, users, and events.
Property / Method
Description
channels
ChannelManager instance for finding channels
users
UserManager instance for finding users
self
The currently logged-in User
welcomeText
Server welcome message
serverVersion
Server version info
connect()
Connect to the Mumble server
disconnect()
Disconnect from the server
isConnected()
Returns true if connected
fetchRegisteredUsers()
Fetch all registered users
deregisterUser(userId)
Deregister a user by ID
renameRegisteredUser(userId, name)
Rename a registered user
ChannelManager
Method
Description
root
The root channel
byId(channelId)
Find channel by ID
byName(name)
Find channel by name
byPath(...path)
Find channel by path segments
find(predicate)
Find first matching channel
findAll(predicate)
Find all matching channels
Channel
Property / Method
Description
id
Channel ID
name
Channel name
temporary
Whether the channel is temporary
users
Users currently in this channel
subChannels
Direct sub-channels
linkedChannels
Linked channels
createSubChannel(name)
Create a sub-channel
remove()
Remove this channel
link(channel)
Link with another channel
unlink(channel)
Unlink from another channel
getPermissions()
Fetch permissions for this channel
fetchAcl()
Fetch the channel ACL
saveAcl(acl)
Save the channel ACL
UserManager
Method
Description
bySession(session)
Find user by session ID
byName(name)
Find user by name
findAll(predicate)
Find all matching users
User
Property / Method
Description
session
Session ID
name
Username
channel
Current channel
channelId
Current channel ID
isRegistered
Whether the user is registered
mute / deaf / suppress
Server mute/deaf/suppress state
selfMute / selfDeaf
Self-mute/deaf state
moveToChannel(channelId)
Move user to a channel
setSelfMute(mute)
Set self-mute state
setSelfDeaf(deaf)
Set self-deaf state
register()
Register the user
deregister()
Deregister the user
rename(name)
Rename a registered user
Permissions
Property / Method
Description
canJoinChannel
Can join/enter the channel
canCreateChannel
Can create sub-channels
canRemoveChannel
Can remove channels
canLinkChannel
Can link channels
canSelfRegister
Can self-register
canRegister
Can register other users
Events
Event
Payload
Description
connect
—
Client connected successfully
disconnect
{ reason?: string }
Client disconnected
channelCreate
Channel
A channel was created
channelUpdate
Channel, ChannelChanges
A channel was updated
channelRemove
Channel
A channel was removed
userCreate
User
A user connected
userUpdate
User, UserChanges
A user's state changed
userRemove
User
A user disconnected
speakingStateChange
{ user: User, speaking: boolean }
A user started/stopped speaking
ClientOptions
Extends Node.js tls.ConnectionOptions.
Option
Type
Default
Description
host
string
—
Server hostname
port
number
64738
Server port
username
string
—
Username for authentication
password
string?
—
Server or user password
tokens
string[]?
[]
Access tokens for server ACL groups
clientName
string?
'simple mumble bot'
Client name sent to the server
pingInterval
number?
10000
Keep-alive ping interval in ms
Since ClientOptions extends tls.ConnectionOptions, you can pass any TLS option such as rejectUnauthorized, cert, key, ca, etc.