-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.js
126 lines (110 loc) · 4.09 KB
/
window.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
}
var sockets = {
"recv": {
protocol: "udp",
port: 8899,
socket: null,
type: 'bind'
},
"http": {
protocol: "tcp",
port: 8080,
socket: null,
type: 'listen'
}
}
var readTimeout;
var readSocket;
var stringToUint8Array = function(string) {
var buffer = new ArrayBuffer(string.length);
var view = new Uint8Array(buffer);
for(var i = 0; i < string.length; i++) {
view[i] = string.charCodeAt(i);
}
return view;
};
var readOSC = function (data) {
chrome.socket.create('udp', {}, function(CreateInfo){
//console.log(CreateInfo);
var socketId = CreateInfo.socketId;
chrome.socket.connect(socketId, '127.0.0.1', 8898, function(result) {
// We are now connected to the socket so send it some data
if(result>=0){
chrome.socket.write(socketId, data, function(sendInfo) {
//console.log("wrote " + sendInfo);
});
}
});
});
}
/*
var writeHTTP = function(socketId, data, sockRef, callback) {
chrome.socket.getInfo(sockRef.socket, function(result){console.log("Listen socket",result);});
if(data.length > 0){
var contentType = "text/html";
var files = document.getElementById("files").files;
console.log(files);
var file = files[0];
var contentLength = file.size;
var header = stringToUint8Array("HTTP/1.0 200 OK\nContent-length: " + file.size + "\nContent-type:" + contentType + "\n\n");
var outputBuffer = new ArrayBuffer(header.byteLength + file.size);
var view = new Uint8Array(outputBuffer)
view.set(header, 0);
var fileReader = new FileReader();
fileReader.onload = function(e) {
view.set(new Uint8Array(e.target.result), header.byteLength);
console.log("Socket to write",socketId);
chrome.socket.write(socketId, outputBuffer, function(writeInfo) {
console.log("WRITE", writeInfo);
chrome.socket.disconnect(socketId);
chrome.socket.destroy(socketId);
console.log("destroyed!!", socketId, sockRef);
chrome.socket.getInfo(socketId, function(result){console.log("Destroyed socket",result);});
chrome.socket.getInfo(sockRef.socket, function(result){console.log("Listen socket",result);});
chrome.socket.accept(sockRef.socket, function(accInfo){
chrome.socket.getInfo(sockRef.socket, function(result){console.log("Listen socket",result);});
console.log("Accepting from socket.write in writeHTTP");
acceptTCP(accInfo, callback, sockRef);
});
});
};
fileReader.readAsArrayBuffer(file);
}else{
chrome.socket.accept(sockRef.socket, function(accInfo){
console.log("Accepting from else in writeHTTP");
acceptTCP(accInfo, callback, sockRef);
});
}
}*/
document.getElementById('test').addEventListener('click', function(e) {
// Create the Socket
connect(sockets['recv'], readOSC);
//connect(sockets['http'], writeHTTP);
console.log("Avail Height: "+screen.availHeight);
console.log("Avail Width: "+screen.availWidth);
console.log("Screen Height: "+screen.height);
console.log("Screen Width: "+screen.width);
console.log("outer Height: "+window.outerHeight);
console.log("outer Width: "+window.outerWidth);
var hosts = document.getElementById("hosts");
chrome.app.window.create('hero_cl/score.html?', {width: screen.width-200, height: screen.height-200});
chrome.app.window.create('hero_cl/index.html');
});
// Attempt fullscreen on window creation.
// It will fail, but hopefully some day it won't:
// http://code.google.com/p/chromium/issues/detail?id=164624
document.body.webkitRequestFullscreen();
var hosts = document.getElementById("hosts");
var socket = chrome.experimental.socket || chrome.socket;
socket.getNetworkList(function(interfaces) {
for(var i in interfaces) {
var interface = interfaces[i];
var opt = document.createElement("option");
opt.value = interface.address;
console.log(interface.address);
opt.innerText = interface.address;
hosts.appendChild(opt);
}
});