import React from 'react'; import Draggable from 'react-draggable'; import PropTypes from 'prop-types'; import { withRoomContext } from '../RoomContext'; class NetworkThrottle extends React.Component { constructor(props) { super(props); this.state = { uplink : '', downlink : '', rtt : '', packetLoss : '', disabled : false }; } render() { const { uplink, downlink, rtt, packetLoss, disabled } = this.state; return (
{ event.preventDefault(); this._apply(); }} >

Network Throttle

UPLINK (kbps)

this.setState({ uplink: event.target.value })} />

DOWNLINK (kbps)

this.setState({ downlink: event.target.value })} />

RTT (ms)

this.setState({ rtt: event.target.value })} />

PACKETLOSS (%)

this.setState({ packetLoss: event.target.value })} />
); } componentWillUnmount() { const { roomClient } = this.props; roomClient.resetNetworkThrottle({ silent: true }); } async _apply() { const { roomClient, secret } = this.props; let { uplink, downlink, rtt, packetLoss } = this.state; uplink = Number(uplink) || 0; downlink = Number(downlink) || 0; rtt = Number(rtt) || 0; packetLoss = Number(packetLoss) || 0; this.setState({ disabled: true }); await roomClient.applyNetworkThrottle( { secret, uplink, downlink, rtt, packetLoss }); window.onunload = () => { roomClient.resetNetworkThrottle({ silent: true, secret }); }; this.setState({ disabled: false }); } async _reset() { const { roomClient, secret } = this.props; this.setState( { uplink : '', downlink : '', rtt : '', packetLoss : '', disabled : false }); this.setState({ disabled: true }); await roomClient.resetNetworkThrottle({ secret }); this.setState({ disabled: false }); } } NetworkThrottle.propTypes = { roomClient : PropTypes.any.isRequired, secret : PropTypes.string.isRequired }; export default withRoomContext(NetworkThrottle);