refactor Request

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-08-04 10:05:05 +02:00
parent 1860280e49
commit df797666ec
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
2 changed files with 3 additions and 9 deletions

View File

@ -24,15 +24,10 @@ export type ReqId = string | number
/** /**
* @public * @public
*/ */
export class Request<P extends any[], M extends string = string> { export interface Request<P extends any[], M extends string = string> {
id?: ReqId id?: ReqId
method: M method: M
params: P params: P
constructor (method: M, params: P, id?: ReqId) {
this.method = method
this.params = params
}
} }
/** /**

View File

@ -14,7 +14,7 @@
// limitations under the License. // limitations under the License.
// //
import { Request, readResponse, serialize } from '@anticrm/platform' import { readResponse, serialize } from '@anticrm/platform'
import { start, _Token } from '../server' import { start, _Token } from '../server'
import { encode } from 'jwt-simple' import { encode } from 'jwt-simple'
import WebSocket from 'ws' import WebSocket from 'ws'
@ -43,7 +43,6 @@ describe('server', () => {
it('should not connect to server without token', (done) => { it('should not connect to server without token', (done) => {
const conn = new WebSocket('ws://localhost:3333/xyz') const conn = new WebSocket('ws://localhost:3333/xyz')
conn.on('error', () => { conn.on('error', () => {
console.log('error')
conn.close() conn.close()
done() done()
}) })
@ -55,7 +54,7 @@ describe('server', () => {
// const start = Date.now() // const start = Date.now()
conn.on('open', () => { conn.on('open', () => {
for (let i = 0; i < total; i++) { for (let i = 0; i < total; i++) {
conn.send(serialize(new Request('ping', [], i))) conn.send(serialize({ method: 'ping', params: [], id: i }))
} }
}) })
let received = 0 let received = 0