mobile: deprecation.

This commit is contained in:
Rajeh Taher
2024-10-14 03:39:46 +03:00
parent 647f8d767f
commit 61a0ff3178
18 changed files with 47 additions and 533 deletions

View File

@@ -1,3 +1,2 @@
export * from './abstract-socket-client'
export * from './mobile-socket-client'
export * from './web-socket-client'
export * from './types'
export * from './websocket'

View File

@@ -1,66 +0,0 @@
import { connect, Socket } from 'net'
import { AbstractSocketClient } from './abstract-socket-client'
export class MobileSocketClient extends AbstractSocketClient {
protected socket: Socket | null = null
get isOpen(): boolean {
return this.socket?.readyState === 'open'
}
get isClosed(): boolean {
return this.socket === null || this.socket?.readyState === 'closed'
}
get isClosing(): boolean {
return this.socket === null || this.socket?.readyState === 'closed'
}
get isConnecting(): boolean {
return this.socket?.readyState === 'opening'
}
async connect(): Promise<void> {
if(this.socket) {
return
}
if(this.config.agent) {
throw new Error('There are not support for proxy agent for mobile connection')
} else {
this.socket = connect({
host: this.url.hostname,
port: Number(this.url.port) || 443
})
}
this.socket.setMaxListeners(0)
const events = ['close', 'connect', 'data', 'drain', 'end', 'error', 'lookup', 'ready', 'timeout']
for(const event of events) {
this.socket?.on(event, (...args: any[]) => this.emit(event, ...args))
}
this.socket.on('data', (...args: any[]) => this.emit('message', ...args))
this.socket.on('ready', (...args: any[]) => this.emit('open', ...args))
}
async close(): Promise<void> {
if(!this.socket) {
return
}
return new Promise<void>(resolve => {
this.socket!.end(resolve)
this.socket = null
})
}
send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean {
if(this.socket === null) {
return false
}
return this.socket.write(str, undefined, cb)
}
}

View File

@@ -1,6 +1,6 @@
import WebSocket from 'ws'
import { DEFAULT_ORIGIN } from '../../Defaults'
import { AbstractSocketClient } from './abstract-socket-client'
import { AbstractSocketClient } from './types'
export class WebSocketClient extends AbstractSocketClient {