Skip to content

Commit 7e73a49

Browse files
committed
mongo store servers users, and logs
1 parent 31cefe1 commit 7e73a49

16 files changed

+246
-64
lines changed

laravel-echo-server.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"mongo": {
2121
"host": "127.0.0.1",
2222
"port": "27017",
23-
"dbName": "presence",
23+
"dbName": "echo",
2424
"user": null,
2525
"password": null
2626
}

src/channels/baseAuthChannel.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Log} from "../log";
2+
import {Logger} from "../log/logger";
23

34
let url = require('url');
45
const request = require('request');
@@ -22,7 +23,7 @@ export class BaseAuthChannel {
2223
* @param options
2324
* @param log
2425
*/
25-
constructor(protected options: any, protected log: any) {
26+
constructor(protected options: any, protected log: Logger) {
2627

2728
this.request = request;
2829
}

src/channels/channel.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {PresenceChannel} from './presence-channel';
22
import {PrivateChannel} from './private-channel';
33
import {Log} from './../log';
44
import {RootChannel} from "./rootChannel";
5+
import {Database} from "../database";
6+
import {Logger} from "../log/logger";
57

68
export class Channel {
79
/**
@@ -32,11 +34,11 @@ export class Channel {
3234
/**
3335
* Create a new channel instance.
3436
*/
35-
constructor(private io, private options, protected log) {
37+
constructor(private io: any, private options: any, protected log: Logger, protected db: Database) {
3638

37-
this.private = new PrivateChannel(options, this.log);
38-
this.rootChannel = new RootChannel(options, this.log);
39-
this.presence = new PresenceChannel(io, options, this.log);
39+
this.private = new PrivateChannel(this.options, this.log);
40+
this.rootChannel = new RootChannel(this.options, this.log);
41+
this.presence = new PresenceChannel(this.io, this.options, this.log, this.db);
4042

4143
Log.success('Channels are ready.');
4244

src/channels/commandChannel.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {IoUtils} from "../utils/ioUtils";
22
import {Log} from "../log";
3+
import {Logger} from "../log/logger";
34

45
export class CommandChannel {
56

6-
constructor(private options: any, protected io: any, protected log: any){
7+
constructor(private options: any, protected io: any, protected log: Logger){
78

89
}
910

src/channels/presence-channel.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1+
import {Logger} from "../log/logger";
2+
13
var _ = require('lodash');
24
import { Channel } from './channel';
35
import { Database } from './../database';
46
import { Log } from './../log';
57

68
export class PresenceChannel {
7-
/**
8-
* Database instance.
9-
*/
10-
db: Database;
119

1210
/**
1311
* Create a new Presence channel instance.
1412
*/
15-
constructor(private io, private options: any, protected log: any) {
16-
this.db = new Database(this.options);
13+
constructor(private io, private options: any, protected log: Logger, protected db: Database) {
1714
}
1815

1916
/**

src/channels/private-channel.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {BaseAuthChannel} from "./baseAuthChannel";
2+
import {Logger} from "../log/logger";
23

34
export class PrivateChannel extends BaseAuthChannel {
45

56
/**
67
* Create a new private channel instance.
78
*/
8-
constructor(protected options: any, protected log: any) {
9+
constructor(protected options: any, protected log: Logger) {
910
super(options, log)
1011
}
1112
}

src/channels/rootChannel.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {BaseAuthChannel} from "./baseAuthChannel";
2+
import {Logger} from "../log/logger";
23

34
export class RootChannel extends BaseAuthChannel {
45

56
/**
67
* Create a new private channel instance.
78
*/
8-
constructor(options: any, log: any) {
9+
constructor(options: any, log: Logger) {
910
super(options, log);
1011
}
1112

src/database/database-driver.ts

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
*/
44
export interface DatabaseDriver {
55

6+
/**
7+
* set user on new Root channel Auth connection
8+
*/
9+
setUserInServer(key: string, value: any): void;
10+
11+
/**
12+
* Delete user from DB base on socket_id
13+
*
14+
* @param collection
15+
* @param socket_id
16+
*/
17+
delUserInServerBySocketId(collection: string, socket_id: any): void;
18+
619
/**
720
* get all members in channel
821
*/
@@ -45,4 +58,12 @@ export interface DatabaseDriver {
4558
* @param sockets array, active array socketsId on Io Channel
4659
*/
4760
removeInactive(channel: string, sockets: any): Promise<any>;
61+
62+
/**
63+
* Remove inactive sockets from this Io server
64+
*
65+
* @param collection
66+
* @param sockets
67+
*/
68+
removeInactiveSocketsInThisServer(collection: string, sockets: any): Promise<any>;
4869
}

src/database/database.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DatabaseDriver } from './database-driver';
22
import {MongoDatabase} from "./mongo";
3+
import {Logger} from "../log/logger";
34

45
/**
56
* Class that controls the key/value data store.
@@ -13,8 +14,8 @@ export class Database implements DatabaseDriver {
1314
/**
1415
* Create a new Mongo database instance.
1516
*/
16-
constructor(private options: any) {
17-
this.driver = new MongoDatabase(this.options);
17+
constructor(private options: any, protected log: Logger) {
18+
this.driver = new MongoDatabase(this.options, this.log);
1819
}
1920

2021

@@ -45,4 +46,16 @@ export class Database implements DatabaseDriver {
4546
removeInactive(channel: string, member: any): Promise<any>{
4647
return this.driver.removeInactive(channel, member);
4748
}
49+
50+
removeInactiveSocketsInThisServer(collection: string, sockets: any): Promise<any>{
51+
return this.driver.removeInactiveSocketsInThisServer(collection, sockets);
52+
}
53+
54+
setUserInServer(collection: string, user: any): void{
55+
return this.driver.setUserInServer(collection, user);
56+
};
57+
58+
delUserInServerBySocketId(collection: string, socket_id: any): void {
59+
return this.driver.delUserInServerBySocketId(collection, socket_id);
60+
}
4861
}

0 commit comments

Comments
 (0)