summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-06-09 01:03:54 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-06-09 01:03:54 +0900
commit4e5545af384f610a56b3d19ea73c3b801b0be6c6 (patch)
tree4cd0b12e891bd1d8991ac4ad14cbbb7af83a0aee /src/api
parentv2038 (diff)
downloadsharkey-4e5545af384f610a56b3d19ea73c3b801b0be6c6.tar.gz
sharkey-4e5545af384f610a56b3d19ea73c3b801b0be6c6.tar.bz2
sharkey-4e5545af384f610a56b3d19ea73c3b801b0be6c6.zip
nanka iroiro
Diffstat (limited to 'src/api')
-rw-r--r--src/api/stream/server.ts20
-rw-r--r--src/api/streaming.ts6
2 files changed, 26 insertions, 0 deletions
diff --git a/src/api/stream/server.ts b/src/api/stream/server.ts
new file mode 100644
index 0000000000..6de5337499
--- /dev/null
+++ b/src/api/stream/server.ts
@@ -0,0 +1,20 @@
+import * as websocket from 'websocket';
+import Xev from 'xev';
+
+const ev = new Xev();
+
+export default function homeStream(request: websocket.request, connection: websocket.connection): void {
+ const onStats = stats => {
+ connection.send(JSON.stringify({
+ type: 'stats',
+ body: stats
+ }));
+ };
+
+ ev.addListener('stats', onStats);
+
+ connection.on('close', () => {
+ console.log('yooo');
+ ev.removeListener('stats', onStats);
+ });
+}
diff --git a/src/api/streaming.ts b/src/api/streaming.ts
index e1d79481d3..c71132100c 100644
--- a/src/api/streaming.ts
+++ b/src/api/streaming.ts
@@ -8,6 +8,7 @@ import isNativeToken from './common/is-native-token';
import homeStream from './stream/home';
import messagingStream from './stream/messaging';
+import serverStream from './stream/server';
module.exports = (server: http.Server) => {
/**
@@ -20,6 +21,11 @@ module.exports = (server: http.Server) => {
ws.on('request', async (request) => {
const connection = request.accept();
+ if (request.resourceURL.pathname === '/server') {
+ serverStream(request, connection);
+ return;
+ }
+
const user = await authenticate(connection, request.resourceURL.query.i);
if (user == null) {