Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 1 | import * as configuration from 'org_frc971/aos/configuration_generated'; |
| 2 | import * as web_proxy from 'org_frc971/aos/network/web_proxy_generated'; |
| 3 | import {Builder} from 'org_frc971/external/com_github_google_flatbuffers/ts/builder'; |
| 4 | import {ByteBuffer} from 'org_frc971/external/com_github_google_flatbuffers/ts/byte-buffer'; |
| 5 | |
James Kuszmaul | 527038a | 2020-12-21 23:40:44 -0800 | [diff] [blame] | 6 | import ChannelFb = configuration.aos.Channel; |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 7 | import Configuration = configuration.aos.Configuration; |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 8 | import Schema = configuration.reflection.Schema; |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 9 | import MessageHeader = web_proxy.aos.web_proxy.MessageHeader; |
| 10 | import WebSocketIce = web_proxy.aos.web_proxy.WebSocketIce; |
| 11 | import WebSocketMessage = web_proxy.aos.web_proxy.WebSocketMessage; |
| 12 | import Payload = web_proxy.aos.web_proxy.Payload; |
| 13 | import WebSocketSdp = web_proxy.aos.web_proxy.WebSocketSdp; |
| 14 | import SdpType = web_proxy.aos.web_proxy.SdpType; |
James Kuszmaul | 527038a | 2020-12-21 23:40:44 -0800 | [diff] [blame] | 15 | import SubscriberRequest = web_proxy.aos.web_proxy.SubscriberRequest; |
| 16 | import ChannelRequestFb = web_proxy.aos.web_proxy.ChannelRequest; |
| 17 | import TransferMethod = web_proxy.aos.web_proxy.TransferMethod; |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 18 | |
| 19 | // There is one handler for each DataChannel, it maintains the state of |
| 20 | // multi-part messages and delegates to a callback when the message is fully |
| 21 | // assembled. |
| 22 | export class Handler { |
| 23 | private dataBuffer: Uint8Array|null = null; |
| 24 | private receivedMessageLength: number = 0; |
| 25 | constructor( |
James Kuszmaul | 48413bf | 2020-09-01 19:19:05 -0700 | [diff] [blame] | 26 | private readonly handlerFunc: |
| 27 | (data: Uint8Array, sentTime: number) => void, |
Philipp Schrader | 47445a0 | 2020-11-14 17:31:04 -0800 | [diff] [blame] | 28 | private readonly channel: RTCDataChannel) { |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 29 | channel.addEventListener('message', (e) => this.handleMessage(e)); |
| 30 | } |
| 31 | |
| 32 | handleMessage(e: MessageEvent): void { |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 33 | const fbBuffer = new ByteBuffer(new Uint8Array(e.data)); |
| 34 | const messageHeader = MessageHeader.getRootAsMessageHeader( |
| 35 | fbBuffer as unknown as flatbuffers.ByteBuffer); |
James Kuszmaul | 48413bf | 2020-09-01 19:19:05 -0700 | [diff] [blame] | 36 | const time = messageHeader.monotonicSentTime().toFloat64() * 1e-9; |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 37 | // Short circuit if only one packet |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 38 | if (messageHeader.packetCount() === 1) { |
James Kuszmaul | 48413bf | 2020-09-01 19:19:05 -0700 | [diff] [blame] | 39 | this.handlerFunc(messageHeader.dataArray(), time); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 40 | return; |
| 41 | } |
| 42 | |
| 43 | if (messageHeader.packetIndex() === 0) { |
| 44 | this.dataBuffer = new Uint8Array(messageHeader.length()); |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 45 | this.receivedMessageLength = 0; |
| 46 | } |
| 47 | if (!messageHeader.dataLength()) { |
| 48 | return; |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 49 | } |
| 50 | this.dataBuffer.set( |
| 51 | messageHeader.dataArray(), |
| 52 | this.receivedMessageLength); |
| 53 | this.receivedMessageLength += messageHeader.dataLength(); |
| 54 | |
| 55 | if (messageHeader.packetIndex() === messageHeader.packetCount() - 1) { |
James Kuszmaul | 48413bf | 2020-09-01 19:19:05 -0700 | [diff] [blame] | 56 | this.handlerFunc(this.dataBuffer, time); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | } |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 60 | |
James Kuszmaul | 527038a | 2020-12-21 23:40:44 -0800 | [diff] [blame] | 61 | class Channel { |
| 62 | constructor(public readonly name: string, public readonly type: string) {} |
| 63 | key(): string { |
| 64 | return this.name + "/" + this.type; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | class ChannelRequest { |
| 69 | constructor( |
| 70 | public readonly channel: Channel, |
| 71 | public readonly transferMethod: TransferMethod) {} |
| 72 | } |
| 73 | |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 74 | // Analogous to the Connection class in //aos/network/web_proxy.h. Because most |
| 75 | // of the apis are native in JS, it is much simpler. |
| 76 | export class Connection { |
| 77 | private webSocketConnection: WebSocket|null = null; |
| 78 | private rtcPeerConnection: RTCPeerConnection|null = null; |
Philipp Schrader | 47445a0 | 2020-11-14 17:31:04 -0800 | [diff] [blame] | 79 | private dataChannel: RTCDataChannel|null = null; |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 80 | private webSocketUrl: string; |
Alex Perry | 6249aaf | 2020-02-29 14:51:49 -0800 | [diff] [blame] | 81 | |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 82 | private configInternal: Configuration|null = null; |
Alex Perry | 6249aaf | 2020-02-29 14:51:49 -0800 | [diff] [blame] | 83 | // A set of functions that accept the config to handle. |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 84 | private readonly configHandlers = new Set<(config: Configuration) => void>(); |
Alex Perry | 6249aaf | 2020-02-29 14:51:49 -0800 | [diff] [blame] | 85 | |
James Kuszmaul | 48413bf | 2020-09-01 19:19:05 -0700 | [diff] [blame] | 86 | private readonly handlerFuncs = |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 87 | new Map<string, ((data: Uint8Array, sentTime: number) => void)[]>(); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 88 | private readonly handlers = new Set<Handler>(); |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 89 | |
James Kuszmaul | 527038a | 2020-12-21 23:40:44 -0800 | [diff] [blame] | 90 | private subscribedChannels: ChannelRequest[] = []; |
| 91 | |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 92 | constructor() { |
| 93 | const server = location.host; |
| 94 | this.webSocketUrl = `ws://${server}/ws`; |
| 95 | } |
| 96 | |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 97 | addConfigHandler(handler: (config: Configuration) => void): void { |
Alex Perry | 6249aaf | 2020-02-29 14:51:49 -0800 | [diff] [blame] | 98 | this.configHandlers.add(handler); |
| 99 | } |
| 100 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 101 | /** |
James Kuszmaul | 527038a | 2020-12-21 23:40:44 -0800 | [diff] [blame] | 102 | * Add a handler for a specific message type, with reliable delivery of all |
| 103 | * messages. |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 104 | */ |
James Kuszmaul | 527038a | 2020-12-21 23:40:44 -0800 | [diff] [blame] | 105 | addReliableHandler( |
| 106 | name: string, type: string, |
| 107 | handler: (data: Uint8Array, sentTime: number) => void): void { |
| 108 | this.addHandlerImpl( |
| 109 | name, type, TransferMethod.EVERYTHING_WITH_HISTORY, handler); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Add a handler for a specific message type. |
| 114 | */ |
| 115 | addHandler( |
| 116 | name: string, type: string, |
| 117 | handler: (data: Uint8Array, sentTime: number) => void): void { |
| 118 | this.addHandlerImpl(name, type, TransferMethod.SUBSAMPLE, handler); |
| 119 | } |
| 120 | |
| 121 | addHandlerImpl( |
| 122 | name: string, type: string, method: TransferMethod, |
| 123 | handler: (data: Uint8Array, sentTime: number) => void): void { |
| 124 | const channel = new Channel(name, type); |
| 125 | const request = new ChannelRequest(channel, method); |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 126 | if (!this.handlerFuncs.has(channel.key())) { |
| 127 | this.handlerFuncs.set(channel.key(), []); |
James Kuszmaul | c4ae11c | 2020-12-26 16:26:58 -0800 | [diff] [blame^] | 128 | } else { |
| 129 | if (method == TransferMethod.EVERYTHING_WITH_HISTORY) { |
| 130 | console.warn( |
| 131 | 'Behavior of multiple reliable handlers is currently poorly ' + |
| 132 | 'defined and may not actually deliver all of the messages.'); |
| 133 | } |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 134 | } |
| 135 | this.handlerFuncs.get(channel.key()).push(handler); |
James Kuszmaul | 527038a | 2020-12-21 23:40:44 -0800 | [diff] [blame] | 136 | this.subscribeToChannel(request); |
| 137 | } |
| 138 | |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 139 | getSchema(typeName: string): Schema { |
| 140 | let schema = null; |
| 141 | const config = this.getConfig(); |
| 142 | for (let ii = 0; ii < config.channelsLength(); ++ii) { |
| 143 | if (config.channels(ii).type() === typeName) { |
| 144 | schema = config.channels(ii).schema(); |
| 145 | } |
| 146 | } |
| 147 | if (schema === null) { |
| 148 | throw new Error('Unable to find schema for ' + typeName); |
| 149 | } |
| 150 | return schema; |
| 151 | } |
| 152 | |
James Kuszmaul | 527038a | 2020-12-21 23:40:44 -0800 | [diff] [blame] | 153 | subscribeToChannel(channel: ChannelRequest): void { |
| 154 | this.subscribedChannels.push(channel); |
| 155 | if (this.configInternal === null) { |
| 156 | throw new Error( |
| 157 | 'Must call subscribeToChannel after we\'ve received the config.'); |
| 158 | } |
| 159 | const builder = new Builder(512) as unknown as flatbuffers.Builder; |
| 160 | const channels: flatbuffers.Offset[] = []; |
| 161 | for (const channel of this.subscribedChannels) { |
| 162 | const nameFb = builder.createString(channel.channel.name); |
| 163 | const typeFb = builder.createString(channel.channel.type); |
| 164 | ChannelFb.startChannel(builder); |
| 165 | ChannelFb.addName(builder, nameFb); |
| 166 | ChannelFb.addType(builder, typeFb); |
| 167 | const channelFb = ChannelFb.endChannel(builder); |
| 168 | ChannelRequestFb.startChannelRequest(builder); |
| 169 | ChannelRequestFb.addChannel(builder, channelFb); |
| 170 | ChannelRequestFb.addMethod(builder, channel.transferMethod); |
| 171 | channels.push(ChannelRequestFb.endChannelRequest(builder)); |
| 172 | } |
| 173 | |
| 174 | const channelsFb = |
| 175 | SubscriberRequest.createChannelsToTransferVector(builder, channels); |
| 176 | SubscriberRequest.startSubscriberRequest(builder); |
| 177 | SubscriberRequest.addChannelsToTransfer(builder, channelsFb); |
| 178 | const connect = SubscriberRequest.endSubscriberRequest(builder); |
| 179 | builder.finish(connect); |
| 180 | this.sendConnectMessage(builder); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 183 | connect(): void { |
| 184 | this.webSocketConnection = new WebSocket(this.webSocketUrl); |
| 185 | this.webSocketConnection.binaryType = 'arraybuffer'; |
| 186 | this.webSocketConnection.addEventListener( |
| 187 | 'open', () => this.onWebSocketOpen()); |
| 188 | this.webSocketConnection.addEventListener( |
| 189 | 'message', (e) => this.onWebSocketMessage(e)); |
| 190 | } |
| 191 | |
Alex Perry | 3dfcb81 | 2020-03-04 19:32:17 -0800 | [diff] [blame] | 192 | getConfig() { |
Philipp Schrader | 47445a0 | 2020-11-14 17:31:04 -0800 | [diff] [blame] | 193 | return this.configInternal; |
Alex Perry | 6249aaf | 2020-02-29 14:51:49 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 196 | // Handle messages on the DataChannel. Handles the Configuration message as |
| 197 | // all other messages are sent on specific DataChannels. |
James Kuszmaul | 1ec7443 | 2020-07-30 20:26:45 -0700 | [diff] [blame] | 198 | onConfigMessage(data: Uint8Array): void { |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 199 | const fbBuffer = new ByteBuffer(data); |
| 200 | this.configInternal = Configuration.getRootAsConfiguration( |
| 201 | fbBuffer as unknown as flatbuffers.ByteBuffer); |
Alex Perry | 3dfcb81 | 2020-03-04 19:32:17 -0800 | [diff] [blame] | 202 | for (const handler of Array.from(this.configHandlers)) { |
Alex Perry | 6249aaf | 2020-02-29 14:51:49 -0800 | [diff] [blame] | 203 | handler(this.configInternal); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
| 207 | onDataChannel(ev: RTCDataChannelEvent): void { |
| 208 | const channel = ev.channel; |
| 209 | const name = channel.label; |
James Kuszmaul | 5f5e123 | 2020-12-22 20:58:00 -0800 | [diff] [blame] | 210 | const handlers = this.handlerFuncs.get(name); |
| 211 | for (const handler of handlers) { |
| 212 | this.handlers.add(new Handler(handler, channel)); |
| 213 | } |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | onIceCandidate(e: RTCPeerConnectionIceEvent): void { |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 217 | if (!e.candidate) { |
| 218 | return; |
| 219 | } |
| 220 | const candidate = e.candidate; |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 221 | const builder = new Builder(512); |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 222 | const candidateString = builder.createString(candidate.candidate); |
| 223 | const sdpMidString = builder.createString(candidate.sdpMid); |
| 224 | |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 225 | const iceFb = WebSocketIce.createWebSocketIce( |
| 226 | builder as unknown as flatbuffers.Builder, candidateString, |
| 227 | sdpMidString, candidate.sdpMLineIndex); |
| 228 | const messageFb = WebSocketMessage.createWebSocketMessage( |
| 229 | builder as unknown as flatbuffers.Builder, Payload.WebSocketIce, iceFb); |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 230 | builder.finish(messageFb); |
| 231 | const array = builder.asUint8Array(); |
| 232 | this.webSocketConnection.send(array.buffer.slice(array.byteOffset)); |
| 233 | } |
| 234 | |
| 235 | // Called for new SDPs. Make sure to set it locally and remotely. |
Philipp Schrader | 47445a0 | 2020-11-14 17:31:04 -0800 | [diff] [blame] | 236 | onOfferCreated(description: RTCSessionDescriptionInit): void { |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 237 | this.rtcPeerConnection.setLocalDescription(description); |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 238 | const builder = new Builder(512); |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 239 | const offerString = builder.createString(description.sdp); |
| 240 | |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 241 | const webSocketSdp = WebSocketSdp.createWebSocketSdp( |
| 242 | builder as unknown as flatbuffers.Builder, SdpType.OFFER, offerString); |
| 243 | const message = WebSocketMessage.createWebSocketMessage( |
| 244 | builder as unknown as flatbuffers.Builder, Payload.WebSocketSdp, |
| 245 | webSocketSdp); |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 246 | builder.finish(message); |
| 247 | const array = builder.asUint8Array(); |
| 248 | this.webSocketConnection.send(array.buffer.slice(array.byteOffset)); |
| 249 | } |
| 250 | |
| 251 | // We now have a websocket, so start setting up the peer connection. We only |
| 252 | // want a DataChannel, so create it and then create an offer to send. |
| 253 | onWebSocketOpen(): void { |
| 254 | this.rtcPeerConnection = new RTCPeerConnection({}); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 255 | this.rtcPeerConnection.addEventListener( |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 256 | 'datachannel', (e) => this.onDataChannel(e)); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 257 | this.dataChannel = this.rtcPeerConnection.createDataChannel('signalling'); |
James Kuszmaul | 1ec7443 | 2020-07-30 20:26:45 -0700 | [diff] [blame] | 258 | this.handlers.add( |
| 259 | new Handler((data) => this.onConfigMessage(data), this.dataChannel)); |
Philipp Schrader | 47445a0 | 2020-11-14 17:31:04 -0800 | [diff] [blame] | 260 | // TODO(james): Is this used? Can we delete it? |
| 261 | // window.dc = this.dataChannel; |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 262 | this.rtcPeerConnection.addEventListener( |
| 263 | 'icecandidate', (e) => this.onIceCandidate(e)); |
| 264 | this.rtcPeerConnection.createOffer().then( |
| 265 | (offer) => this.onOfferCreated(offer)); |
| 266 | } |
| 267 | |
| 268 | // When we receive a websocket message, we need to determine what type it is |
| 269 | // and handle appropriately. Either by setting the remote description or |
| 270 | // adding the remote ice candidate. |
| 271 | onWebSocketMessage(e: MessageEvent): void { |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 272 | const buffer = new Uint8Array(e.data) |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 273 | const fbBuffer = new ByteBuffer(buffer); |
| 274 | const message = WebSocketMessage.getRootAsWebSocketMessage( |
| 275 | fbBuffer as unknown as flatbuffers.ByteBuffer); |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 276 | switch (message.payloadType()) { |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 277 | case Payload.WebSocketSdp: |
| 278 | const sdpFb = message.payload(new WebSocketSdp()); |
| 279 | if (sdpFb.type() !== SdpType.ANSWER) { |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 280 | console.log('got something other than an answer back'); |
| 281 | break; |
| 282 | } |
| 283 | this.rtcPeerConnection.setRemoteDescription(new RTCSessionDescription( |
| 284 | {'type': 'answer', 'sdp': sdpFb.payload()})); |
| 285 | break; |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 286 | case Payload.WebSocketIce: |
| 287 | const iceFb = message.payload(new WebSocketIce()); |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 288 | const candidate = {} as RTCIceCandidateInit; |
| 289 | candidate.candidate = iceFb.candidate(); |
| 290 | candidate.sdpMid = iceFb.sdpMid(); |
| 291 | candidate.sdpMLineIndex = iceFb.sdpMLineIndex(); |
| 292 | this.rtcPeerConnection.addIceCandidate(candidate); |
| 293 | break; |
| 294 | default: |
| 295 | console.log('got an unknown message'); |
| 296 | break; |
| 297 | } |
| 298 | } |
Alex Perry | 6249aaf | 2020-02-29 14:51:49 -0800 | [diff] [blame] | 299 | |
| 300 | /** |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 301 | * Subscribes to messages. Only the most recent connect message is in use. Any |
| 302 | * channels not specified in the message are implicitely unsubscribed. |
Alex Perry | 6249aaf | 2020-02-29 14:51:49 -0800 | [diff] [blame] | 303 | * @param a Finished flatbuffer.Builder containing a Connect message to send. |
| 304 | */ |
| 305 | sendConnectMessage(builder: any) { |
Alex Perry | 3dfcb81 | 2020-03-04 19:32:17 -0800 | [diff] [blame] | 306 | const array = builder.asUint8Array(); |
Alex Perry | 6249aaf | 2020-02-29 14:51:49 -0800 | [diff] [blame] | 307 | this.dataChannel.send(array.buffer.slice(array.byteOffset)); |
| 308 | } |
Alex Perry | b3b5079 | 2020-01-18 16:13:45 -0800 | [diff] [blame] | 309 | } |