MCSM:WebConsole: полученые данных с websocket
This commit is contained in:
@@ -19,14 +19,14 @@ import java.util.concurrent.TimeUnit;
|
||||
public class FrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
|
||||
private final Logger logger = LoggerFactory.getLogger(FrameHandler.class);
|
||||
private ScheduledFuture<?> sesFuture;
|
||||
private int i = 1;
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
ctx.channel().writeAndFlush(new TextWebSocketFrame("<S:channelActive>"));
|
||||
|
||||
ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
|
||||
sesFuture = ses.scheduleAtFixedRate(() -> ctx.channel().writeAndFlush(new TextWebSocketFrame("<S:ping>")),
|
||||
1L, 1L, TimeUnit.SECONDS);
|
||||
sesFuture = ses.scheduleAtFixedRate(() -> ctx.channel().writeAndFlush(
|
||||
new TextWebSocketFrame(String.format("<S:ping:%d>", i++))),
|
||||
500L, 1000L, TimeUnit.MILLISECONDS);
|
||||
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@@ -65,21 +65,33 @@ var Tabs = React.createClass({
|
||||
});
|
||||
|
||||
var WebConsole = React.createClass({
|
||||
render: function(){return(
|
||||
ce('div', {id: 'webconsole'},
|
||||
ce('p', null, '[19:50:18 WARN]: **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!'),
|
||||
ce('p', null, '[19:50:18 WARN]: The server will make no attempt to authenticate usernames. Beware.'),
|
||||
ce('p', null, '[19:50:18 WARN]: While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.'),
|
||||
ce('p', null, '[19:50:18 WARN]: To change this, set "online-mode" to "true" in the server.properties file.'),
|
||||
ce('p', null, '[19:50:18 INFO]: **** Beginning UUID conversion, this may take A LONG time ****'),
|
||||
ce('p', null, '[19:50:18 INFO]: Preparing level "voidworld"'),
|
||||
ce('p', null, '[19:50:18 INFO]: -------- World Settings For [voidworld] --------'),
|
||||
ce('p', null, '[19:50:18 INFO]: Arrow Despawn Rate: 1200'),
|
||||
ce('p', null, '[19:50:18 INFO]: Item Merge Radius: 2.5'),
|
||||
ce('p', null, '[19:50:18 INFO]: Item Despawn Rate: 6000'),
|
||||
ce('p', null, '[19:50:18 INFO]: Allow Zombie Pigmen to spawn from portal blocks: true')
|
||||
ws: null,
|
||||
/*--------------------*/
|
||||
getInitialState: function(){return{
|
||||
lines: []
|
||||
}},
|
||||
render: function(){
|
||||
return(
|
||||
ce('div', {id: 'webconsole', ref: 'webconsole'}, this.state.lines.map(function(line){ return ce('p', null, line); }))
|
||||
)
|
||||
)}
|
||||
},
|
||||
componentDidMount: function(){
|
||||
var _this = this;
|
||||
|
||||
this.ws = new WebSocket("ws://127.0.0.1:8770"); //FIXME указывать ip:port из настроек
|
||||
this.ws.onopen = function(){ console.debug('WS: open...'); };
|
||||
this.ws.onclose = function(){ console.debug('WS: close...'); };
|
||||
this.ws.onmessage = function(event){
|
||||
console.debug('WS: message: '+event.data);
|
||||
_this.setState({ lines: _this.state.lines.concat([event.data]) });
|
||||
};
|
||||
},
|
||||
componentDidUpdate: function() {
|
||||
// this.refs.webconsole.scrollTop = this.refs.webconsole.scrollHeight;
|
||||
},
|
||||
componentWillUnmount: function(){
|
||||
this.ws.close();
|
||||
}
|
||||
});
|
||||
|
||||
var ServerInfo = React.createClass({
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
height: 500px;
|
||||
padding: 8px;
|
||||
font-family: monospace;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
#webconsole p {
|
||||
|
||||
Reference in New Issue
Block a user