mirror of
https://github.com/reanimate/reanimate.git
synced 2026-09-14 09:32:22 +00:00
Deploying to gh-pages from @ ce6ea17c57 🚀
This commit is contained in:
parent
663be49dfe
commit
dfdfc87c23
13 changed files with 7239 additions and 0 deletions
44
playground/playground.js
Normal file
44
playground/playground.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
function playgroundInit(elt) {
|
||||
var mySockets = {};
|
||||
|
||||
function sendSocketCommand(wat) {
|
||||
if (wat.cmd == "connect") {
|
||||
socket = new WebSocket(wat.address);
|
||||
socket.onopen = function (event) {
|
||||
app.ports.receiveSocketMsg.send({
|
||||
name: wat.name,
|
||||
msg: "data",
|
||||
data: "connection established"
|
||||
});
|
||||
}
|
||||
socket.onmessage = function (event) {
|
||||
app.ports.receiveSocketMsg.send({
|
||||
name: wat.name,
|
||||
msg: "data",
|
||||
data: event.data
|
||||
});
|
||||
}
|
||||
connectionFailedHandler = function (event) {
|
||||
app.ports.receiveSocketMsg.send({
|
||||
name: wat.name,
|
||||
msg: "data",
|
||||
data: "connection failed"
|
||||
});
|
||||
}
|
||||
socket.onerror = connectionFailedHandler;
|
||||
socket.onclose = connectionFailedHandler;
|
||||
mySockets[wat.name] = socket;
|
||||
} else if (wat.cmd == "send") {
|
||||
mySockets[wat.name].send(wat.content);
|
||||
} else if (wat.cmd == "close") {
|
||||
mySockets[wat.name].close();
|
||||
delete mySockets[wat.name];
|
||||
}
|
||||
}
|
||||
|
||||
var app = Elm.Main.init({
|
||||
node: document.getElementById(elt)
|
||||
});
|
||||
app.ports.sendSocketCommand.subscribe(sendSocketCommand);
|
||||
return app;
|
||||
}
|
||||
Loading…
Reference in a new issue