Android: create, edit and delete channels
A one-page channel editor with what the desktop dialog has but the permissions and the icon: name, password, topic, description, type, sorting, talk power, codec preset or codec and quality, and the limits. Create channel is on the server sheet; create sub-channel, edit and delete on the channel sheet, each only with the permission for it. The codec list, presets and bandwidth move to core for both editors. Core gains channel delete, and the desktop channel menu a Delete Channel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -97,6 +97,13 @@ final class ChannelAdmin {
|
||||
conn.socket().executeCommand(cmd).complete();
|
||||
}
|
||||
|
||||
/** Deletes a channel, with its sub-channels and whoever is in them moved out when {@code force}. */
|
||||
void delete(int channelId, boolean force) throws Exception {
|
||||
conn.socket().executeCommand(new SingleCommand("channeldelete", ProtocolRole.CLIENT,
|
||||
new CommandSingleParameter("cid", Integer.toString(channelId)),
|
||||
new CommandSingleParameter("force", force ? "1" : "0"))).complete();
|
||||
}
|
||||
|
||||
// ---- channel permissions ----
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.ts3client.net;
|
||||
|
||||
/**
|
||||
* The voice codecs a channel can use, in TeamSpeak's own id order, with the editor's
|
||||
* presets and what one talking client costs in bandwidth.
|
||||
*/
|
||||
public final class ChannelCodec {
|
||||
|
||||
/** Codec names, indexed by {@link ChannelSettings#codec}. */
|
||||
public static final String[] NAMES = {
|
||||
"Speex Narrowband", "Speex Wideband", "Speex Ultra-Wideband",
|
||||
"CELT Mono", "Opus Voice", "Opus Music"};
|
||||
|
||||
public static final int OPUS_VOICE = 4;
|
||||
public static final int OPUS_MUSIC = 5;
|
||||
public static final int MAX_QUALITY = 10;
|
||||
|
||||
/** The channel editor's presets; a codec and quality matching none of them is custom. */
|
||||
public enum Preset {
|
||||
VOICE_MOBILE("Voice Mobile", OPUS_VOICE, 4),
|
||||
VOICE_DESKTOP("Voice Desktop", OPUS_VOICE, 6),
|
||||
MUSIC("Music", OPUS_MUSIC, 6);
|
||||
|
||||
public final String label;
|
||||
public final int codec;
|
||||
public final int quality;
|
||||
|
||||
Preset(String label, int codec, int quality) {
|
||||
this.label = label;
|
||||
this.codec = codec;
|
||||
this.quality = quality;
|
||||
}
|
||||
|
||||
/** The preset with this codec and quality, or null for a custom setting. */
|
||||
public static Preset of(int codec, int quality) {
|
||||
for (Preset p : values()) {
|
||||
if (p.codec == codec && p.quality == quality) return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bandwidth per talking client in KiB/s at quality 0 and 10, per codec, as published by
|
||||
* TeamSpeak. The steps in between are interpolated: the client shows a figure per
|
||||
* quality step, and only the two ends of each codec's range are documented.
|
||||
*/
|
||||
private static final double[][] BANDWIDTH_RANGE = {
|
||||
{2.49, 5.22}, {2.69, 7.37}, {2.73, 7.57}, {6.10, 13.92}, {2.73, 7.71}, {3.08, 11.87}};
|
||||
|
||||
private ChannelCodec() {
|
||||
}
|
||||
|
||||
public static String name(int codec) {
|
||||
return NAMES[clampCodec(codec)];
|
||||
}
|
||||
|
||||
public static int clampCodec(int codec) {
|
||||
return Math.max(0, Math.min(NAMES.length - 1, codec));
|
||||
}
|
||||
|
||||
/** KiB/s one talking client costs. */
|
||||
public static double bandwidth(int codec, int quality) {
|
||||
double[] range = BANDWIDTH_RANGE[clampCodec(codec)];
|
||||
int q = Math.max(0, Math.min(MAX_QUALITY, quality));
|
||||
return range[0] + (range[1] - range[0]) * q / MAX_QUALITY;
|
||||
}
|
||||
|
||||
/** {@link #bandwidth} as the editor shows it. */
|
||||
public static String bandwidthText(int codec, int quality) {
|
||||
return String.format("%.2f KiB/s", bandwidth(codec, quality));
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@ public final class ChannelSettings {
|
||||
/** How long a channel outlives its last occupant. */
|
||||
public enum Type {TEMPORARY, SEMI_PERMANENT, PERMANENT}
|
||||
|
||||
/** TeamSpeak's ceiling for {@code channel_delete_delay}, in seconds. */
|
||||
public static final int MAX_DELETE_DELAY = 604800;
|
||||
|
||||
public int id;
|
||||
public int parentId;
|
||||
public String name = "";
|
||||
|
||||
@@ -1432,6 +1432,18 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a channel; with {@code force}, also one that has sub-channels or clients in it.
|
||||
*
|
||||
* @param callback given {@code null} on success, or the failure message
|
||||
*/
|
||||
public void deleteChannel(int channelId, boolean force, Consumer<String> callback) {
|
||||
run((ignored, error) -> callback.accept(error), () -> {
|
||||
channels.delete(channelId, force);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/** The ids of the icons uploaded to this virtual server. */
|
||||
public void requestServerIcons(BiConsumer<List<Long>, String> callback) {
|
||||
run(callback, channels::listIcons);
|
||||
|
||||
@@ -630,6 +630,29 @@ public final class ServerSession {
|
||||
return hasPower("i_client_ban_power");
|
||||
}
|
||||
|
||||
public boolean canCreateChannels() {
|
||||
return permitsAny("b_channel_create_temporary", "b_channel_create_semi_permanent",
|
||||
"b_channel_create_permanent");
|
||||
}
|
||||
|
||||
public boolean canEditChannels() {
|
||||
return permitsAny("b_channel_modify_name", "b_channel_modify_topic", "b_channel_modify_description",
|
||||
"b_channel_modify_password", "b_channel_modify_codec", "b_channel_modify_maxclients");
|
||||
}
|
||||
|
||||
public boolean canDeleteChannels() {
|
||||
return permitsAny("b_channel_delete_temporary", "b_channel_delete_semi_permanent",
|
||||
"b_channel_delete_permanent");
|
||||
}
|
||||
|
||||
private boolean permitsAny(String... permissions) {
|
||||
if (!conn.isConnected()) return false;
|
||||
for (String p : permissions) {
|
||||
if (conn.getModel().permits(p)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we have any of a power; whether it beats the client's needed power only the
|
||||
* server knows, so it is left to refuse.
|
||||
|
||||
@@ -28,12 +28,9 @@ import java.awt.Insets;
|
||||
*/
|
||||
final class ChannelAdvancedPanel extends JPanel implements ChannelDialog.Tab {
|
||||
|
||||
/** TeamSpeak's ceiling for {@code channel_delete_delay}, in seconds. */
|
||||
private static final int MAX_DELETE_DELAY = 604800;
|
||||
|
||||
private final JTextField phoneticName = new JTextField();
|
||||
private final JSpinner deleteDelay =
|
||||
Spinners.compact(new JSpinner(new SpinnerNumberModel(0, 0, MAX_DELETE_DELAY, 1)));
|
||||
Spinners.compact(new JSpinner(new SpinnerNumberModel(0, 0, ChannelSettings.MAX_DELETE_DELAY, 1)));
|
||||
private final JButton deleteDelayMax = new JButton("max");
|
||||
private final JCheckBox encrypted = new JCheckBox("Voice Data encrypted");
|
||||
|
||||
@@ -55,7 +52,7 @@ final class ChannelAdvancedPanel extends JPanel implements ChannelDialog.Tab {
|
||||
deleteDelay.setToolTipText("<html><p>Delay in seconds after temporary channels are deleted"
|
||||
+ " after the last user left the channel.</p></html>");
|
||||
deleteDelayMax.setToolTipText("Set delete delay to maximum value");
|
||||
deleteDelayMax.addActionListener(a -> deleteDelay.setValue(MAX_DELETE_DELAY));
|
||||
deleteDelayMax.addActionListener(a -> deleteDelay.setValue(ChannelSettings.MAX_DELETE_DELAY));
|
||||
encrypted.setToolTipText("Voice data in this channel will be encrypted.");
|
||||
|
||||
ButtonGroup users = new ButtonGroup();
|
||||
@@ -105,7 +102,7 @@ final class ChannelAdvancedPanel extends JPanel implements ChannelDialog.Tab {
|
||||
@Override
|
||||
public void read(ChannelSettings settings) {
|
||||
phoneticName.setText(settings.phoneticName);
|
||||
deleteDelay.setValue(Math.min(MAX_DELETE_DELAY, Math.max(0, settings.deleteDelay)));
|
||||
deleteDelay.setValue(Math.min(ChannelSettings.MAX_DELETE_DELAY, Math.max(0, settings.deleteDelay)));
|
||||
encrypted.setSelected(settings.encrypted);
|
||||
|
||||
if (settings.maxClientsUnlimited) maxUsersUnlimited.setSelected(true);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ts3client.ui;
|
||||
|
||||
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import com.ts3client.net.ChannelCodec;
|
||||
import com.ts3client.net.ChannelSettings;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
@@ -24,27 +25,11 @@ import java.awt.Insets;
|
||||
*/
|
||||
final class ChannelAudioPanel extends JPanel implements ChannelDialog.Tab {
|
||||
|
||||
/** Codec names in TeamSpeak's own id order, which is what the combo box index is. */
|
||||
private static final String[] CODEC_NAMES = {
|
||||
"Speex Narrowband", "Speex Wideband", "Speex Ultra-Wideband",
|
||||
"CELT Mono", "Opus Voice", "Opus Music"};
|
||||
|
||||
/**
|
||||
* Bandwidth per talking client in KiB/s at quality 0 and 10, per codec, as published by
|
||||
* TeamSpeak. The steps in between are interpolated: the client shows a figure per
|
||||
* quality step, and only the two ends of each codec's range are documented.
|
||||
*/
|
||||
private static final double[][] BANDWIDTH_RANGE = {
|
||||
{2.49, 5.22}, {2.69, 7.37}, {2.73, 7.57}, {6.10, 13.92}, {2.73, 7.71}, {3.08, 11.87}};
|
||||
|
||||
private static final int CODEC_OPUS_VOICE = 4;
|
||||
private static final int CODEC_OPUS_MUSIC = 5;
|
||||
|
||||
private final JRadioButton voiceMobile = new JRadioButton("Voice Mobile");
|
||||
private final JRadioButton voiceDesktop = new JRadioButton("Voice Desktop");
|
||||
private final JRadioButton music = new JRadioButton("Music");
|
||||
private final JRadioButton custom = new JRadioButton("Custom");
|
||||
private final JComboBox<String> codec = new JComboBox<>(CODEC_NAMES);
|
||||
private final JComboBox<String> codec = new JComboBox<>(ChannelCodec.NAMES);
|
||||
private final JSlider quality = new JSlider(0, 10, 6);
|
||||
private final JLabel qualityValue = new JLabel("6");
|
||||
private final JLabel bandwidth = new JLabel();
|
||||
@@ -59,9 +44,9 @@ final class ChannelAudioPanel extends JPanel implements ChannelDialog.Tab {
|
||||
presets.add(voiceDesktop);
|
||||
presets.add(music);
|
||||
presets.add(custom);
|
||||
voiceMobile.addActionListener(a -> applyPreset(CODEC_OPUS_VOICE, 4));
|
||||
voiceDesktop.addActionListener(a -> applyPreset(CODEC_OPUS_VOICE, 6));
|
||||
music.addActionListener(a -> applyPreset(CODEC_OPUS_MUSIC, 6));
|
||||
voiceMobile.addActionListener(a -> applyPreset(ChannelCodec.Preset.VOICE_MOBILE));
|
||||
voiceDesktop.addActionListener(a -> applyPreset(ChannelCodec.Preset.VOICE_DESKTOP));
|
||||
music.addActionListener(a -> applyPreset(ChannelCodec.Preset.MUSIC));
|
||||
custom.addActionListener(a -> setCustomEnabled(true));
|
||||
|
||||
codec.addActionListener(a -> updateBandwidth());
|
||||
@@ -77,12 +62,15 @@ final class ChannelAudioPanel extends JPanel implements ChannelDialog.Tab {
|
||||
|
||||
@Override
|
||||
public void read(ChannelSettings settings) {
|
||||
codec.setSelectedIndex(Math.max(0, Math.min(CODEC_NAMES.length - 1, settings.codec)));
|
||||
quality.setValue(Math.max(0, Math.min(10, settings.codecQuality)));
|
||||
if (settings.codec == CODEC_OPUS_VOICE && settings.codecQuality == 4) voiceMobile.setSelected(true);
|
||||
else if (settings.codec == CODEC_OPUS_VOICE && settings.codecQuality == 6) voiceDesktop.setSelected(true);
|
||||
else if (settings.codec == CODEC_OPUS_MUSIC && settings.codecQuality == 6) music.setSelected(true);
|
||||
else custom.setSelected(true);
|
||||
codec.setSelectedIndex(ChannelCodec.clampCodec(settings.codec));
|
||||
quality.setValue(Math.max(0, Math.min(ChannelCodec.MAX_QUALITY, settings.codecQuality)));
|
||||
ChannelCodec.Preset preset = ChannelCodec.Preset.of(settings.codec, settings.codecQuality);
|
||||
if (preset == null) custom.setSelected(true);
|
||||
else switch (preset) {
|
||||
case VOICE_MOBILE -> voiceMobile.setSelected(true);
|
||||
case VOICE_DESKTOP -> voiceDesktop.setSelected(true);
|
||||
case MUSIC -> music.setSelected(true);
|
||||
}
|
||||
setCustomEnabled(custom.isSelected());
|
||||
updateBandwidth();
|
||||
}
|
||||
@@ -93,9 +81,9 @@ final class ChannelAudioPanel extends JPanel implements ChannelDialog.Tab {
|
||||
settings.codecQuality = quality.getValue();
|
||||
}
|
||||
|
||||
private void applyPreset(int codecId, int qualityValue) {
|
||||
codec.setSelectedIndex(codecId);
|
||||
quality.setValue(qualityValue);
|
||||
private void applyPreset(ChannelCodec.Preset preset) {
|
||||
codec.setSelectedIndex(preset.codec);
|
||||
quality.setValue(preset.quality);
|
||||
setCustomEnabled(false);
|
||||
updateBandwidth();
|
||||
}
|
||||
@@ -107,10 +95,7 @@ final class ChannelAudioPanel extends JPanel implements ChannelDialog.Tab {
|
||||
|
||||
private void updateBandwidth() {
|
||||
qualityValue.setText(Integer.toString(quality.getValue()));
|
||||
int index = Math.max(0, Math.min(BANDWIDTH_RANGE.length - 1, codec.getSelectedIndex()));
|
||||
double[] range = BANDWIDTH_RANGE[index];
|
||||
double value = range[0] + (range[1] - range[0]) * quality.getValue() / 10.0;
|
||||
bandwidth.setText(String.format("%.2f KiB/s", value));
|
||||
bandwidth.setText(ChannelCodec.bandwidthText(codec.getSelectedIndex(), quality.getValue()));
|
||||
}
|
||||
|
||||
private JPanel presetBox() {
|
||||
|
||||
@@ -32,6 +32,9 @@ final class ChannelMenu {
|
||||
JMenuItem edit = new JMenuItem("Edit Channel", Icons.of("CHANNEL_EDIT"));
|
||||
edit.addActionListener(a -> actions.editChannel(channel));
|
||||
menu.add(edit);
|
||||
JMenuItem delete = new JMenuItem("Delete Channel", Icons.of("CHANNEL_DELETE"));
|
||||
delete.addActionListener(a -> actions.deleteChannel(channel));
|
||||
menu.add(delete);
|
||||
menu.addSeparator();
|
||||
addSubscriptionItems(menu, channel, actions);
|
||||
JMenuItem files = new JMenuItem("Browse files", Icons.of("FILETRANSFER"));
|
||||
|
||||
@@ -297,6 +297,23 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
ChannelDialog.toEdit(host, conn, groupIcons, channel).setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteChannel(ChannelNode channel) {
|
||||
if (!conn.isConnected()) return;
|
||||
// Like TeamSpeak, a channel that is not empty takes its sub-channels along and sends its clients away.
|
||||
boolean occupied = !channel.children.isEmpty() || !channel.clients.isEmpty();
|
||||
String question = "Delete channel \"" + channel.name + "\""
|
||||
+ (occupied ? " with its sub-channels and the clients in it?" : "?");
|
||||
if (JOptionPane.showConfirmDialog(host, question, "Delete Channel", JOptionPane.OK_CANCEL_OPTION,
|
||||
JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
|
||||
return;
|
||||
}
|
||||
conn.deleteChannel(channel.id, true, error -> {
|
||||
if (error != null) SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(host,
|
||||
"Could not delete the channel: " + error, "Error", JOptionPane.ERROR_MESSAGE));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createChannel(ChannelNode parent, ChannelSettings.Type type) {
|
||||
if (!conn.isConnected()) return;
|
||||
|
||||
@@ -65,6 +65,8 @@ public final class ServerTreePanel extends JPanel {
|
||||
/** Opens the channel editor for a channel. */
|
||||
void editChannel(ChannelNode channel);
|
||||
|
||||
void deleteChannel(ChannelNode channel);
|
||||
|
||||
/**
|
||||
* Opens the channel creator.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user