forked from smogon/pokemon-showdown
-
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.
Work in progress. I haven't written documentation for the Go code or confirmed whether this works as intended on Windows yet. This turned into a pretty substantial refactor of the Node version of sockets-related code to not only to make using Go child processes possible, but to optimize it and make unit testing of it and any code dependent on it possible to write entirely synchronously. sockets.js and sockets-workers.js are now written in Typescript, though they won't be able to be transpiled until after Config, Users, Dnsbl, and Monitor work with it as well. Fixes smogon#2943
- Loading branch information
Showing
19 changed files
with
2,312 additions
and
625 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const {Session, SockJSConnection} = require('sockjs/lib/transport'); | ||
|
||
const chars = 'abcdefghijklmnopqrstuvwxyz1234567890-'; | ||
let sessionidCount = 0; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
function generateSessionid() { | ||
let ret = ''; | ||
let idx = sessionidCount; | ||
for (let i = 0; i < 8; i++) { | ||
ret = chars[idx % chars.length] + ret; | ||
idx = idx / chars.length | 0; | ||
} | ||
sessionidCount++; | ||
return ret; | ||
} | ||
|
||
/** | ||
* @param {string} sessionid | ||
* @param {{options: {{}}} config | ||
* @return SockJSConnection | ||
*/ | ||
exports.createSocket = function (sessionid = generateSessionid(), config = {options: {}}) { | ||
let session = new Session(sessionid, config); | ||
let socket = new SockJSConnection(session); | ||
socket.remoteAddress = '127.0.0.1'; | ||
socket.protocol = 'websocket'; | ||
return socket; | ||
}; | ||
|
||
// TODO: move worker mocks here, use require('../sockets-workers').Multiplexer to stub IPC |
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.