Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions flottform/forms/src/default-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,9 @@ const handleTextInputStates = ({
if (id) {
flottformItem.setAttribute('id', id);
}
flottformTextInputHost.on('done', (message: string) => {
statusInformation.innerHTML = onSuccessText ?? `✨ You have succesfully submitted your message`;
flottformTextInputHost.on('text-received', (message: string) => {
statusInformation.innerHTML =
onSuccessText ?? `✨ You have succesfully submitted your message: ${message}`;
statusInformation.appendChild(refreshChannelButton);
flottformItem.replaceChildren(statusInformation);
});
Expand Down
22 changes: 16 additions & 6 deletions flottform/forms/src/flottform-text-input-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { FlottformChannelClient } from './flottform-channel-client';
import { DEFAULT_WEBRTC_CONFIG, EventEmitter, Logger, POLL_TIME_IN_MS } from './internal';

type Listeners = {
init: [];
connected: [];
'webrtc:connection-impossible': [];
sending: []; // Emitted to signal the start of sending the file(s)
done: [];
'text-transferred': [text: string]; // Emitted to signal the transfer of one text TO the Host.
'text-received': [text: string]; // Emitted to signal the reception of one text FROM the Host.
disconnected: [];
error: [e: string];
};
Expand Down Expand Up @@ -49,13 +50,19 @@ export class FlottformTextInputClient extends EventEmitter<Listeners> {

sendText = (text: string) => {
// For now, I didn't handle very large texts since for most use cases the text won't exceed the size of 1 chunk ( 16KB )
this.emit('sending');
this.channel?.sendData(text);
this.emit('done');
this.emit('text-transferred', text);
};

private handleIncomingData = (e: MessageEvent) => {
// We suppose that the data received is small enough to be all included in 1 message
this.emit('text-received', e.data);
};

private registerListeners = () => {
this.channel?.on('init', () => {});
this.channel?.on('init', () => {
this.emit('init');
});
this.channel?.on('retrieving-info-from-endpoint', () => {});
this.channel?.on('sending-client-info', () => {});
this.channel?.on('connecting-to-host', () => {});
Expand All @@ -65,8 +72,11 @@ export class FlottformTextInputClient extends EventEmitter<Listeners> {
this.channel?.on('connection-impossible', () => {
this.emit('webrtc:connection-impossible');
});
this.channel?.on('receiving-data', (e) => {
this.handleIncomingData(e);
});
this.channel?.on('done', () => {
this.emit('done');
//this.emit('done');
});
this.channel?.on('disconnected', () => {
this.emit('disconnected');
Expand Down
13 changes: 9 additions & 4 deletions flottform/forms/src/flottform-text-input-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
} from './internal';

type Listeners = BaseListeners & {
done: [data: string];
'text-transferred': [text: string]; // Emitted to signal the transfer of one text TO the Client.
'text-received': [text: string]; // Emitted to signal the reception of one text FROM the Client.
'webrtc:waiting-for-text': [];
receive: [];
'webrtc:waiting-for-data': [];
};

Expand Down Expand Up @@ -76,10 +76,15 @@ export class FlottformTextInputHost extends BaseInputHost<Listeners> {
return this.qrCode;
};

sendText = (text: string) => {
// For now, I didn't handle very large texts since for most use cases the text won't exceed the size of 1 chunk ( 16KB )
this.channel?.sendData(text);
this.emit('text-transferred', text);
};

private handleIncomingData = (e: MessageEvent) => {
this.emit('receive');
// We suppose that the data received is small enough to be all included in 1 message
this.emit('done', e.data);
this.emit('text-received', e.data);
if (this.inputField) {
this.inputField.value = e.data;
const event = new Event('change');
Expand Down