feat: functional legacy socket

This commit is contained in:
Adhiraj Singh
2021-12-17 20:58:33 +05:30
parent d8b415a075
commit c803e22e8a
15 changed files with 695 additions and 66 deletions

View File

@@ -3,6 +3,7 @@ import { jidDecode, jidEncode } from './jid-utils';
import { Binary, numUtf8Bytes } from '../../WABinary/Binary';
import { Boom } from '@hapi/boom';
import { proto } from '../../WAProto';
import { BinaryNode } from './types';
const LIST1 = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '.', '<27>', '<27>', '<27>', '<27>'];
const LIST2 = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
@@ -210,20 +211,6 @@ function bufferToUInt(e: Uint8Array | Buffer, t: number) {
for (let i = 0; i < t; i++) a = 256 * a + e[i]
return a
}
/**
* the binary node WA uses internally for communication
*
* this is manipulated soley as an object and it does not have any functions.
* This is done for easy serialization, to prevent running into issues with prototypes &
* to maintain functional code structure
* */
export type BinaryNode = {
tag: string
attrs: { [key: string]: string }
content?: BinaryNode[] | string | Uint8Array
}
export type BinaryNodeAttributes = BinaryNode['attrs']
export type BinaryNodeData = BinaryNode['content']
export const decodeBinaryNode = (data: Binary): BinaryNode => {
//U
@@ -333,4 +320,6 @@ export const getBinaryNodeMessages = ({ content }: BinaryNode) => {
}
export * from './jid-utils'
export { Binary } from '../../WABinary/Binary'
export { Binary } from '../../WABinary/Binary'
export * from './types'
export * from './Legacy'