@elice/material-runbox 1.220803.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/cjs/components/material-runbox/MaterialRunbox.d.ts +7 -0
- package/cjs/components/material-runbox/MaterialRunbox.js +44 -0
- package/cjs/components/material-runbox/MaterialRunbox.styled.d.ts +1 -0
- package/cjs/components/material-runbox/MaterialRunbox.styled.js +15 -0
- package/cjs/components/material-runbox/MaterialRunboxContent.d.ts +18 -0
- package/cjs/components/material-runbox/MaterialRunboxContent.js +305 -0
- package/cjs/components/material-runbox/MaterialRunboxContent.styled.d.ts +8 -0
- package/cjs/components/material-runbox/MaterialRunboxContent.styled.js +50 -0
- package/cjs/components/material-runbox/MaterialRunboxRunnerRoomWrapper.d.ts +6 -0
- package/cjs/components/material-runbox/MaterialRunboxRunnerRoomWrapper.js +72 -0
- package/cjs/components/material-runbox/MaterialRunboxStdioWrapper.d.ts +7 -0
- package/cjs/components/material-runbox/MaterialRunboxStdioWrapper.js +80 -0
- package/cjs/components/material-runbox/index.d.ts +2 -0
- package/cjs/components/material-runbox/locales.d.ts +15 -0
- package/cjs/components/material-runbox/locales.js +35 -0
- package/cjs/components/material-runbox/websocket.d.ts +10 -0
- package/cjs/components/material-runbox/websocket.js +20 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +9 -0
- package/es/components/material-runbox/MaterialRunbox.d.ts +7 -0
- package/es/components/material-runbox/MaterialRunbox.js +39 -0
- package/es/components/material-runbox/MaterialRunbox.styled.d.ts +1 -0
- package/es/components/material-runbox/MaterialRunbox.styled.js +7 -0
- package/es/components/material-runbox/MaterialRunboxContent.d.ts +18 -0
- package/es/components/material-runbox/MaterialRunboxContent.js +297 -0
- package/es/components/material-runbox/MaterialRunboxContent.styled.d.ts +8 -0
- package/es/components/material-runbox/MaterialRunboxContent.styled.js +38 -0
- package/es/components/material-runbox/MaterialRunboxRunnerRoomWrapper.d.ts +6 -0
- package/es/components/material-runbox/MaterialRunboxRunnerRoomWrapper.js +66 -0
- package/es/components/material-runbox/MaterialRunboxStdioWrapper.d.ts +7 -0
- package/es/components/material-runbox/MaterialRunboxStdioWrapper.js +74 -0
- package/es/components/material-runbox/index.d.ts +2 -0
- package/es/components/material-runbox/locales.d.ts +15 -0
- package/es/components/material-runbox/locales.js +30 -0
- package/es/components/material-runbox/websocket.d.ts +10 -0
- package/es/components/material-runbox/websocket.js +15 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactIntl = require('react-intl');
|
|
5
|
+
var apiClient = require('@elice/api-client');
|
|
6
|
+
var blocks = require('@elice/blocks');
|
|
7
|
+
var materialSharedUtils = require('@elice/material-shared-utils');
|
|
8
|
+
var locales = require('./locales.js');
|
|
9
|
+
var MaterialRunboxRunnerRoomWrapper = require('./MaterialRunboxRunnerRoomWrapper.js');
|
|
10
|
+
var MaterialRunbox_styled = require('./MaterialRunbox.styled.js');
|
|
11
|
+
|
|
12
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
15
|
+
|
|
16
|
+
const MaterialRunbox = ({
|
|
17
|
+
materialRunboxId,
|
|
18
|
+
locale = 'en'
|
|
19
|
+
}) => {
|
|
20
|
+
const isReady = materialSharedUtils.useMaterialConfigApiClientUpdate(apiClient.config.init);
|
|
21
|
+
|
|
22
|
+
if (!isReady) {
|
|
23
|
+
return React__default["default"].createElement(blocks.Flex, {
|
|
24
|
+
justify: "center",
|
|
25
|
+
align: "center",
|
|
26
|
+
width: "100%",
|
|
27
|
+
height: "100%"
|
|
28
|
+
}, React__default["default"].createElement(blocks.Spinner, {
|
|
29
|
+
size: "small"
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return React__default["default"].createElement(MaterialRunbox_styled.StyledMaterialRunbox, {
|
|
34
|
+
key: materialRunboxId
|
|
35
|
+
}, React__default["default"].createElement(reactIntl.IntlProvider, {
|
|
36
|
+
locale: locale,
|
|
37
|
+
defaultLocale: "en",
|
|
38
|
+
messages: locale in locales ? locales[locale] : locales.en
|
|
39
|
+
}, React__default["default"].createElement(MaterialRunboxRunnerRoomWrapper, {
|
|
40
|
+
materialRunboxId: materialRunboxId
|
|
41
|
+
})));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
module.exports = MaterialRunbox;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const StyledMaterialRunbox: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var styled = require('styled-components');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
10
|
+
|
|
11
|
+
const StyledMaterialRunbox = styled__default["default"].div.withConfig({
|
|
12
|
+
componentId: "sc-2frgib-0"
|
|
13
|
+
})(["display:flex;flex-direction:column;padding-top:0.5rem;width:100%;height:100%;background-color:#fff;"]);
|
|
14
|
+
|
|
15
|
+
exports.StyledMaterialRunbox = StyledMaterialRunbox;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare enum MaterialRunboxStatus {
|
|
3
|
+
Idle = 0,
|
|
4
|
+
Connecting = 1,
|
|
5
|
+
Loading = 2,
|
|
6
|
+
Done = 3,
|
|
7
|
+
Disconnected = 4,
|
|
8
|
+
Terminated = 5,
|
|
9
|
+
Error = 6
|
|
10
|
+
}
|
|
11
|
+
interface MaterialRunboxContentProps {
|
|
12
|
+
runboxUrl: string | null;
|
|
13
|
+
isRunboxTerminated: boolean;
|
|
14
|
+
isRunboxJoinError: boolean;
|
|
15
|
+
reconnect: () => void;
|
|
16
|
+
}
|
|
17
|
+
declare const MaterialRunboxContent: React.FC<MaterialRunboxContentProps>;
|
|
18
|
+
export default MaterialRunboxContent;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var reactIntl = require('react-intl');
|
|
7
|
+
var reactUse = require('react-use');
|
|
8
|
+
var blocks = require('@elice/blocks');
|
|
9
|
+
var icons = require('@elice/icons');
|
|
10
|
+
var websocket = require('./websocket.js');
|
|
11
|
+
var MaterialRunboxContent_styled = require('./MaterialRunboxContent.styled.js');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
16
|
+
|
|
17
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
18
|
+
exports.MaterialRunboxStatus = void 0;
|
|
19
|
+
|
|
20
|
+
(function (MaterialRunboxStatus) {
|
|
21
|
+
MaterialRunboxStatus[MaterialRunboxStatus["Idle"] = 0] = "Idle";
|
|
22
|
+
MaterialRunboxStatus[MaterialRunboxStatus["Connecting"] = 1] = "Connecting";
|
|
23
|
+
MaterialRunboxStatus[MaterialRunboxStatus["Loading"] = 2] = "Loading";
|
|
24
|
+
MaterialRunboxStatus[MaterialRunboxStatus["Done"] = 3] = "Done";
|
|
25
|
+
MaterialRunboxStatus[MaterialRunboxStatus["Disconnected"] = 4] = "Disconnected";
|
|
26
|
+
MaterialRunboxStatus[MaterialRunboxStatus["Terminated"] = 5] = "Terminated";
|
|
27
|
+
MaterialRunboxStatus[MaterialRunboxStatus["Error"] = 6] = "Error";
|
|
28
|
+
})(exports.MaterialRunboxStatus || (exports.MaterialRunboxStatus = {}));
|
|
29
|
+
|
|
30
|
+
const MaterialRunboxContent = ({
|
|
31
|
+
runboxUrl,
|
|
32
|
+
isRunboxTerminated,
|
|
33
|
+
isRunboxJoinError,
|
|
34
|
+
reconnect
|
|
35
|
+
}) => {
|
|
36
|
+
const intl = reactIntl.useIntl();
|
|
37
|
+
const [runboxStats, setRunboxStats] = React__default["default"].useState(null);
|
|
38
|
+
const [isRunboxUrlLoaded, setRunboxUrlLoaded] = React__default["default"].useState(false);
|
|
39
|
+
const isRunboxUrlLoadedPrev = reactUse.usePrevious(isRunboxUrlLoaded);
|
|
40
|
+
const [runboxStatus, setRunboxStatus] = React__default["default"].useState(exports.MaterialRunboxStatus.Idle);
|
|
41
|
+
const isRunboxPreparing = runboxStatus !== exports.MaterialRunboxStatus.Done && runboxStatus !== exports.MaterialRunboxStatus.Terminated;
|
|
42
|
+
websocket.WSMaterialRunboxStdio.useMessage(message => {
|
|
43
|
+
if (message.type === 'stats') {
|
|
44
|
+
setRunboxStats(message.data);
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
camelize: true
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const handleReconnect = () => {
|
|
51
|
+
setRunboxStats(null);
|
|
52
|
+
setRunboxUrlLoaded(false);
|
|
53
|
+
reconnect();
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleShare = async () => {
|
|
57
|
+
if (!runboxUrl) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
await navigator.clipboard.writeText(runboxUrl);
|
|
63
|
+
blocks.Notification.success(intl.formatMessage({
|
|
64
|
+
id: 'runbox.share.success'
|
|
65
|
+
}));
|
|
66
|
+
} catch (e) {
|
|
67
|
+
alert(runboxUrl);
|
|
68
|
+
}
|
|
69
|
+
}; //
|
|
70
|
+
// Change `isRunboxUrlLoaded` flag to false, when runbox url removed.
|
|
71
|
+
//
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
React__default["default"].useEffect(() => {
|
|
75
|
+
if (!runboxUrl) {
|
|
76
|
+
setRunboxUrlLoaded(false);
|
|
77
|
+
}
|
|
78
|
+
}, [runboxUrl]); //
|
|
79
|
+
// Determine runbox status.
|
|
80
|
+
//
|
|
81
|
+
|
|
82
|
+
React__default["default"].useEffect(() => {
|
|
83
|
+
setRunboxStatus((() => {
|
|
84
|
+
switch (true) {
|
|
85
|
+
case isRunboxJoinError:
|
|
86
|
+
return exports.MaterialRunboxStatus.Error;
|
|
87
|
+
|
|
88
|
+
case !runboxUrl && isRunboxTerminated:
|
|
89
|
+
return exports.MaterialRunboxStatus.Terminated;
|
|
90
|
+
|
|
91
|
+
case !runboxUrl && !isRunboxTerminated && isRunboxUrlLoadedPrev:
|
|
92
|
+
return exports.MaterialRunboxStatus.Disconnected;
|
|
93
|
+
|
|
94
|
+
case !runboxUrl && !isRunboxTerminated && !isRunboxUrlLoadedPrev:
|
|
95
|
+
return exports.MaterialRunboxStatus.Connecting;
|
|
96
|
+
|
|
97
|
+
case Boolean(runboxUrl) && !isRunboxUrlLoaded:
|
|
98
|
+
return exports.MaterialRunboxStatus.Loading;
|
|
99
|
+
|
|
100
|
+
case Boolean(runboxUrl) && isRunboxUrlLoaded:
|
|
101
|
+
return exports.MaterialRunboxStatus.Done;
|
|
102
|
+
|
|
103
|
+
default:
|
|
104
|
+
return exports.MaterialRunboxStatus.Idle;
|
|
105
|
+
}
|
|
106
|
+
})());
|
|
107
|
+
}, [isRunboxJoinError, isRunboxTerminated, isRunboxUrlLoaded, isRunboxUrlLoadedPrev, runboxUrl]);
|
|
108
|
+
/**
|
|
109
|
+
* Runbox status message shown at header.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
const renderRunboxStatusMessage = () => {
|
|
113
|
+
switch (runboxStatus) {
|
|
114
|
+
case exports.MaterialRunboxStatus.Idle:
|
|
115
|
+
return React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
116
|
+
id: "runbox.status.idle"
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
case exports.MaterialRunboxStatus.Connecting:
|
|
120
|
+
return React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
121
|
+
id: "runbox.status.connecting"
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
case exports.MaterialRunboxStatus.Loading:
|
|
125
|
+
return React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
126
|
+
id: "runbox.status.loading"
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
case exports.MaterialRunboxStatus.Done:
|
|
130
|
+
return React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
131
|
+
id: "runbox.status.done"
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
case exports.MaterialRunboxStatus.Disconnected:
|
|
135
|
+
return React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
136
|
+
id: "runbox.status.disconnected"
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
case exports.MaterialRunboxStatus.Terminated:
|
|
140
|
+
return React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
141
|
+
id: "runbox.status.terminated"
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Header of runbox.
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
const renderRunboxHeader = () => {
|
|
151
|
+
const runboxStatsInfo = runboxStats ? React__default["default"].createElement(blocks.LaptopOrLarger, null, React__default["default"].createElement(blocks.Flex, null, React__default["default"].createElement(blocks.Flex, {
|
|
152
|
+
align: "center"
|
|
153
|
+
}, React__default["default"].createElement(blocks.Text, {
|
|
154
|
+
size: "tiny",
|
|
155
|
+
lineHeight: 1.5,
|
|
156
|
+
role: "gray7",
|
|
157
|
+
bold: true
|
|
158
|
+
}, "CPU:\u00A0"), React__default["default"].createElement(blocks.Flex, {
|
|
159
|
+
align: "center",
|
|
160
|
+
width: "30px"
|
|
161
|
+
}, React__default["default"].createElement(blocks.AntProgress, {
|
|
162
|
+
type: "line",
|
|
163
|
+
percent: runboxStats.cpu.percent,
|
|
164
|
+
status: 'active',
|
|
165
|
+
showInfo: false
|
|
166
|
+
})), React__default["default"].createElement(blocks.Text, {
|
|
167
|
+
size: "tiny",
|
|
168
|
+
lineHeight: 1.5,
|
|
169
|
+
role: "gray5"
|
|
170
|
+
}, "\u00A0", `${runboxStats.cpu.percent.toFixed(0)}%`)), React__default["default"].createElement(blocks.Hspace, {
|
|
171
|
+
width: 1
|
|
172
|
+
}), React__default["default"].createElement(blocks.Flex, {
|
|
173
|
+
align: "center"
|
|
174
|
+
}, React__default["default"].createElement(blocks.Text, {
|
|
175
|
+
size: "tiny",
|
|
176
|
+
lineHeight: 1.5,
|
|
177
|
+
role: "gray7",
|
|
178
|
+
bold: true
|
|
179
|
+
}, "MEM:\u00A0"), React__default["default"].createElement(blocks.Flex, {
|
|
180
|
+
align: "center",
|
|
181
|
+
width: "30px"
|
|
182
|
+
}, React__default["default"].createElement(blocks.AntProgress, {
|
|
183
|
+
percent: runboxStats.memory.currentBytes / runboxStats.memory.limitBytes * 100,
|
|
184
|
+
status: 'active',
|
|
185
|
+
showInfo: false
|
|
186
|
+
})), React__default["default"].createElement(blocks.Text, {
|
|
187
|
+
size: "tiny",
|
|
188
|
+
lineHeight: 1.5,
|
|
189
|
+
role: "gray5"
|
|
190
|
+
}, "\u00A0", `${(runboxStats.memory.currentBytes / 1024 / 1024).toFixed(0)}M / ${(runboxStats.memory.limitBytes / 1024 / 1024).toFixed(0)}M`)), React__default["default"].createElement(blocks.Hspace, {
|
|
191
|
+
width: 1
|
|
192
|
+
}), React__default["default"].createElement(blocks.Text, {
|
|
193
|
+
size: "tiny",
|
|
194
|
+
lineHeight: 1.5,
|
|
195
|
+
role: "gray7",
|
|
196
|
+
bold: true
|
|
197
|
+
}, "DISK:\u00A0"), React__default["default"].createElement(blocks.Text, {
|
|
198
|
+
size: "tiny",
|
|
199
|
+
lineHeight: 1.5,
|
|
200
|
+
role: "gray5"
|
|
201
|
+
}, `Read ${(runboxStats.block.rxBytes / 1024 / 1024).toFixed(0)}M Write ${(runboxStats.block.txBytes / 1024 / 1024).toFixed(0)}M`), React__default["default"].createElement(blocks.Hspace, {
|
|
202
|
+
width: 1
|
|
203
|
+
}), React__default["default"].createElement(blocks.Text, {
|
|
204
|
+
size: "tiny",
|
|
205
|
+
lineHeight: 1.5,
|
|
206
|
+
role: "gray7",
|
|
207
|
+
bold: true
|
|
208
|
+
}, "NET:\u00A0"), React__default["default"].createElement(blocks.Text, {
|
|
209
|
+
size: "tiny",
|
|
210
|
+
lineHeight: 1.5,
|
|
211
|
+
role: "gray5"
|
|
212
|
+
}, `↓${(runboxStats.network.rxBytes / 1024 / 1024).toFixed(0)}M ↑${(runboxStats.network.txBytes / 1024 / 1024).toFixed(0)}M`), React__default["default"].createElement(blocks.Hspace, {
|
|
213
|
+
width: 1
|
|
214
|
+
}))) : null;
|
|
215
|
+
return React__default["default"].createElement(MaterialRunboxContent_styled.RunboxHeader, null, runboxStatsInfo, React__default["default"].createElement(blocks.Flex, {
|
|
216
|
+
align: "center"
|
|
217
|
+
}, React__default["default"].createElement(MaterialRunboxContent_styled.RunboxStatusLight, {
|
|
218
|
+
status: runboxStatus
|
|
219
|
+
}), React__default["default"].createElement(blocks.Hspace, {
|
|
220
|
+
width: 0.5
|
|
221
|
+
}), React__default["default"].createElement(blocks.Text, {
|
|
222
|
+
size: "small"
|
|
223
|
+
}, renderRunboxStatusMessage())), React__default["default"].createElement(blocks.Hspace, {
|
|
224
|
+
width: 1
|
|
225
|
+
}), React__default["default"].createElement(blocks.IconButton, {
|
|
226
|
+
icon: icons.eilShare,
|
|
227
|
+
role: "greyfb",
|
|
228
|
+
size: "small",
|
|
229
|
+
border: true,
|
|
230
|
+
disabled: isRunboxPreparing,
|
|
231
|
+
onClick: handleShare
|
|
232
|
+
}), React__default["default"].createElement(blocks.Hspace, {
|
|
233
|
+
width: 0.5
|
|
234
|
+
}), React__default["default"].createElement(blocks.Tooltip, {
|
|
235
|
+
title: isRunboxPreparing ? intl.formatMessage({
|
|
236
|
+
id: 'runbox.reloadButton.tooltip'
|
|
237
|
+
}) : undefined
|
|
238
|
+
}, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.IconButton, {
|
|
239
|
+
icon: icons.eilReset,
|
|
240
|
+
iconSpin: isRunboxPreparing,
|
|
241
|
+
role: "greyfb",
|
|
242
|
+
size: "small",
|
|
243
|
+
border: true,
|
|
244
|
+
disabled: isRunboxPreparing,
|
|
245
|
+
onClick: handleReconnect
|
|
246
|
+
}))));
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Body of runbox.
|
|
250
|
+
*/
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
const renderRunboxBody = () => {
|
|
254
|
+
if (runboxStatus === exports.MaterialRunboxStatus.Terminated) {
|
|
255
|
+
return React__default["default"].createElement(MaterialRunboxContent_styled.RunboxBody, null, React__default["default"].createElement(MaterialRunboxContent_styled.RunboxBodyOverlay, null, React__default["default"].createElement(blocks.Box, null, React__default["default"].createElement(blocks.Text, {
|
|
256
|
+
size: "small",
|
|
257
|
+
preWrap: true,
|
|
258
|
+
lineHeight: 1.5,
|
|
259
|
+
textAlign: "center"
|
|
260
|
+
}, React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
261
|
+
id: "runbox.overlay.message.terminated"
|
|
262
|
+
})))));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (runboxStatus === exports.MaterialRunboxStatus.Error) {
|
|
266
|
+
return React__default["default"].createElement(MaterialRunboxContent_styled.RunboxBody, null, React__default["default"].createElement(MaterialRunboxContent_styled.RunboxBodyOverlay, null, React__default["default"].createElement(blocks.Box, null, React__default["default"].createElement(blocks.Text, {
|
|
267
|
+
size: "small",
|
|
268
|
+
preWrap: true,
|
|
269
|
+
lineHeight: 1.5,
|
|
270
|
+
textAlign: "center"
|
|
271
|
+
}, React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
272
|
+
id: "runbox.overlay.message.error"
|
|
273
|
+
})))));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return React__default["default"].createElement(MaterialRunboxContent_styled.RunboxBody, null, React__default["default"].createElement(MaterialRunboxContent_styled.RunboxBodyOverlay, {
|
|
277
|
+
"aria-hidden": !isRunboxPreparing
|
|
278
|
+
}, React__default["default"].createElement(blocks.Box, null, React__default["default"].createElement(blocks.Spinner, null), React__default["default"].createElement(blocks.Vspace, {
|
|
279
|
+
height: 1
|
|
280
|
+
}), React__default["default"].createElement(blocks.Text, {
|
|
281
|
+
size: "small",
|
|
282
|
+
preWrap: true,
|
|
283
|
+
lineHeight: 1.5,
|
|
284
|
+
textAlign: "center"
|
|
285
|
+
}, runboxStatus === exports.MaterialRunboxStatus.Disconnected ? React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
286
|
+
id: "runbox.overlay.message.disconnected"
|
|
287
|
+
}) : React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
288
|
+
id: "runbox.overlay.message.connecting"
|
|
289
|
+
})))), runboxUrl ? React__default["default"].createElement(MaterialRunboxContent_styled.RunboxBodyIframe, {
|
|
290
|
+
src: runboxUrl + '/?folder=/mnt/elice/workspace',
|
|
291
|
+
title: "material-runbox",
|
|
292
|
+
onLoad: () => setRunboxUrlLoaded(true),
|
|
293
|
+
allow: "clipboard-read; clipboard-write"
|
|
294
|
+
}) : null);
|
|
295
|
+
}; //
|
|
296
|
+
//
|
|
297
|
+
//
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
return React__default["default"].createElement(React__default["default"].Fragment, null, renderRunboxHeader(), React__default["default"].createElement(blocks.Vspace, {
|
|
301
|
+
height: 0.5
|
|
302
|
+
}), renderRunboxBody());
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
exports["default"] = MaterialRunboxContent;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MaterialRunboxStatus } from './MaterialRunboxContent';
|
|
2
|
+
export declare const RunboxHeader: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
3
|
+
export declare const RunboxBody: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
|
+
export declare const RunboxBodyOverlay: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
|
+
export declare const RunboxBodyIframe: import("styled-components").StyledComponent<"iframe", any, {}, never>;
|
|
6
|
+
export declare const RunboxStatusLight: import("styled-components").StyledComponent<"span", any, {
|
|
7
|
+
status: MaterialRunboxStatus;
|
|
8
|
+
}, never>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var designTokens = require('@elice/design-tokens');
|
|
6
|
+
var styled = require('styled-components');
|
|
7
|
+
var MaterialRunboxContent = require('./MaterialRunboxContent.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
12
|
+
|
|
13
|
+
const RunboxHeader = styled__default["default"].div.withConfig({
|
|
14
|
+
componentId: "sc-c53ntk-0"
|
|
15
|
+
})(["flex:0 0 2.5rem;display:flex;justify-content:flex-end;align-items:center;padding:0 0.5rem;"]);
|
|
16
|
+
const RunboxBody = styled__default["default"].div.withConfig({
|
|
17
|
+
componentId: "sc-c53ntk-1"
|
|
18
|
+
})(["position:relative;flex:1;"]);
|
|
19
|
+
const RunboxBodyOverlay = styled__default["default"].div.withConfig({
|
|
20
|
+
componentId: "sc-c53ntk-2"
|
|
21
|
+
})(["position:absolute;top:0;left:0;display:flex;justify-content:center;align-items:center;flex:1;width:100%;height:100%;background:rgba(255,255,255,0.8);&[aria-hidden='true']{display:none;}"]);
|
|
22
|
+
const RunboxBodyIframe = styled__default["default"].iframe.withConfig({
|
|
23
|
+
componentId: "sc-c53ntk-3"
|
|
24
|
+
})(["width:100%;height:100%;border:none;"]);
|
|
25
|
+
const RunboxStatusLight = styled__default["default"].span.withConfig({
|
|
26
|
+
componentId: "sc-c53ntk-4"
|
|
27
|
+
})(["display:block;width:0.5rem;height:0.5rem;border-radius:50%;background-color:", ";"], props => {
|
|
28
|
+
switch (props.status) {
|
|
29
|
+
case MaterialRunboxContent.MaterialRunboxStatus.Loading:
|
|
30
|
+
case MaterialRunboxContent.MaterialRunboxStatus.Connecting:
|
|
31
|
+
return designTokens.base.color.yellow3;
|
|
32
|
+
|
|
33
|
+
case MaterialRunboxContent.MaterialRunboxStatus.Disconnected:
|
|
34
|
+
return designTokens.base.color.red7;
|
|
35
|
+
|
|
36
|
+
case MaterialRunboxContent.MaterialRunboxStatus.Done:
|
|
37
|
+
return designTokens.base.color.green7;
|
|
38
|
+
|
|
39
|
+
case MaterialRunboxContent.MaterialRunboxStatus.Idle:
|
|
40
|
+
case MaterialRunboxContent.MaterialRunboxStatus.Terminated:
|
|
41
|
+
default:
|
|
42
|
+
return designTokens.base.color.white;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
exports.RunboxBody = RunboxBody;
|
|
47
|
+
exports.RunboxBodyIframe = RunboxBodyIframe;
|
|
48
|
+
exports.RunboxBodyOverlay = RunboxBodyOverlay;
|
|
49
|
+
exports.RunboxHeader = RunboxHeader;
|
|
50
|
+
exports.RunboxStatusLight = RunboxStatusLight;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var apiClient = require('@elice/api-client');
|
|
5
|
+
var materialSharedUtils = require('@elice/material-shared-utils');
|
|
6
|
+
var MaterialRunboxStdioWrapper = require('./MaterialRunboxStdioWrapper.js');
|
|
7
|
+
var websocket = require('./websocket.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
12
|
+
|
|
13
|
+
const MaterialRunboxRunnerRoomWrapper = ({
|
|
14
|
+
materialRunboxId
|
|
15
|
+
}) => {
|
|
16
|
+
const {
|
|
17
|
+
apiWsOriginUrl
|
|
18
|
+
} = materialSharedUtils.useMaterialConfig();
|
|
19
|
+
const abortCtrlRef = React__default["default"].useRef(new AbortController());
|
|
20
|
+
const [runboxRunningId, setRunboxRunningId] = React__default["default"].useState();
|
|
21
|
+
const [isRunboxJoinError, setRunboxJoinError] = React__default["default"].useState(false);
|
|
22
|
+
const [isRunboxRunningCanceling, setRunboxRunningCanceling] = React__default["default"].useState(false);
|
|
23
|
+
/**
|
|
24
|
+
* Resolve runner room token.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const resolveRunnerRoomToken = React__default["default"].useCallback(async () => {
|
|
28
|
+
setRunboxJoinError(false);
|
|
29
|
+
abortCtrlRef.current.abort();
|
|
30
|
+
abortCtrlRef.current = new AbortController();
|
|
31
|
+
return apiClient.postOrgRunnerRoomMaterialRunboxJoin({
|
|
32
|
+
materialRunboxId
|
|
33
|
+
}, {
|
|
34
|
+
signal: abortCtrlRef.current.signal
|
|
35
|
+
}).then(res => {
|
|
36
|
+
setRunboxJoinError(false);
|
|
37
|
+
setRunboxRunningId(res.runboxRunningId);
|
|
38
|
+
return res.roomToken;
|
|
39
|
+
}).catch(err => {
|
|
40
|
+
setRunboxJoinError(true);
|
|
41
|
+
throw err;
|
|
42
|
+
});
|
|
43
|
+
}, [materialRunboxId]);
|
|
44
|
+
/**
|
|
45
|
+
* Reconnect runbox.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
const reconnectRunnerRoomWebSocket = React__default["default"].useCallback(async () => {
|
|
49
|
+
if (!runboxRunningId) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setRunboxRunningCanceling(true);
|
|
54
|
+
return apiClient.postOrgMaterialRunboxRunboxRunningCancel({
|
|
55
|
+
runboxRunningId
|
|
56
|
+
}).then(() => setRunboxRunningCanceling(false)).catch(() => setRunboxRunningCanceling(false));
|
|
57
|
+
}, [runboxRunningId]); //
|
|
58
|
+
//
|
|
59
|
+
//
|
|
60
|
+
|
|
61
|
+
return React__default["default"].createElement(websocket.WSMaterialRunboxRunnerRoom.Provider, {
|
|
62
|
+
enable: !isRunboxRunningCanceling,
|
|
63
|
+
endpoint: `${apiWsOriginUrl}/runner_room`,
|
|
64
|
+
tokenProvider: resolveRunnerRoomToken,
|
|
65
|
+
connectionTimeout: 8000
|
|
66
|
+
}, React__default["default"].createElement(MaterialRunboxStdioWrapper, {
|
|
67
|
+
isRunboxJoinError: isRunboxJoinError,
|
|
68
|
+
reconnectRunnerRoomWebSocket: reconnectRunnerRoomWebSocket
|
|
69
|
+
}));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
module.exports = MaterialRunboxRunnerRoomWrapper;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface MaterialRunboxStdioWrapperProps {
|
|
3
|
+
isRunboxJoinError: boolean;
|
|
4
|
+
reconnectRunnerRoomWebSocket: () => Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
declare const MaterialRunboxStdioWrapper: React.FC<MaterialRunboxStdioWrapperProps>;
|
|
7
|
+
export default MaterialRunboxStdioWrapper;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var MaterialRunboxContent = require('./MaterialRunboxContent.js');
|
|
5
|
+
var websocket = require('./websocket.js');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
|
+
|
|
11
|
+
const RECONNECT_DELAY = 500;
|
|
12
|
+
|
|
13
|
+
const MaterialRunboxStdioWrapper = ({
|
|
14
|
+
isRunboxJoinError,
|
|
15
|
+
reconnectRunnerRoomWebSocket
|
|
16
|
+
}) => {
|
|
17
|
+
const [roomToken, setRoomToken] = React__default["default"].useState('');
|
|
18
|
+
const [wsUri, setWsUri] = React__default["default"].useState('');
|
|
19
|
+
const [runboxUrl, setRunboxUrl] = React__default["default"].useState(null);
|
|
20
|
+
const [isRunboxTerminated, setRunboxTerminated] = React__default["default"].useState(false);
|
|
21
|
+
const {
|
|
22
|
+
close: closeRunnerRoom
|
|
23
|
+
} = websocket.WSMaterialRunboxRunnerRoom.useControls();
|
|
24
|
+
const runnerRoomWsStatus = websocket.WSMaterialRunboxRunnerRoom.useReadyState();
|
|
25
|
+
/**
|
|
26
|
+
* Reconnect runbox.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const reconnect = () => {
|
|
30
|
+
setRunboxUrl(null);
|
|
31
|
+
setRunboxTerminated(false);
|
|
32
|
+
setTimeout(() => void reconnectRunnerRoomWebSocket(), RECONNECT_DELAY);
|
|
33
|
+
}; //
|
|
34
|
+
//
|
|
35
|
+
//
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
websocket.WSMaterialRunboxRunnerRoom.useMessage(message => {
|
|
39
|
+
switch (message.type) {
|
|
40
|
+
case 'ROOM_PREPARED':
|
|
41
|
+
setRoomToken(message.data.roomToken);
|
|
42
|
+
setWsUri(message.data.forwarder.wsUri);
|
|
43
|
+
setRunboxUrl(message.data.forwarder.httpUri);
|
|
44
|
+
break;
|
|
45
|
+
|
|
46
|
+
case 'EXECUTE_DONE':
|
|
47
|
+
closeRunnerRoom();
|
|
48
|
+
setRunboxTerminated(true);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
camelize: true
|
|
53
|
+
}); //
|
|
54
|
+
// Remove runbox url, when websocket is not open state.
|
|
55
|
+
//
|
|
56
|
+
|
|
57
|
+
React__default["default"].useEffect(() => {
|
|
58
|
+
if (runnerRoomWsStatus !== WebSocket.OPEN) {
|
|
59
|
+
setRunboxUrl(null);
|
|
60
|
+
}
|
|
61
|
+
}, [runnerRoomWsStatus]); //
|
|
62
|
+
//
|
|
63
|
+
//
|
|
64
|
+
|
|
65
|
+
const isReady = Boolean(wsUri) && Boolean(roomToken);
|
|
66
|
+
return React__default["default"].createElement(websocket.WSMaterialRunboxStdio.Provider, {
|
|
67
|
+
enable: isReady,
|
|
68
|
+
endpoint: `${wsUri}/client/stdio`,
|
|
69
|
+
tokenProvider: async () => roomToken,
|
|
70
|
+
maxRetries: 5,
|
|
71
|
+
heartAttack: true
|
|
72
|
+
}, isReady ? React__default["default"].createElement(MaterialRunboxContent["default"], {
|
|
73
|
+
runboxUrl: runboxUrl,
|
|
74
|
+
isRunboxJoinError: isRunboxJoinError,
|
|
75
|
+
isRunboxTerminated: isRunboxTerminated,
|
|
76
|
+
reconnect: reconnect
|
|
77
|
+
}) : null);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
module.exports = MaterialRunboxStdioWrapper;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const en: {
|
|
2
|
+
'runbox.status.idle': string;
|
|
3
|
+
'runbox.status.connecting': string;
|
|
4
|
+
'runbox.status.loading': string;
|
|
5
|
+
'runbox.status.done': string;
|
|
6
|
+
'runbox.status.disconnected': string;
|
|
7
|
+
'runbox.status.terminated': string;
|
|
8
|
+
'runbox.reloadButton.tooltip': string;
|
|
9
|
+
'runbox.overlay.message.terminated': string;
|
|
10
|
+
'runbox.overlay.message.error': string;
|
|
11
|
+
'runbox.overlay.message.disconnected': string;
|
|
12
|
+
'runbox.overlay.message.connecting': string;
|
|
13
|
+
'runbox.share.success': string;
|
|
14
|
+
};
|
|
15
|
+
export declare const ko: typeof en;
|