-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (33 loc) · 964 Bytes
/
script.js
File metadata and controls
40 lines (33 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React from 'react';
import ReactDOM from 'react-dom';
import io from 'socket.io-client';
//establish connection to server
var socket = io.connect();
//button interface for issuing commands to robot
var Videostream = React.createClass({
getInitialState: function() {
return {
imagesource: "/pic.jpg"
};
},
componentWillMount: function() {
var vstream = this;
socket.on('image', function(msg) {
var buff = msg.buffer;
var dataView = new DataView(buff);
var blob = new Blob([dataView], {type: "image/png"});
var url = URL.createObjectURL(blob);
vstream.setState({imagesource: url});
vstream.forceUpdate();
console.log('frame received');
});
},
render: function() {
var imagesource = this.state.imagesource;
return <div>
<image src={imagesource}/>
</div>
}
});
// adds buttons to DOM
ReactDOM.render(<Videostream />, document.getElementById('container'));