-
Notifications
You must be signed in to change notification settings - Fork 9
/
index-embed.html
119 lines (95 loc) · 4.29 KB
/
index-embed.html
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
<html>
<head>
<title>Jam ! Test App(embed)</title>
<style>
.warned{
color:blue;
}
</style>
</head>
<body>
<div id='embed'>
<!--<iframe src="./?designUrl=http://www.goo.fr&meshUrl=foo&modelUrl=bar" style="width: 90%; height: 300px"
scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0">
</iframe>-->
<iframe src="./" style="width: 90%; height: 300px"
scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0"
id="embeded"
>
</iframe>
</div>
<script>
function receiveMessage(event)
{
const data = [event.data]
data
.filter(data=>data.source === "jam")
.map(function(data){
console.log("main window recieved message from Jam", data ,data.request)
})
}
window.addEventListener("message", receiveMessage, false)
var embeded = document.getElementById("embeded").contentWindow
setTimeout(function() {
console.log("load model from postMessage")
embeded.postMessage("hey yo","*")
embeded.postMessage({modelUrl:"http://localhost:3000/demo-data/UM2CableChain_BedEnd.STL"},"*")
//embeded.postMessage({designUrl:"http://localhost:3000/xxx"},"*")
}, 1000)
setTimeout(function() {
//to clear jam
embeded.postMessage({clear:true},"*")
}, 5000)
setTimeout(function() {
//to load a model
console.log("load model from postMessage")
embeded.postMessage({modelUrl:"http://localhost:3000/demo-data/UM2CableChain_BedEnd.STL"},"*")
}, 10000)
setTimeout(function() {
//to get transform data
embeded.postMessage({"getTransforms":null},"*")
}, 7000)
//test
setTimeout(function() {
//send html5 FILE object
console.log("send html5 FILE data")
var fileParts = ['<a id="a"><b id="b">hey!</b></a>']
var data = new Blob(fileParts, {type : 'text/html'})
//var dataTest = new window.File()
embeded.postMessage({dataTest:data},"*")
}, 1000)
setTimeout(function() {
//to get transform data
embeded.postMessage({getStatus:null},"*")
}, 8000)
setTimeout(function() {
embeded.postMessage({captureScreen:null},"*")
}, 9000)
setTimeout(function() {
embeded.postMessage({designId:"144"},"*")
}, 9000)
setTimeout(function() {
// base64 string (stl cube)
var base64str = "TUVTSC1NRVNILU1FU0gtTUVTSC1NRVNILU1FU0gtTUVTSC1NRVNILU1FU0gtTUVTSC1NRVNILU1FU0gtTUVTSC1NRVNILU1FU0gtTUVTSAoMAAAAAACAvwAAAIAAAACAAAAAAAAAIEEAACBBAAAAAAAAIEEAAAAAAAAAAAAAAAAAACBBAAAAAIC/AAAAAAAAAAAAAAAAAAAgQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIEEAAAAAgD8AAACAAAAAAAAAIEEAAAAAAAAgQQAAIEEAACBBAAAAAAAAIEEAACBBAAAgQQAAAACAPwAAAAAAAAAAAAAgQQAAAAAAACBBAAAgQQAAAAAAAAAAAAAgQQAAIEEAAAAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAAAAAACBBAAAAAAAAAAAAACBBAAAAAAAAIEEAAAAAAAAAAIC/AAAAAAAAAAAAAAAAAAAgQQAAAAAAAAAAAAAAAAAAIEEAAAAAAAAgQQAAAAAAAAAAgD8AAAAAAAAgQQAAIEEAACBBAAAgQQAAIEEAAAAAAAAAAAAAIEEAAAAAAAAAAAAAAACAPwAAAAAAACBBAAAgQQAAIEEAAAAAAAAgQQAAAAAAAAAAAAAgQQAAIEEAAAAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAAAAAACBBAAAAAAAAIEEAACBBAAAAAAAAAAAAAAAAAAAAAIC/AAAgQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgQQAAIEEAAAAAAAAAAAAAAAAAAAAAgD8AACBBAAAgQQAAIEEAAAAAAAAgQQAAIEEAAAAAAAAAAAAAIEEAAAAAAAAAAAAAAACAPwAAIEEAACBBAAAgQQAAAAAAAAAAAAAgQQAAIEEAAAAAAAAgQQAA";
var binary = atob(base64str.replace(/\s/g, ''))
// get binary length
var len = binary.length;
// create ArrayBuffer with binary length
var buffer = new ArrayBuffer(len)
// create 8-bit Array
var view = new Uint8Array(buffer)
// save unicode of binary data into 8-bit Array
for (var i = 0; i < len; i++) {
view[i] = binary.charCodeAt(i)
}
// create the blob object with content-type "application/pdf"
var data = new Blob( [view], { type: "application/sla" })
var file = new File([data], 'cube.stl')
embeded.postMessage({addPartData:{uuid:"8D118F05-E695-43BE-B934-D72BB11890B2",file}},"*")
}, 200)
setTimeout(function() {
embeded.postMessage({removePartData:{uuid:"8D118F05-E695-43BE-B934-D72BB11890B2"}},"*")
},2000)
</script>
</body>
</html>