2017-07-10 19:08:49 +09:00

108 lines
1.6 KiB
TypeScript

import * as React from 'react';
import RaisedButton from 'material-ui/RaisedButton';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';
// import {client} from 'websocket'
const styles = {
container: {
textAlign: 'center',
paddingTop: 200,
},
};
interface MainState {
open: boolean;
}
interface Person {
name: string;
age: number;
}
let es = new WebSocket("ws://192.168.1.209:8000/echo");
es.onopen = function (event: any) {
console.log("open websocket")
let dat: any;
dat = {
"test": "fffff",
"echo": "ehochoc",
};
let mm :any;
mm = {
"message" : dat
};
es.send(JSON.stringify(mm));
};
es.onmessage = function (event:any) {
console.log(event.data);
}
var hello = (person: Person) => {
console.log(`안녕하세요! ${person.name} 입니다.`);
}
export class Main extends React.Component<any, any> {
constructor(props: any, context: any) {
super(props, context);
this.handleRequestClose = this.handleRequestClose.bind(this);
this.handleTouchTap = this.handleTouchTap.bind(this);
const p: Person = {
name: 'Mark',
age: 35
};
hello(p); // 안녕하세요! Mark 입니다.
this.state = {
open: false,
} as MainState;
}
handleRequestClose() {
this.setState({
open: false,
} as MainState);
}
handleTouchTap() {
this.setState({
open: true,
});
}
render() {
const standardActions = (
<FlatButton
label="Ok"
primary={true}
onTouchTap={this.handleRequestClose}
/>
) as any;
return (
<div></div>
);
}
}