Skip to content

Commit 659e27e

Browse files
author
edencoder
committed
amend issues
1 parent 58bf9a7 commit 659e27e

File tree

5 files changed

+802
-4182
lines changed

5 files changed

+802
-4182
lines changed

bundles/socket/daemons/socket.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11

22
// Require dependencies
33
import uuid from 'uuid';
4-
import fetch from 'node-fetch';
54
import config from 'config';
65
import Daemon from 'daemon';
76
import session from 'express-session';
87
import socketio from 'socket.io';
98
import SessionStore from '@edenjs/session-store';
109
import cookieParser from 'cookie-parser';
1110

12-
// Require cache dependencies
13-
const calls = cache('calls');
14-
1511
// require models
1612
const User = model('user');
1713

@@ -23,6 +19,7 @@ const aclHelper = helper('user/acl');
2319
*
2420
* @cluster front
2521
* @cluster socket
22+
* @priority 1000
2623
*/
2724
export default class SocketDaemon extends Daemon {
2825
/**
@@ -75,6 +72,11 @@ export default class SocketDaemon extends Daemon {
7572
* Build chat daemon
7673
*/
7774
build() {
75+
// initializing
76+
this.logger.log('info', 'initializing socket.io', {
77+
class : this.constructor.name
78+
});
79+
7880
// Set io
7981
this.__socketIO = socketio(this.eden.router.app.server);
8082

@@ -318,19 +320,26 @@ export default class SocketDaemon extends Daemon {
318320
// Reload user
319321
if (user) await user.refresh();
320322

321-
// Loop endpoints
322-
const matched = calls.filter((call) => {
323-
// Remove call
324-
return data.name === call.path;
323+
// load calls
324+
let call = null;
325+
const ctrl = Object.values(this.eden.get('controllers')).find((ctrl) => {
326+
// return found
327+
const subCall = ctrl.calls.find((c) => c.path === data.name);
328+
329+
// set call
330+
if (subCall) call = subCall;
331+
332+
// return sub call
333+
return subCall;
325334
});
326335

327-
// Loop matched
328-
matched.forEach(async (call) => {
336+
// run function
337+
if (ctrl) {
329338
// check ACL
330339
if (call.acl && !await aclHelper.validate(user, call.acl)) return;
331340

332341
// get controller
333-
const controller = await this.eden.controller(call.file);
342+
const controller = this.eden.get(`controller.${ctrl.data.file}`);
334343

335344
// Set opts
336345
const opts = {
@@ -346,11 +355,11 @@ export default class SocketDaemon extends Daemon {
346355
await this.eden.hook('socket.call.opts', opts);
347356

348357
// Run endpoint
349-
const response = await controller[call.fn].apply(controller, [...data.args, opts]);
358+
const response = await controller[call.fn](...data.args, opts);
350359

351360
// Return response
352361
socket.emit(data.id, response);
353-
});
362+
}
354363
}
355364

356365
/**
@@ -383,7 +392,6 @@ export default class SocketDaemon extends Daemon {
383392
// create faux request and response
384393
let req = { ...socket.request };
385394
let res = { ...socket.request.res, send : (data, code = 200) => {
386-
console.log('send', data);
387395
// await text
388396
socket.emit(data.id, code, JSON.stringify(data));
389397
}, end : (data, code = 200) => {

config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const config = {};
2+
3+
config.frontend = {
4+
riot : {
5+
include : {
6+
socket : 'socket/public/js/bootstrap', // Include socket module
7+
},
8+
},
9+
};
10+
11+
module.exports = config;

edenconfig.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)