import React, {Component} from 'react'; import './ConnectionContent.scss'; import {Dropdown, Button} from 'react-bootstrap'; import axios from 'axios'; class ConnectionContent extends Component { constructor(props) { super(props); this.state = { loading: false, connectionContent: null, format: "default", decoded: false, }; this.validFormats = ["default", "hex", "hexdump", "base32", "base64", "ascii", "binary", "decimal", "octal"]; this.setFormat = this.setFormat.bind(this); } componentDidUpdate(prevProps, prevState, snapshot) { if (this.props.connection !== null && ( this.props.connection !== prevProps.connection || this.state.format !== prevState.format)) { this.setState({loading: true}); // TODO: limit workaround. axios.get(`/api/streams/${this.props.connection.id}?format=${this.state.format}&limit=999999`).then(res => { this.setState({ connectionContent: res.data, loading: false }); }); } } setFormat(format) { if (this.validFormats.includes(format)) { this.setState({format: format}); } } toggleDecoded() { this.setState({decoded: !this.state.decoded}); } render() { let content = this.state.connectionContent; if (content === null) { return
nope
; } let payload = content.map((c, i) => {c.from_client ?
{c.content}
: <> {c.decoded_content ? <>
{c.content}
{c.decoded_content}
:
{c.content}
} }
); return (
format plain hex hexdump base32 base64 ascii binary decimal octal
{payload}
); } } export default ConnectionContent;