mirror of
https://github.com/Cameri/nostream.git
synced 2025-07-05 12:50:38 +02:00
fix: use utf8 instead of utf-8 for ws messages
This commit is contained in:
@ -120,7 +120,7 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
|
|||||||
private async onClientMessage(raw: Buffer) {
|
private async onClientMessage(raw: Buffer) {
|
||||||
let abort: () => void
|
let abort: () => void
|
||||||
try {
|
try {
|
||||||
const message = attemptValidation(messageSchema)(JSON.parse(raw.toString('utf-8')))
|
const message = attemptValidation(messageSchema)(JSON.parse(raw.toString('utf8')))
|
||||||
|
|
||||||
const messageHandler = this.createMessageHandler([message, this]) as IMessageHandler & IAbortable
|
const messageHandler = this.createMessageHandler([message, this]) as IMessageHandler & IAbortable
|
||||||
if (typeof messageHandler.abort === 'function') {
|
if (typeof messageHandler.abort === 'function') {
|
||||||
|
@ -13,6 +13,7 @@ export const workerFactory = (): AppWorker => {
|
|||||||
const dbClient = getDbClient()
|
const dbClient = getDbClient()
|
||||||
const eventRepository = new EventRepository(dbClient)
|
const eventRepository = new EventRepository(dbClient)
|
||||||
|
|
||||||
|
// deepcode ignore HttpToHttps: <please specify a reason of ignoring this>
|
||||||
const server = http.createServer()
|
const server = http.createServer()
|
||||||
const webSocketServer = new WebSocketServer({
|
const webSocketServer = new WebSocketServer({
|
||||||
server,
|
server,
|
||||||
|
@ -158,7 +158,7 @@ export class EventRepository implements IEventRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async create(event: Event): Promise<number> {
|
public async create(event: Event): Promise<number> {
|
||||||
return this.insert(event).then(prop('rowCount') as () => number)
|
return this.insert(event).then(prop('rowCount') as () => number, () => 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private insert(event: Event) {
|
private insert(event: Event) {
|
||||||
|
@ -97,7 +97,7 @@ export async function waitForEOSE(ws: WebSocket, subscription: string): Promise<
|
|||||||
ws.once('error', onError)
|
ws.once('error', onError)
|
||||||
|
|
||||||
function onMessage(raw: RawData) {
|
function onMessage(raw: RawData) {
|
||||||
const message = JSON.parse(raw.toString('utf-8'))
|
const message = JSON.parse(raw.toString('utf8'))
|
||||||
if (message[0] === MessageType.EOSE && message[1] === subscription) {
|
if (message[0] === MessageType.EOSE && message[1] === subscription) {
|
||||||
resolve()
|
resolve()
|
||||||
cleanup()
|
cleanup()
|
||||||
@ -139,7 +139,7 @@ export async function waitForNextEvent(ws: WebSocket, subscription: string): Pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onMessage(raw: RawData) {
|
function onMessage(raw: RawData) {
|
||||||
const message = JSON.parse(raw.toString('utf-8'))
|
const message = JSON.parse(raw.toString('utf8'))
|
||||||
if (message[0] === MessageType.EVENT && message[1] === subscription) {
|
if (message[0] === MessageType.EVENT && message[1] === subscription) {
|
||||||
resolve(message[2])
|
resolve(message[2])
|
||||||
cleanup()
|
cleanup()
|
||||||
@ -172,7 +172,7 @@ export async function waitForEventCount(
|
|||||||
cleanup()
|
cleanup()
|
||||||
}
|
}
|
||||||
function onMessage(raw: RawData) {
|
function onMessage(raw: RawData) {
|
||||||
const message = JSON.parse(raw.toString('utf-8'))
|
const message = JSON.parse(raw.toString('utf8'))
|
||||||
if (message[0] === MessageType.EVENT && message[1] === subscription) {
|
if (message[0] === MessageType.EVENT && message[1] === subscription) {
|
||||||
events.push(message[2])
|
events.push(message[2])
|
||||||
if (!eose && events.length === count) {
|
if (!eose && events.length === count) {
|
||||||
@ -213,7 +213,7 @@ export async function waitForNotice(ws: WebSocket): Promise<void> {
|
|||||||
ws.once('error', onError)
|
ws.once('error', onError)
|
||||||
|
|
||||||
function onMessage(raw: RawData) {
|
function onMessage(raw: RawData) {
|
||||||
const message = JSON.parse(raw.toString('utf-8'))
|
const message = JSON.parse(raw.toString('utf8'))
|
||||||
if (message[0] === MessageType.NOTICE) {
|
if (message[0] === MessageType.NOTICE) {
|
||||||
resolve(message[1])
|
resolve(message[1])
|
||||||
cleanup()
|
cleanup()
|
||||||
|
@ -28,7 +28,7 @@ describe('webSocketAdapterFactory', () => {
|
|||||||
onStub.returns(client)
|
onStub.returns(client)
|
||||||
const request: IncomingMessage = {
|
const request: IncomingMessage = {
|
||||||
headers: {
|
headers: {
|
||||||
'sec-websocket-key': Buffer.from('key', 'utf-8').toString('base64'),
|
'sec-websocket-key': Buffer.from('key', 'utf8').toString('base64'),
|
||||||
},
|
},
|
||||||
} as any
|
} as any
|
||||||
const webSocketServerAdapter: IWebSocketServerAdapter = {} as any
|
const webSocketServerAdapter: IWebSocketServerAdapter = {} as any
|
||||||
|
Reference in New Issue
Block a user