Rework subscription on webapp.
ConfigHandler is more optional now.
Connection is treated as a service to be injected.
Change-Id: I7efea116fe7ebb895ffdc42aedfe0f1f7b05e874
diff --git a/aos/network/www/config_handler.ts b/aos/network/www/config_handler.ts
index ae9896c..3d20f0d 100644
--- a/aos/network/www/config_handler.ts
+++ b/aos/network/www/config_handler.ts
@@ -1,13 +1,15 @@
import {Configuration, Channel} from 'aos/configuration_generated';
import {Connect} from 'aos/network/connect_generated';
+import {Connection} from './proxy';
export class ConfigHandler {
private readonly root_div = document.getElementById('config');
private readonly tree_div;
+ private config: Configuration|null = null
- constructor(
- private readonly config: Configuration,
- private readonly dataChannel: RTCDataChannel) {
+ constructor(private readonly connection: Connection) {
+ this.connection.addConfigHandler((config) => this.handleConfig(config));
+
const show_button = document.createElement('button');
show_button.addEventListener('click', () => this.toggleConfig());
const show_text = document.createTextNode('Show/Hide Config');
@@ -18,6 +20,11 @@
this.root_div.appendChild(this.tree_div);
}
+ handleConfig(config: Configuration) {
+ this.config = config;
+ this.printConfig();
+ }
+
printConfig() {
for (const i = 0; i < this.config.channelsLength(); i++) {
const channel_div = document.createElement('div');
@@ -70,9 +77,7 @@
Connect.addChannelsToTransfer(builder, channelsfb);
const connect = Connect.endConnect(builder);
builder.finish(connect);
- const array = builder.asUint8Array();
- console.log('connect', array);
- this.dataChannel.send(array.buffer.slice(array.byteOffset));
+ this.connection.sendConnectMessage(builder);
}
toggleConfig() {