forked from parse-community/parse-server
-
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.
Implement WebSocketServer Adapter (parse-community#5866)
* Implement WebSocketServerAdapter * lint * clean up
- Loading branch information
Showing
10 changed files
with
593 additions
and
544 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/*eslint no-unused-vars: "off"*/ | ||
import { WSSAdapter } from './WSSAdapter'; | ||
const WebSocketServer = require('ws').Server; | ||
|
||
/** | ||
* Wrapper for ws node module | ||
*/ | ||
export class WSAdapter extends WSSAdapter { | ||
constructor(options: any) { | ||
super(options); | ||
const wss = new WebSocketServer({ server: options.server }); | ||
wss.on('listening', this.onListen); | ||
wss.on('connection', this.onConnection); | ||
} | ||
|
||
onListen() {} | ||
onConnection(ws) {} | ||
start() {} | ||
close() {} | ||
} | ||
|
||
export default WSAdapter; |
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,52 @@ | ||
/*eslint no-unused-vars: "off"*/ | ||
// WebSocketServer Adapter | ||
// | ||
// Adapter classes must implement the following functions: | ||
// * onListen() | ||
// * onConnection(ws) | ||
// * start() | ||
// * close() | ||
// | ||
// Default is WSAdapter. The above functions will be binded. | ||
|
||
/** | ||
* @module Adapters | ||
*/ | ||
/** | ||
* @interface WSSAdapter | ||
*/ | ||
export class WSSAdapter { | ||
/** | ||
* @param {Object} options - {http.Server|https.Server} server | ||
*/ | ||
constructor(options) { | ||
this.onListen = () => {} | ||
this.onConnection = () => {} | ||
} | ||
|
||
// /** | ||
// * Emitted when the underlying server has been bound. | ||
// */ | ||
// onListen() {} | ||
|
||
// /** | ||
// * Emitted when the handshake is complete. | ||
// * | ||
// * @param {WebSocket} ws - RFC 6455 WebSocket. | ||
// */ | ||
// onConnection(ws) {} | ||
|
||
/** | ||
* Initialize Connection. | ||
* | ||
* @param {Object} options | ||
*/ | ||
start(options) {} | ||
|
||
/** | ||
* Closes server. | ||
*/ | ||
close() {} | ||
} | ||
|
||
export default WSSAdapter; |
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
Oops, something went wrong.