Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
},
"dependencies": {
"emoji-regex": "^10.1.0",
"qrcode.react": "^3.1.0"
"http-proxy-agent": "^7.0.2",
"qrcode.react": "^3.1.0",
"socks-proxy-agent": "^8.0.4"
},
"optionalDependencies": {
"lodash": "^4.17.21",
Expand Down
15 changes: 15 additions & 0 deletions src/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { PhoneNumber } from './PhoneNumber'
import type { PlatformAPI, LoginCreds, LoginResult } from './PlatformAPI'
import type { PlatformInfo } from './PlatformInfo'


export type AuthProps = {
isReauthing?: boolean
api?: PlatformAPI
Expand All @@ -22,4 +23,18 @@ export interface Platform {
info: PlatformInfo
api: PlatformAPI
auth?: React.LazyExoticComponent<React.FC<AuthProps> | React.ComponentClass<AuthProps>>
proxyConfig?: ProxyConfig;
}
export interface ProxyConfig {
host: string;
port: number;
protocol: 'http' | 'https' | 'socks4' | 'socks5';
auth?: {
username: string;
password: string;
};
}

export interface PlatformConfig {
proxyConfig?: ProxyConfig;
}
4 changes: 3 additions & 1 deletion src/PlatformAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { NotificationsInfo } from './Notifications'
import type { StickerPack, StickerPackID } from './StickerPack'
import type { Attachment, AttachmentID } from './Attachment'
import type { OverridablePlatformInfo } from './PlatformInfo'
import type { PlatformConfig } from './Platform'

export type OnLoginEventCallback = (data: any) => void

Expand Down Expand Up @@ -130,8 +131,9 @@ export interface PlatformAPI {
* Called after new PlatformAPI()
* @param session - return value of `serializeSession`, `undefined` if not logged in
*/
init: (session: SerializedSession, context: ClientContext, prefs?: Record<string, boolean | string>) => Awaitable<void>
init(session?: any, prefs?: Record<string, any>, config?: PlatformConfig): Awaitable<void>;


/** `dispose` disconnects all network connections and cleans up. Called when user disables account and when app exits. */
dispose: () => Awaitable<void>

Expand Down
20 changes: 20 additions & 0 deletions src/PlatformInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type Pref = {
default: boolean | string
}


type HTMLSVG = `<svg ${string} </svg>`
type HexColor = `#${string}`

Expand Down Expand Up @@ -97,6 +98,15 @@ export interface OverridablePlatformInfo {
}
}
}
export interface ProxyConfig {
host: string;
port: number;
protocol: 'http' | 'https' | 'socks4' | 'socks5';
auth?: {
username: string;
password: string;
};
}

export interface PlatformInfo extends OverridablePlatformInfo, ExtraProp {
name: string
Expand Down Expand Up @@ -131,6 +141,16 @@ export interface PlatformInfo extends OverridablePlatformInfo, ExtraProp {

prefs?: Record<string, Pref>

proxyConfig?: {
host: string;
port: number;
protocol: 'http' | 'https' | 'socks4' | 'socks5';
auth?: {
username: string;
password: string;
};
};

getUserProfileLink?: (participant: Participant) => string
generateUniqueMessageID?: () => string
}
28 changes: 27 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { TextsNodeGlobals, TextsRendererGlobals } from './TextsGlobals'
import { SocksProxyAgent } from 'socks-proxy-agent'

export * from './enums'
export * from './errors'
export * from './constants'

export * from './fetch'
export * from './generic'
export * from './CustomEmoji'
Expand All @@ -22,6 +22,32 @@ export * from './User'
export * from './StickerPack'
export * from './IAsyncSqlite'
export * from './util'
export type { ProxyConfig, PlatformConfig } from './Platform';

// Ensure the globalThis texts is of correct type
export const texts = (globalThis as any).texts as TextsNodeGlobals
export const textsRenderer = (globalThis as any).texts as TextsRendererGlobals



// // Wrap the original createHttpClient method
// const originalCreateHttpClient = texts.createHttpClient.bind(texts)

// // Define a new createHttpClient method with proxy support
// texts.createHttpClient = (options: any & { proxy?: ProxyConfig }) => {
// // Check if proxy options are provided
// if (options.proxy) {
// const { protocol, host, port, auth } = options.proxy
// const proxyUrl = `${protocol}://${auth ? `${auth.username}:${auth.password}@` : ''}${host}:${port}`

// // Set the appropriate agent based on the protocol
// if (protocol === 'socks4' || protocol === 'socks5') {
// options.agent = new SocksProxyAgent(proxyUrl)
// } else {
// options.agent = new HttpsProxyAgent(proxyUrl)
// }
// }

// // Call the original createHttpClient with the updated options
// // return originalCreateHttpClient(options)
// }
85 changes: 85 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1612,8 +1612,10 @@ __metadata:
emoji-regex: ^10.1.0
eslint: ^8.30.0
form-data: ^4.0.0
http-proxy-agent: ^7.0.2
lodash: ^4.17.21
qrcode.react: ^3.1.0
socks-proxy-agent: ^8.0.4
typescript: ^5.0.2
ws: ^8.15.1
dependenciesMeta:
Expand Down Expand Up @@ -1908,6 +1910,15 @@ __metadata:
languageName: node
linkType: hard

"agent-base@npm:^7.1.0, agent-base@npm:^7.1.1":
version: 7.1.1
resolution: "agent-base@npm:7.1.1"
dependencies:
debug: ^4.3.4
checksum: 51c158769c5c051482f9ca2e6e1ec085ac72b5a418a9b31b4e82fe6c0a6699adb94c1c42d246699a587b3335215037091c79e0de512c516f73b6ea844202f037
languageName: node
linkType: hard

"ajv@npm:^6.10.0, ajv@npm:^6.12.4":
version: 6.12.6
resolution: "ajv@npm:6.12.6"
Expand Down Expand Up @@ -2368,6 +2379,18 @@ __metadata:
languageName: node
linkType: hard

"debug@npm:^4.3.4":
version: 4.3.6
resolution: "debug@npm:4.3.6"
dependencies:
ms: 2.1.2
peerDependenciesMeta:
supports-color:
optional: true
checksum: 1630b748dea3c581295e02137a9f5cbe2c1d85fea35c1e6597a65ca2b16a6fce68cec61b299d480787ef310ba927dc8c92d3061faba0ad06c6a724672f66be7f
languageName: node
linkType: hard

"deep-is@npm:^0.1.3":
version: 0.1.4
resolution: "deep-is@npm:0.1.4"
Expand Down Expand Up @@ -3142,6 +3165,16 @@ __metadata:
languageName: node
linkType: hard

"http-proxy-agent@npm:^7.0.2":
version: 7.0.2
resolution: "http-proxy-agent@npm:7.0.2"
dependencies:
agent-base: ^7.1.0
debug: ^4.3.4
checksum: 670858c8f8f3146db5889e1fa117630910101db601fff7d5a8aa637da0abedf68c899f03d3451cac2f83bcc4c3d2dabf339b3aa00ff8080571cceb02c3ce02f3
languageName: node
linkType: hard

"ignore@npm:^5.1.4, ignore@npm:^5.1.8":
version: 5.1.9
resolution: "ignore@npm:5.1.9"
Expand Down Expand Up @@ -3201,6 +3234,16 @@ __metadata:
languageName: node
linkType: hard

"ip-address@npm:^9.0.5":
version: 9.0.5
resolution: "ip-address@npm:9.0.5"
dependencies:
jsbn: 1.1.0
sprintf-js: ^1.1.3
checksum: aa15f12cfd0ef5e38349744e3654bae649a34c3b10c77a674a167e99925d1549486c5b14730eebce9fea26f6db9d5e42097b00aa4f9f612e68c79121c71652dc
languageName: node
linkType: hard

"is-arrayish@npm:^0.2.1":
version: 0.2.1
resolution: "is-arrayish@npm:0.2.1"
Expand Down Expand Up @@ -3383,6 +3426,13 @@ __metadata:
languageName: node
linkType: hard

"jsbn@npm:1.1.0":
version: 1.1.0
resolution: "jsbn@npm:1.1.0"
checksum: 944f924f2bd67ad533b3850eee47603eed0f6ae425fd1ee8c760f477e8c34a05f144c1bd4f5a5dd1963141dc79a2c55f89ccc5ab77d039e7077f3ad196b64965
languageName: node
linkType: hard

"jsesc@npm:^2.5.1":
version: 2.5.2
resolution: "jsesc@npm:2.5.2"
Expand Down Expand Up @@ -4165,13 +4215,48 @@ __metadata:
languageName: node
linkType: hard

"smart-buffer@npm:^4.2.0":
version: 4.2.0
resolution: "smart-buffer@npm:4.2.0"
checksum: b5167a7142c1da704c0e3af85c402002b597081dd9575031a90b4f229ca5678e9a36e8a374f1814c8156a725d17008ae3bde63b92f9cfd132526379e580bec8b
languageName: node
linkType: hard

"socks-proxy-agent@npm:^8.0.4":
version: 8.0.4
resolution: "socks-proxy-agent@npm:8.0.4"
dependencies:
agent-base: ^7.1.1
debug: ^4.3.4
socks: ^2.8.3
checksum: b2ec5051d85fe49072f9a250c427e0e9571fd09d5db133819192d078fd291276e1f0f50f6dbc04329b207738b1071314cee8bdbb4b12e27de42dbcf1d4233c67
languageName: node
linkType: hard

"socks@npm:^2.8.3":
version: 2.8.3
resolution: "socks@npm:2.8.3"
dependencies:
ip-address: ^9.0.5
smart-buffer: ^4.2.0
checksum: 7a6b7f6eedf7482b9e4597d9a20e09505824208006ea8f2c49b71657427f3c137ca2ae662089baa73e1971c62322d535d9d0cf1c9235cf6f55e315c18203eadd
languageName: node
linkType: hard

"source-map@npm:^0.5.0":
version: 0.5.7
resolution: "source-map@npm:0.5.7"
checksum: 5dc2043b93d2f194142c7f38f74a24670cd7a0063acdaf4bf01d2964b402257ae843c2a8fa822ad5b71013b5fcafa55af7421383da919752f22ff488bc553f4d
languageName: node
linkType: hard

"sprintf-js@npm:^1.1.3":
version: 1.1.3
resolution: "sprintf-js@npm:1.1.3"
checksum: a3fdac7b49643875b70864a9d9b469d87a40dfeaf5d34d9d0c5b1cda5fd7d065531fcb43c76357d62254c57184a7b151954156563a4d6a747015cfb41021cad0
languageName: node
linkType: hard

"string-natural-compare@npm:^3.0.1":
version: 3.0.1
resolution: "string-natural-compare@npm:3.0.1"
Expand Down