add option to send first packet twice

This commit is contained in:
Lewis Moten
2024-05-17 22:24:54 -04:00
parent 6f4b898f52
commit 79c8494f9f
2 changed files with 16 additions and 1 deletions

View File

@@ -28,6 +28,10 @@ class MessagePanel extends BasePanel {
this.addDynamicText('bytes', 0);
this.closeField();
this.addCheckboxes('packet-options', [
{ text: 'Send First Packet Twice', id: 'first-packet-twice', checked: true },
]);
this.addEventListener('send-button-click', () => {
if(this.getSendButtonText() === 'Send') {
this.dispatcher.emit('sendClick');
@@ -46,6 +50,8 @@ class MessagePanel extends BasePanel {
});
this.dispatcher.emit('dataTypeChange', {values: [this.getDataType()]});
}
setIsFirstPacketSentTwice = (checked) => this.setCheckedById('first-packet-twice', checked);
getIsFirstPacketSentTwice = () => this.getCheckedById('first-packet-twice');
getSendButtonText = () => this.getValueById('send-button');
setSendButtonText = text => this.setValueById('send-button', text);
setMessageText = text => {

View File

@@ -75,6 +75,7 @@ function handleWindowLoad() {
messagePanel.setMessageText(Randomizer.text(5));
messagePanel.setDataType('text');
messagePanel.setSendButtonText('Send');
messagePanel.setIsFirstPacketSentTwice(true);
messagePanel.addEventListener('dataTypeChange', ({values: [dataType]}) => {
receivePanel.setDataType(dataType);
@@ -491,16 +492,24 @@ function sendPackets(bytes, packetIndeces) {
AudioSender.setAudioContext(audioContext);
const sendFirstTwice = messagePanel.getIsFirstPacketSentTwice();
if(audioContext.state !== "running") {
statusPanel.appendText(`Expected audio context to be running. State: ${audioContext.state}`);
}
const startSeconds = AudioSender.now() + 0.1;
let startSeconds = AudioSender.now() + 0.1;
const packetBitCount = PacketUtils.getPacketMaxBitCount();
const packer = PacketUtils.pack(bytes);
try {
AudioSender.beginAt(startSeconds);
if(sendFirstTwice) {
let packet = packer.getBits(packetIndeces[0]);
packet.push(...new Array(packetBitCount - packet.length).fill(0));
sendPacket(packet, startSeconds);
startSeconds += packetDurationSeconds;
}
// send all packets
for(let i = 0; i < requestedPacketCount; i++) {
let packet = packer.getBits(packetIndeces[i]);