feat: native-mobile-api

This commit is contained in:
SamuelScheit
2023-04-20 13:01:11 +02:00
parent 28be45a9b4
commit ef673f62ca
17 changed files with 940 additions and 74 deletions
+47
View File
@@ -0,0 +1,47 @@
import { Socket } from 'net'
import { MOBILE_ENDPOINT, MOBILE_PORT } from '../Defaults'
import { SocketConfig } from '../Types'
export class MobileSocket extends Socket {
constructor(public config: SocketConfig) {
super()
if(config.auth.creds.registered) {
this.connect()
}
this.on('data', (d) => {
this.emit('message', d)
})
}
override connect() {
return super.connect(MOBILE_PORT, MOBILE_ENDPOINT, () => {
this.emit('open')
})
}
get isOpen(): boolean {
return this.readyState === 'open'
}
get isClosed(): boolean {
return this.readyState === 'closed'
}
get isClosing(): boolean {
return this.isClosed
}
get isConnecting(): boolean {
return this.readyState === 'opening'
}
close(): void {
this.end()
}
send(data: unknown, cb?: ((err?: Error | undefined) => void) | undefined) {
return super.write(data as Uint8Array | string, cb as ((err?: Error | undefined) => void))
}
}