Skip to content

Commit

Permalink
mongo store servers users, and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
AdSegura committed Aug 22, 2019
1 parent 31cefe1 commit 7e73a49
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 64 deletions.
2 changes: 1 addition & 1 deletion laravel-echo-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"mongo": {
"host": "127.0.0.1",
"port": "27017",
"dbName": "presence",
"dbName": "echo",
"user": null,
"password": null
}
Expand Down
3 changes: 2 additions & 1 deletion src/channels/baseAuthChannel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Log} from "../log";
import {Logger} from "../log/logger";

let url = require('url');
const request = require('request');
Expand All @@ -22,7 +23,7 @@ export class BaseAuthChannel {
* @param options
* @param log
*/
constructor(protected options: any, protected log: any) {
constructor(protected options: any, protected log: Logger) {

this.request = request;
}
Expand Down
10 changes: 6 additions & 4 deletions src/channels/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {PresenceChannel} from './presence-channel';
import {PrivateChannel} from './private-channel';
import {Log} from './../log';
import {RootChannel} from "./rootChannel";
import {Database} from "../database";
import {Logger} from "../log/logger";

export class Channel {
/**
Expand Down Expand Up @@ -32,11 +34,11 @@ export class Channel {
/**
* Create a new channel instance.
*/
constructor(private io, private options, protected log) {
constructor(private io: any, private options: any, protected log: Logger, protected db: Database) {

this.private = new PrivateChannel(options, this.log);
this.rootChannel = new RootChannel(options, this.log);
this.presence = new PresenceChannel(io, options, this.log);
this.private = new PrivateChannel(this.options, this.log);
this.rootChannel = new RootChannel(this.options, this.log);
this.presence = new PresenceChannel(this.io, this.options, this.log, this.db);

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

Expand Down
3 changes: 2 additions & 1 deletion src/channels/commandChannel.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {IoUtils} from "../utils/ioUtils";
import {Log} from "../log";
import {Logger} from "../log/logger";

export class CommandChannel {

constructor(private options: any, protected io: any, protected log: any){
constructor(private options: any, protected io: any, protected log: Logger){

}

Expand Down
9 changes: 3 additions & 6 deletions src/channels/presence-channel.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import {Logger} from "../log/logger";

var _ = require('lodash');
import { Channel } from './channel';
import { Database } from './../database';
import { Log } from './../log';

export class PresenceChannel {
/**
* Database instance.
*/
db: Database;

/**
* Create a new Presence channel instance.
*/
constructor(private io, private options: any, protected log: any) {
this.db = new Database(this.options);
constructor(private io, private options: any, protected log: Logger, protected db: Database) {
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/channels/private-channel.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {BaseAuthChannel} from "./baseAuthChannel";
import {Logger} from "../log/logger";

export class PrivateChannel extends BaseAuthChannel {

/**
* Create a new private channel instance.
*/
constructor(protected options: any, protected log: any) {
constructor(protected options: any, protected log: Logger) {
super(options, log)
}
}
3 changes: 2 additions & 1 deletion src/channels/rootChannel.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {BaseAuthChannel} from "./baseAuthChannel";
import {Logger} from "../log/logger";

export class RootChannel extends BaseAuthChannel {

/**
* Create a new private channel instance.
*/
constructor(options: any, log: any) {
constructor(options: any, log: Logger) {
super(options, log);
}

Expand Down
21 changes: 21 additions & 0 deletions src/database/database-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
*/
export interface DatabaseDriver {

/**
* set user on new Root channel Auth connection
*/
setUserInServer(key: string, value: any): void;

/**
* Delete user from DB base on socket_id
*
* @param collection
* @param socket_id
*/
delUserInServerBySocketId(collection: string, socket_id: any): void;

/**
* get all members in channel
*/
Expand Down Expand Up @@ -45,4 +58,12 @@ export interface DatabaseDriver {
* @param sockets array, active array socketsId on Io Channel
*/
removeInactive(channel: string, sockets: any): Promise<any>;

/**
* Remove inactive sockets from this Io server
*
* @param collection
* @param sockets
*/
removeInactiveSocketsInThisServer(collection: string, sockets: any): Promise<any>;
}
17 changes: 15 additions & 2 deletions src/database/database.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DatabaseDriver } from './database-driver';
import {MongoDatabase} from "./mongo";
import {Logger} from "../log/logger";

/**
* Class that controls the key/value data store.
Expand All @@ -13,8 +14,8 @@ export class Database implements DatabaseDriver {
/**
* Create a new Mongo database instance.
*/
constructor(private options: any) {
this.driver = new MongoDatabase(this.options);
constructor(private options: any, protected log: Logger) {
this.driver = new MongoDatabase(this.options, this.log);
}


Expand Down Expand Up @@ -45,4 +46,16 @@ export class Database implements DatabaseDriver {
removeInactive(channel: string, member: any): Promise<any>{
return this.driver.removeInactive(channel, member);
}

removeInactiveSocketsInThisServer(collection: string, sockets: any): Promise<any>{
return this.driver.removeInactiveSocketsInThisServer(collection, sockets);
}

setUserInServer(collection: string, user: any): void{
return this.driver.setUserInServer(collection, user);
};

delUserInServerBySocketId(collection: string, socket_id: any): void {
return this.driver.delUserInServerBySocketId(collection, socket_id);
}
}
Loading

0 comments on commit 7e73a49

Please sign in to comment.