|
|
@ -6,7 +6,6 @@ import {TLDeserialization, TLSerialization} from './tl_utils'; |
|
|
|
import CryptoWorker from '../crypto/cryptoworker'; |
|
|
|
import CryptoWorker from '../crypto/cryptoworker'; |
|
|
|
import AppStorage from '../storage'; |
|
|
|
import AppStorage from '../storage'; |
|
|
|
import Schema from './schema'; |
|
|
|
import Schema from './schema'; |
|
|
|
|
|
|
|
|
|
|
|
import timeManager from './timeManager'; |
|
|
|
import timeManager from './timeManager'; |
|
|
|
import NetworkerFactory from './networkerFactory'; |
|
|
|
import NetworkerFactory from './networkerFactory'; |
|
|
|
import { logger, LogLevels } from '../logger'; |
|
|
|
import { logger, LogLevels } from '../logger'; |
|
|
@ -30,7 +29,7 @@ import Socket from './transports/websocket'; |
|
|
|
|
|
|
|
|
|
|
|
//console.error('networker included!', new Error().stack);
|
|
|
|
//console.error('networker included!', new Error().stack);
|
|
|
|
|
|
|
|
|
|
|
|
type MessageOptions = InvokeApiOptions & Partial<{ |
|
|
|
export type MTMessageOptions = InvokeApiOptions & Partial<{ |
|
|
|
noResponse: true, |
|
|
|
noResponse: true, |
|
|
|
longPoll: true, |
|
|
|
longPoll: true, |
|
|
|
|
|
|
|
|
|
|
@ -39,7 +38,7 @@ type MessageOptions = InvokeApiOptions & Partial<{ |
|
|
|
messageID: string, |
|
|
|
messageID: string, |
|
|
|
}>; |
|
|
|
}>; |
|
|
|
|
|
|
|
|
|
|
|
type Message = InvokeApiOptions & MessageOptions & { |
|
|
|
export type MTMessage = InvokeApiOptions & MTMessageOptions & { |
|
|
|
msg_id: string, |
|
|
|
msg_id: string, |
|
|
|
seq_no: number, |
|
|
|
seq_no: number, |
|
|
|
body?: Uint8Array | number[], |
|
|
|
body?: Uint8Array | number[], |
|
|
@ -76,7 +75,7 @@ export default class MTPNetworker { |
|
|
|
private lastServerMessages: Array<string> = []; |
|
|
|
private lastServerMessages: Array<string> = []; |
|
|
|
|
|
|
|
|
|
|
|
private sentMessages: { |
|
|
|
private sentMessages: { |
|
|
|
[msgID: string]: Message |
|
|
|
[msgID: string]: MTMessage |
|
|
|
} = {}; |
|
|
|
} = {}; |
|
|
|
|
|
|
|
|
|
|
|
private pendingMessages: {[msgID: string]: number} = {}; |
|
|
|
private pendingMessages: {[msgID: string]: number} = {}; |
|
|
@ -195,7 +194,7 @@ export default class MTPNetworker { |
|
|
|
return seqNo; |
|
|
|
return seqNo; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public wrapMtpCall(method: string, params: any = {}, options: MessageOptions = {}) { |
|
|
|
public wrapMtpCall(method: string, params: any = {}, options: MTMessageOptions = {}) { |
|
|
|
const serializer = new TLSerialization({mtproto: true}); |
|
|
|
const serializer = new TLSerialization({mtproto: true}); |
|
|
|
|
|
|
|
|
|
|
|
serializer.storeMethod(method, params); |
|
|
|
serializer.storeMethod(method, params); |
|
|
@ -215,7 +214,7 @@ export default class MTPNetworker { |
|
|
|
return this.pushMessage(message, options); |
|
|
|
return this.pushMessage(message, options); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public wrapMtpMessage(object: any = {}, options: MessageOptions = {}) { |
|
|
|
public wrapMtpMessage(object: any = {}, options: MTMessageOptions = {}) { |
|
|
|
const serializer = new TLSerialization({mtproto: true}); |
|
|
|
const serializer = new TLSerialization({mtproto: true}); |
|
|
|
serializer.storeObject(object, 'Object'); |
|
|
|
serializer.storeObject(object, 'Object'); |
|
|
|
|
|
|
|
|
|
|
@ -424,7 +423,7 @@ export default class MTPNetworker { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private handleSentEncryptedRequestHTTP(promise: ReturnType<MTPNetworker['sendEncryptedRequest']>, message: Message, noResponseMsgs: string[]) { |
|
|
|
private handleSentEncryptedRequestHTTP(promise: ReturnType<MTPNetworker['sendEncryptedRequest']>, message: MTMessage, noResponseMsgs: string[]) { |
|
|
|
promise |
|
|
|
promise |
|
|
|
.then((result) => { |
|
|
|
.then((result) => { |
|
|
|
this.toggleOffline(false); |
|
|
|
this.toggleOffline(false); |
|
|
@ -481,7 +480,7 @@ export default class MTPNetworker { |
|
|
|
seq_no: number, |
|
|
|
seq_no: number, |
|
|
|
body: Uint8Array | number[], |
|
|
|
body: Uint8Array | number[], |
|
|
|
isAPI?: boolean |
|
|
|
isAPI?: boolean |
|
|
|
}, options: MessageOptions = {}) { |
|
|
|
}, options: MTMessageOptions = {}) { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
this.sentMessages[message.msg_id] = Object.assign(message, options, { |
|
|
|
this.sentMessages[message.msg_id] = Object.assign(message, options, { |
|
|
|
deferred: {resolve, reject} |
|
|
|
deferred: {resolve, reject} |
|
|
@ -587,7 +586,7 @@ export default class MTPNetworker { |
|
|
|
|
|
|
|
|
|
|
|
if(this.pendingResends.length) { |
|
|
|
if(this.pendingResends.length) { |
|
|
|
const resendMsgIDs: Array<string> = this.pendingResends.slice(); |
|
|
|
const resendMsgIDs: Array<string> = this.pendingResends.slice(); |
|
|
|
const resendOpts: MessageOptions = { |
|
|
|
const resendOpts: MTMessageOptions = { |
|
|
|
noSchedule: true, |
|
|
|
noSchedule: true, |
|
|
|
notContentRelated: true, |
|
|
|
notContentRelated: true, |
|
|
|
messageID: '' // will set in wrapMtpMessage->pushMessage
|
|
|
|
messageID: '' // will set in wrapMtpMessage->pushMessage
|
|
|
@ -706,7 +705,7 @@ export default class MTPNetworker { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var containerSentMessage: Message = { |
|
|
|
var containerSentMessage: MTMessage = { |
|
|
|
msg_id: timeManager.generateID(), |
|
|
|
msg_id: timeManager.generateID(), |
|
|
|
seq_no: this.generateSeqNo(true), |
|
|
|
seq_no: this.generateSeqNo(true), |
|
|
|
container: true, |
|
|
|
container: true, |
|
|
@ -776,7 +775,7 @@ export default class MTPNetworker { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public sendEncryptedRequest(message: Message, options: any = {}) { |
|
|
|
public sendEncryptedRequest(message: MTMessage, options: any = {}) { |
|
|
|
const self = this; |
|
|
|
const self = this; |
|
|
|
|
|
|
|
|
|
|
|
this.log.debug('Send encrypted', message, options, this.authKeyID); |
|
|
|
this.log.debug('Send encrypted', message, options, this.authKeyID); |
|
|
|