You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
44 lines
1.1 KiB
package com.jotuntech.sketcher.server.command;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import com.jotuntech.sketcher.common.User;
|
|
import com.jotuntech.sketcher.server.Command;
|
|
import com.jotuntech.sketcher.server.Connection;
|
|
import com.jotuntech.sketcher.server.Server;
|
|
|
|
public class VoiceCommand implements Command {
|
|
boolean voiceEnabled;
|
|
|
|
public VoiceCommand() {
|
|
|
|
}
|
|
|
|
public VoiceCommand(boolean voiceEnabled) {
|
|
this.voiceEnabled = voiceEnabled;
|
|
}
|
|
|
|
public int perform(Server server, Connection connection) {
|
|
User user = connection.getUser();
|
|
if(user == null) {
|
|
return Connection.SEND_NONE;
|
|
}
|
|
if(user.isViewer()) {
|
|
return Connection.SEND_NONE;
|
|
}
|
|
if(voiceEnabled) {
|
|
server.getVoiceServer().addClient(server.getConnectionMap().getKeyForValue(connection));
|
|
} else {
|
|
server.getVoiceServer().removeClient(server.getConnectionMap().getKeyForValue(connection));
|
|
}
|
|
return Connection.SEND_NONE;
|
|
}
|
|
|
|
public void decode(ByteBuffer in) {
|
|
voiceEnabled = in.get() != 0;
|
|
}
|
|
|
|
public void encode(ByteBuffer out) {
|
|
out.put((byte) (voiceEnabled ? 0xFF : 0x00));
|
|
}
|
|
}
|
|
|