forked from patrickfuller/camp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.js
32 lines (26 loc) · 934 Bytes
/
client.js
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
/*global $, WebSocket, console, window, document*/
"use strict";
/**
* Connects to Pi server and receives video data.
*/
var client = {
// Connects to Pi via websocket
connect: function (port) {
var self = this, video = document.getElementById("video");
this.socket = new WebSocket("ws://" + window.location.hostname + ":" + port + "/websocket");
// Request the video stream once connected
this.socket.onopen = function () {
console.log("Connected!");
self.readCamera();
};
// Currently, all returned messages are video data. However, this is
// extensible with full-spec JSON-RPC.
this.socket.onmessage = function (messageEvent) {
video.src = "data:image/jpeg;base64," + messageEvent.data;
};
},
// Requests video stream
readCamera: function () {
this.socket.send("read_camera");
}
};