Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/app/connection-info.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Modal } from "antd";6import { FormattedMessage, useIntl } from "react-intl";78import { Button, Col, Row } from "@cocalc/frontend/antd-bootstrap";9import {10React,11useActions,12useTypedRedux,13} from "@cocalc/frontend/app-framework";14import { Icon } from "@cocalc/frontend/components";15import { labels } from "@cocalc/frontend/i18n";16import { webapp_client } from "@cocalc/frontend/webapp-client";17import { COLORS } from "@cocalc/util/theme";1819export const ConnectionInfo: React.FC = React.memo(() => {20const intl = useIntl();2122const ping = useTypedRedux("page", "ping");23const avgping = useTypedRedux("page", "avgping");24const status = useTypedRedux("page", "connection_status");25const hub = useTypedRedux("account", "hub");26const page_actions = useActions("page");2728function close() {29page_actions.show_connection(false);30}3132return (33<Modal34width={900}35open36onCancel={close}37onOk={close}38title={39<>40<Icon name="wifi" style={{ marginRight: "1em" }} />{" "}41{intl.formatMessage(labels.connection)}42</>43}44>45<div>46{ping ? (47<Row>48<Col sm={3}>49<h4>50<FormattedMessage51id="connection-info.ping"52defaultMessage="Ping time"53description={"Ping how long a server takes to respond"}54/>55</h4>56</Col>57<Col sm={6}>58<pre>59<FormattedMessage60id="connection-info.ping_info"61defaultMessage="{avgping}ms (latest: {ping}ms)"62description={63"Short string stating the average and the most recent ping in milliseconds."64}65values={{ avgping, ping }}66/>67</pre>68</Col>69</Row>70) : undefined}71<Row>72<Col sm={3}>73<h4>74<FormattedMessage75id="connection-info.hub_server"76defaultMessage="Hub server"77description={"Ping how long a server takes to respond"}78/>79</h4>80</Col>81<Col sm={6}>82<pre>{hub != null ? hub : "Not signed in"}</pre>83</Col>84<Col sm={2}>85<Button onClick={webapp_client.hub_client.fix_connection}>86<Icon name="repeat" spin={status === "connecting"} />{" "}87{intl.formatMessage(labels.reconnect)}88</Button>89</Col>90</Row>91<Row>92<Col sm={3}>93<h4>{intl.formatMessage(labels.message_plural, { num: 10 })}</h4>94</Col>95<Col sm={6}>96<MessageInfo />97</Col>98</Row>99</div>100</Modal>101);102});103104function bytes_to_str(bytes: number): string {105const x = Math.round(bytes / 1000);106if (x < 1000) {107return x + "K";108}109return x / 1000 + "M";110}111112const MessageInfo: React.FC = React.memo(() => {113const intl = useIntl();114115const info = useTypedRedux("account", "mesg_info");116117if (info == null) {118return <span></span>;119}120121function messages(num: number): string {122return `${num} ${intl.formatMessage(labels.message_plural, { num })}`;123}124125const sent = intl.formatMessage({126id: "connection-info.messages_sent",127defaultMessage: "sent",128description: "Messages sent",129});130131const received = intl.formatMessage({132id: "connection-info.messages_received",133defaultMessage: "received",134description: "Messages received",135});136137return (138<div>139<pre>140{messages(info.get("sent"))} {sent} (141{bytes_to_str(info.get("sent_length"))})142<br />143{messages(info.get("recv"))} {received} (144{bytes_to_str(info.get("recv_length"))})145<br />146<span147style={148info.get("count") > 0149? { color: "#08e", fontWeight: "bold" }150: undefined151}152>153{messages(info.get("count"))} in flight154</span>155<br />156{messages(info.get("enqueued"))} queued to send157</pre>158<div style={{ color: COLORS.GRAY_M }}>159<FormattedMessage160id="connection-info.info"161defaultMessage={`Connection icon color changes as the number of messages in flight to a hub increases.162Usually, no action is needed, but the counts are helpful for diagnostic purposes.163The maximum number of messages that can be sent at the same time is {max}.`}164values={{ max: info.get("max_concurrent") }}165/>166</div>167</div>168);169});170171172