wspromisify
Advanced tools
Comparing version 0.0.52 to 0.0.53
@@ -75,3 +75,3 @@ { | ||
}, | ||
"version": "0.0.52", | ||
"version": "0.0.53", | ||
"devDependencies": { | ||
@@ -78,0 +78,0 @@ "@types/node": "^8.0.58", |
# WebsocketPromisify | ||
[![Build Status](https://circleci.com/gh/houd1ni/WebsocketPromisify/tree/master.svg?style=shield)](https://circleci.com/gh/houd1ni/WebsocketPromisify/tree/master) | ||
a nice this readme version: https://houd1ni.github.io/WebsocketPromisify/ | ||
Makes websocket's API just like REST with Promise-like API, with native Promises. | ||
@@ -3,0 +8,0 @@ Has a lot of yummies and very lightweight (less than 5kb in gzip)! |
import test from 'ava' | ||
import * as specs from './specs' | ||
import mockServer from './mock' | ||
import mockServer from './mock/index' | ||
import * as _ from 'ramda' | ||
@@ -5,0 +5,0 @@ |
@@ -13,3 +13,3 @@ | ||
const getPort = (req) => +req.originalUrl.split('/')[2] || 6666 | ||
const getPort = (req) => +req.originalUrl.split('/')[2] || 40510 | ||
@@ -16,0 +16,0 @@ app.get(/\/on\/.*/, async (req, res) => { |
@@ -8,32 +8,35 @@ | ||
const createServer = async (port = 6666) => { | ||
if(mockServer[port] === undefined) { | ||
mockServer[port] = new (WS as any).Server({ port }) | ||
mockServer[port].on('connection', (socket) => { | ||
socket.on('message', (rawMessage: string): null => { | ||
const {id, data} = JSON.parse(rawMessage) | ||
// console.log(rawMessage) | ||
let response = '' | ||
if(data.shut) { | ||
socket.terminate() | ||
socket.isAlive = false | ||
socket.ping('', false, true) | ||
return null | ||
} else if(data.echo) { | ||
response = data | ||
} | ||
socket.send(JSON.stringify({ | ||
id, | ||
data: response | ||
})) | ||
return null | ||
const createServer = async (port = 40510) => { | ||
return new Promise((ff, rj) => { | ||
if(mockServer[port] === undefined) { | ||
mockServer[port] = new (WS as any).Server({ port }, () => { | ||
mockServer[port].on('connection', (socket) => { | ||
socket.on('message', (rawMessage: string): null => { | ||
const {id, data} = JSON.parse(rawMessage) | ||
let response = '' | ||
if(data.shut) { | ||
socket.terminate() | ||
socket.isAlive = false | ||
socket.ping('', false, true) | ||
return null | ||
} else if(data.echo) { | ||
response = data | ||
} | ||
socket.send(JSON.stringify({ | ||
id, | ||
data: response | ||
})) | ||
return null | ||
}) | ||
return true | ||
}) | ||
return ff(true) | ||
}) | ||
}) | ||
return true | ||
} else { | ||
return false | ||
} | ||
} else { | ||
return ff(false) | ||
} | ||
}) | ||
} | ||
const killServer = async (port = 6666) => { | ||
const killServer = async (port = 40510) => { | ||
return new Promise((ff, rj) => { | ||
@@ -40,0 +43,0 @@ if(mockServer[port]) { |
@@ -10,3 +10,3 @@ | ||
return new Promise(async (ff, rj) => { | ||
const ws = await createNew({}) | ||
const ws = await createNew({}, 40513) | ||
@@ -13,0 +13,0 @@ setTimeout(async () => { |
@@ -14,5 +14,5 @@ | ||
timeout: 500 | ||
}, 8090) | ||
}, 40512) | ||
await shutDown(8090) | ||
await shutDown(40512) | ||
@@ -19,0 +19,0 @@ setTimeout(async () => { |
import { | ||
createNew, | ||
turnOn, | ||
is | ||
@@ -13,5 +14,8 @@ } from '../utils' | ||
let done = false | ||
const existing_addr = 'ws://localhost:6666' | ||
const existing_port = 40514 | ||
const existing_addr = 'ws://localhost:' + existing_port | ||
return new Promise(async (ff, rj) => { | ||
await turnOn(existing_port) | ||
setTimeout(() => { | ||
@@ -18,0 +22,0 @@ if(!done) { |
@@ -12,4 +12,6 @@ import echo from './echo' | ||
// addresses in use: 40510 - 40514 | ||
export { | ||
once, | ||
echo, | ||
@@ -23,4 +25,3 @@ lazy, | ||
ready, | ||
once, | ||
existing_socket, | ||
} |
@@ -13,3 +13,3 @@ | ||
const reconnect = async (t) => { | ||
const port = 6667 | ||
const port = 40511 | ||
@@ -16,0 +16,0 @@ return new Promise(async (ff, rj) => { |
@@ -19,2 +19,4 @@ | ||
} | ||
return null | ||
} | ||
@@ -21,0 +23,0 @@ |
@@ -8,3 +8,3 @@ | ||
const turnOn = async (port: number) => { | ||
await axios.get('http://localhost:8085/on/' + port) | ||
await axios.get('http://127.0.0.1:8085/on/' + port) | ||
return true | ||
@@ -14,10 +14,10 @@ } | ||
const shutDown = async (port: number) => { | ||
await axios.get('http://localhost:8085/off/' + port) | ||
await axios.get('http://127.0.0.1:8085/off/' + port) | ||
return true | ||
} | ||
const createNew = async (config, port = 6666): Promise<WSP> => { | ||
const createNew = async (config, port = 40510): Promise<WSP> => { | ||
await turnOn(port) | ||
const ws = new WSP(Object.assign({ | ||
url: 'localhost:' + port, | ||
url: '127.0.0.1:' + port, | ||
adapter: (host, protocols) => new (WS as any)(host, protocols) | ||
@@ -24,0 +24,0 @@ }, config)) |
@@ -8,3 +8,3 @@ { | ||
"allowJs": true, | ||
"target": "es2017", | ||
"target": "esnext", | ||
"module": "commonjs", | ||
@@ -11,0 +11,0 @@ "outDir": "./dist" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65290
33
1406
128