websocket stuff

This commit is contained in:
Martin Donnelly 2016-02-17 11:52:09 +00:00
parent 326b27499f
commit 77b4591054
3 changed files with 103 additions and 31 deletions

View File

@ -3,8 +3,8 @@
<component name="ChangeListManager">
<list default="true" id="8a985735-5aff-47ce-a55f-2957d4f9c5f9" name="Default" comment="should render page now">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/package.json" afterPath="$PROJECT_DIR$/package.json" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/routes/temp.js" afterPath="$PROJECT_DIR$/routes/temp.js" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/views/temp.ejs" afterPath="$PROJECT_DIR$/views/temp.ejs" />
</list>
<ignored path="silvrapi.iws" />
<ignored path=".idea/workspace.xml" />
@ -28,8 +28,8 @@
<file leaf-file-name="temp.ejs" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/views/temp.ejs">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-14.0">
<caret line="21" column="31" selection-start-line="21" selection-start-column="31" selection-end-line="21" selection-end-column="31" />
<state vertical-scroll-proportion="-7.0">
<caret line="104" column="42" selection-start-line="104" selection-start-column="42" selection-end-line="104" selection-end-column="42" />
<folding />
</state>
</provider>
@ -48,8 +48,8 @@
<file leaf-file-name="temp.js" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/routes/temp.js">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.36183205">
<caret line="146" column="18" selection-start-line="146" selection-start-column="18" selection-end-line="146" selection-end-column="18" />
<state vertical-scroll-proportion="0.5980861">
<caret line="176" column="43" selection-start-line="176" selection-start-column="43" selection-end-line="176" selection-end-column="43" />
<folding />
</state>
</provider>
@ -462,18 +462,6 @@
<option name="number" value="Default" />
<updated>1447021065296</updated>
</task>
<task id="LOCAL-00001" summary="Initial Commit&#10;">
<created>1447023017687</created>
<option name="number" value="00001" />
<option name="project" value="LOCAL" />
<updated>1447023017687</updated>
</task>
<task id="LOCAL-00002" summary="Initial Commit&#10;">
<created>1447030070358</created>
<option name="number" value="00002" />
<option name="project" value="LOCAL" />
<updated>1447030070358</updated>
</task>
<task id="LOCAL-00003" summary="debugging">
<created>1447055263421</created>
<option name="number" value="00003" />
@ -738,7 +726,37 @@
<option name="project" value="LOCAL" />
<updated>1455705443426</updated>
</task>
<option name="localTasksCounter" value="47" />
<task id="LOCAL-00047" summary="should render page now">
<created>1455707085360</created>
<option name="number" value="00047" />
<option name="project" value="LOCAL" />
<updated>1455707085360</updated>
</task>
<task id="LOCAL-00048" summary="socket stuff">
<created>1455707397224</created>
<option name="number" value="00048" />
<option name="project" value="LOCAL" />
<updated>1455707397225</updated>
</task>
<task id="LOCAL-00049" summary="should render page now">
<created>1455707426616</created>
<option name="number" value="00049" />
<option name="project" value="LOCAL" />
<updated>1455707426616</updated>
</task>
<task id="LOCAL-00050" summary="socket stuff">
<created>1455707818885</created>
<option name="number" value="00050" />
<option name="project" value="LOCAL" />
<updated>1455707818938</updated>
</task>
<task id="LOCAL-00051" summary="should render page now">
<created>1455708009465</created>
<option name="number" value="00051" />
<option name="project" value="LOCAL" />
<updated>1455708009465</updated>
</task>
<option name="localTasksCounter" value="52" />
<servers />
</component>
<component name="ToolWindowManager">
@ -751,7 +769,7 @@
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Version Control" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2614108" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2614108" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.47095436" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32823366" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
@ -793,6 +811,7 @@
<MESSAGE value="blah" />
<MESSAGE value="blah&#10;" />
<MESSAGE value="modified to use events, hopefully will fix the crashing particle" />
<MESSAGE value="socket stuff" />
<MESSAGE value="should render page now" />
<option name="LAST_COMMIT_MESSAGE" value="should render page now" />
</component>
@ -1183,14 +1202,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/views/temp.ejs">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-14.0">
<caret line="21" column="31" selection-start-line="21" selection-start-column="31" selection-end-line="21" selection-end-column="31" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/newapp.js">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-5.206897">
@ -1199,10 +1210,18 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/views/temp.ejs">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-7.0">
<caret line="104" column="42" selection-start-line="104" selection-start-column="42" selection-end-line="104" selection-end-column="42" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/routes/temp.js">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.36183205">
<caret line="146" column="18" selection-start-line="146" selection-start-column="18" selection-end-line="146" selection-end-column="18" />
<state vertical-scroll-proportion="0.5980861">
<caret line="176" column="43" selection-start-line="176" selection-start-column="43" selection-end-line="176" selection-end-column="43" />
<folding />
</state>
</provider>

View File

@ -174,7 +174,7 @@ wsServer.on('request', function (request) {
return;
}
var connection = request.accept('', request.origin);
var connection = request.accept('stream', request.origin);
logger.debug((new Date()) + ' Connection accepted.');
var sendSocketHandler = (obj) => {
@ -199,4 +199,4 @@ wsServer.on('request', function (request) {
logger.debug((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
busEmitter.removeListener('sendSocket', sendSocketHandler);
});
});;
});;;

View File

@ -95,6 +95,59 @@
}
);
(function () {
console.log('Starting socket?');
var url = "ws://api.silvrtree.co.uk:8085";
var wsCtor = window['MozWebSocket'] ? MozWebSocket : WebSocket;
this.socket = new wsCtor(url, 'stream');
this.handleData = function(d) {
switch(d.id) {
case 'LightingDataReceived':
// this.updateLighting(d.sensorData.d);
break;
case 'ProjectorDataReceived':
// this.updateProj(d.sensorData.d);
break;
case 'HeatingDataReceived':
break;
default:
}
};
this.handleWebsocketMessage = function (message) {
try {
var command = JSON.parse(message.data);
}
catch (e) { /* do nothing */
}
if (command) {
//this.dispatchCommand(command);
this.handleData(command);
}
};
this.handleWebsocketClose = function () {
alert("WebSocket Connection Closed.");
};
this.socket.onmessage = this.handleWebsocketMessage.bind(this);
this.socket.onclose = this.handleWebsocketClose.bind(this);
})();
</script>
</body>