Skip to content

Commit

Permalink
fix: boolean typo and disable keepalive
Browse files Browse the repository at this point in the history
  • Loading branch information
starknt committed May 21, 2023
1 parent fbf9837 commit 0f2b5c3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
10 changes: 5 additions & 5 deletions scripts/g-cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ tcp.on('msg', (msg) => {

// tcp.on('heartbeat', o => console.error('当前人气: ', o))
// tcp.on('WATCHED_CHANGE', ({ data }) => console.error(data.data.num, '人看过直播'))
// tcp.on('DANMU_MSG', ({ data }) => {
// console.log(data)
// })
tcp.on('DANMU_MSG', ({ data }) => {
console.log(data)
})
tcp.on('error', console.error)
tcp.on('close', () => {
console.log('退出直播间')
tcp.on('close', (e) => {
console.log('退出直播间', e)
})
3 changes: 0 additions & 3 deletions src/base/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ export class LiveClient<E extends Record<EventKey, any>> extends EventEmitter<Me
this.on(CLOSE_EVENT, (e) => {
// @ts-expect-error close event
this.emit('close', e)

if (this.options.keepalive)
this.socket.reconnect()
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/base/eventemitter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EventEmitter } from './eventemitter'

describe('EventEmitter', () => {
test('Basic test case', () => {
const emitter = new EventEmitter()
const emitter = new EventEmitter<{ close: boolean; t1: void }>()
let emitHit = 0

emitter.on('t1', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/base/eventemitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export type Listener<O extends Record<EventKey, any>, K extends keyof O, V = O[K
: (...args: any[]) => void | Promise<void>
: V extends Nil
? () => void | Promise<void>
: (arg: V) => void | Promise<void>
: V extends boolean ? (arg: boolean) => void | Promise<void>
: (arg: V) => void | Promise<void>

export class EventEmitter<E extends Record<EventKey, any>> {
private readonly eventListeners: Map<keyof E, Listener<E, any>[]> = new Map()
Expand Down
1 change: 1 addition & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class KeepLiveWS<E extends Record<EventKey, any> = { }> extends LiveClien
this.ws.close()
},
reconnect: () => {
this.ws?.close()
this.ws = null!
const socket = new WebSocket(options.ssl ? WEBSOCKET_SSL_URL : WEBSOCKET_URL)
socket.binaryType = 'arraybuffer'
Expand Down
2 changes: 2 additions & 0 deletions src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class KeepLiveTCP<E extends Record<EventKey, any> = { }> extends LiveClie
this.tcpSocket.write(data)
},
reconnect: () => {
this.tcpSocket?.end()
this.tcpSocket = null!
const socket = resolvedOptions.url ? connect(resolvedOptions.url) : connect(NODE_SOCKET_PORT, SOCKET_HOST)
this.tcpSocket = socket
Expand Down Expand Up @@ -136,6 +137,7 @@ export class KeepLiveWS<E extends Record<EventKey, any> = { }> extends LiveClien
this.ws.close()
},
reconnect: () => {
this.ws?.close()
this.ws = null!
const socket = new WebSocket(options.ssl ? WEBSOCKET_SSL_URL : WEBSOCKET_URL)
this.ws = socket
Expand Down

0 comments on commit 0f2b5c3

Please sign in to comment.