-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from Psychopoulet/develop
Develop
- Loading branch information
Showing
11 changed files
with
132 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"use strict"; | ||
|
||
// deps | ||
|
||
// natives | ||
const { join } = require("path"); | ||
|
||
// locals | ||
|
||
// plugin | ||
const { Server } = require(join(__dirname, "..", "..", "..", "lib", "main.js")); | ||
|
||
// module | ||
|
||
module.exports = class ServerWithSockets extends Server { | ||
|
||
constructor (opt) { | ||
|
||
super(opt); | ||
|
||
this._onConnection = null; | ||
|
||
} | ||
|
||
_releaseWorkSpace () { | ||
|
||
return this._socketServer ? Promise.resolve().then(() => { | ||
|
||
if ("function" === typeof this._onConnection) { | ||
|
||
this._socketServer.removeListener("connection", this._onConnection); | ||
this._onConnection = null; | ||
|
||
} | ||
|
||
}) : Promise.resolve(); | ||
|
||
} | ||
|
||
socketMiddleware (server) { | ||
|
||
super.socketMiddleware(server); | ||
|
||
this._onConnection = (socket) => { | ||
|
||
socket.on("message", (payload) => { | ||
|
||
const req = JSON.parse(payload); | ||
|
||
// check plugin | ||
if ("string" === typeof req.plugin && this._Descriptor.info.title === req.plugin) { | ||
|
||
// check command (switch ?) | ||
if ("string" === typeof req.command && "ping" === req.command) { | ||
|
||
this.emit("ping"); | ||
this.push("pong", "test"); | ||
|
||
} | ||
|
||
} | ||
|
||
}); | ||
|
||
}; | ||
|
||
this._socketServer.on("connection", this._onConnection); | ||
|
||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters