Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 1.44 KB

README.md

File metadata and controls

51 lines (38 loc) · 1.44 KB

adnl

npm GitHub top language

ADNL JavaScript implementation.

⚠️ Work in progress, API can (and most likely will) be changed! This is not production ready version yet.

How to install

npm i adnl

Simple usage

import { ADNLClient } from 'adnl'

const ADNL_HOST = '127.0.0.1'
const ADNL_PORT = 1337
const ADNL_PUB_KEY = 'hex/base64/buffer'

const TL_GETTIME = '7af98bb435263e6c95d6fecb497dfd0aa5f031e7d412986b5ce720496db512052e8f2d100cdf068c7904345aad16000000000000'
const TL_PARSE_GETTIME = (data: Buffer) => {
    const unix = data.slice(data.byteLength - 7, data.byteLength - 3).readUint32LE(0)

    return new Date(unix * 1000).toString()
}

const client = new ADNLClient(ADNL_HOST, ADNL_PORT, ADNL_PUB_KEY)

client.on('connect', () => console.log('on connect'))
client.on('close', () => console.log('on close'))
client.on('data', (data: Buffer) => console.log('on data: ', TL_PARSE_GETTIME(data)))
client.on('error', (error: Error) => console.log('on error', error))
client.on('ready', () => {
    console.log('on ready')

    let counter = 0
    let interval = setInterval(() => {
        client.write(Buffer.from(TL_GETTIME, 'hex'))
    
        if (++counter === 5) {
            clearInterval(interval)
            client.end()
        }
    }, 3000)
})

License

MIT License