MCSM:WebConsole: полученые данных с websocket
This commit is contained in:
@@ -19,14 +19,14 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class FrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
|
public class FrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
|
||||||
private final Logger logger = LoggerFactory.getLogger(FrameHandler.class);
|
private final Logger logger = LoggerFactory.getLogger(FrameHandler.class);
|
||||||
private ScheduledFuture<?> sesFuture;
|
private ScheduledFuture<?> sesFuture;
|
||||||
|
private int i = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
ctx.channel().writeAndFlush(new TextWebSocketFrame("<S:channelActive>"));
|
|
||||||
|
|
||||||
ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
|
ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
|
||||||
sesFuture = ses.scheduleAtFixedRate(() -> ctx.channel().writeAndFlush(new TextWebSocketFrame("<S:ping>")),
|
sesFuture = ses.scheduleAtFixedRate(() -> ctx.channel().writeAndFlush(
|
||||||
1L, 1L, TimeUnit.SECONDS);
|
new TextWebSocketFrame(String.format("<S:ping:%d>", i++))),
|
||||||
|
500L, 1000L, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
super.channelActive(ctx);
|
super.channelActive(ctx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,21 +65,33 @@ var Tabs = React.createClass({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var WebConsole = React.createClass({
|
var WebConsole = React.createClass({
|
||||||
render: function(){return(
|
ws: null,
|
||||||
ce('div', {id: 'webconsole'},
|
/*--------------------*/
|
||||||
ce('p', null, '[19:50:18 WARN]: **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!'),
|
getInitialState: function(){return{
|
||||||
ce('p', null, '[19:50:18 WARN]: The server will make no attempt to authenticate usernames. Beware.'),
|
lines: []
|
||||||
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.'),
|
render: function(){
|
||||||
ce('p', null, '[19:50:18 INFO]: **** Beginning UUID conversion, this may take A LONG time ****'),
|
return(
|
||||||
ce('p', null, '[19:50:18 INFO]: Preparing level "voidworld"'),
|
ce('div', {id: 'webconsole', ref: 'webconsole'}, this.state.lines.map(function(line){ return ce('p', null, line); }))
|
||||||
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')
|
|
||||||
)
|
)
|
||||||
)}
|
},
|
||||||
|
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({
|
var ServerInfo = React.createClass({
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
height: 500px;
|
height: 500px;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
#webconsole p {
|
#webconsole p {
|
||||||
|
|||||||
Reference in New Issue
Block a user