@@ -16,12 +16,14 @@ import { AttachmentNotFoundError, AttachmentURLMissingError } from './types/Erro
1616import StrictEventEmitter from 'strict-event-emitter-types'
1717import ClientEvents from './ClientEvents'
1818import * as Payloads from './mqtt/payloads'
19+ import DeviceId from './types/DeviceId'
1920
2021const debugLog = debug ( 'fblib' )
2122
2223export interface ClientOptions {
2324 selfListen ?: boolean
2425 session ?: Session
26+ deviceId ?: DeviceId
2527}
2628
2729type ClientEmitter = StrictEventEmitter < EventEmitter , ClientEvents >
@@ -51,6 +53,10 @@ export default class Client extends (EventEmitter as { new(): ClientEmitter }) {
5153 session = { tokens : null , deviceId : null }
5254 }
5355
56+ if ( options . deviceId ) {
57+ session . deviceId = options . deviceId
58+ }
59+
5460 if ( ! session . deviceId ) {
5561 const deviceId = makeDeviceId ( )
5662 session . deviceId = deviceId
@@ -215,29 +221,62 @@ export default class Client extends (EventEmitter as { new(): ClientEmitter }) {
215221 }
216222
217223 private async createQueue ( seqId : number ) {
218- const obj = {
219- delta_batch_size : 125 ,
220- max_deltas_able_to_process : 1250 ,
221- sync_api_version : 3 ,
222- encoding : 'JSON' ,
223224
225+ // sync_api_version 3: You receive /t_ms payloads as json
226+ // sync_api_version 10: You receiove /t_ms payloads as thrift,
227+ // and connectQueue() does not have to be called.
228+ // Note that connectQueue() should always use 10 instead.
229+
230+ const obj = (
231+ {
224232 initial_titan_sequence_id : seqId ,
225- device_id : this . session . deviceId . deviceId ,
233+ delta_batch_size : 125 ,
234+ device_params : {
235+ image_sizes : {
236+ 0 : '4096x4096' ,
237+ 4 : '312x312' ,
238+ 1 : '768x768' ,
239+ 2 : '420x420' ,
240+ 3 : '312x312'
241+ } ,
242+ animated_image_format : 'WEBP,GIF' ,
243+ animated_image_sizes : {
244+ 0 : '4096x4096' ,
245+ 4 : '312x312' ,
246+ 1 : '768x768' ,
247+ 2 : '420x420' ,
248+ 3 : '312x312'
249+ }
250+ } ,
226251 entity_fbid : this . session . tokens . uid ,
227-
252+ sync_api_version : 3 , // Must be 3 instead of 10 to receive json payloads
253+ encoding : 'JSON' , // Must be removed if using sync_api_version 10
228254 queue_params : {
229- buzz_on_deltas_enabled : 'false' ,
255+ // Array of numbers -> Some bitwise encoding scheme -> base64. Numbers range from 0 to 67
256+ // Decides what type of /t_ms delta messages you get. Flags unknown, copy-pasted from app.
257+ client_delta_sync_bitmask : 'Amvr2dBlf7PNgA' ,
230258 graphql_query_hashes : {
231- xma_query_id : '10153919431161729 '
259+ xma_query_id : '306810703252313 '
232260 } ,
233-
234261 graphql_query_params : {
235- '10153919431161729' : {
236- xma_id : '<ID>'
262+ 306810703252313 : {
263+ xma_id : '<ID>' ,
264+ small_preview_width : 624 ,
265+ small_preview_height : 312 ,
266+ large_preview_width : 1536 ,
267+ large_preview_height : 768 ,
268+ full_screen_width : 4096 ,
269+ full_screen_height : 4096 ,
270+ blur : 0.0 ,
271+ nt_context : {
272+ styles_id : 'fe1fd5357bb40c81777dc915dfbd6aa4' ,
273+ pixel_ratio : 3.0
274+ }
237275 }
238276 }
239277 }
240278 }
279+ )
241280
242281 await this . mqttApi . sendPublish (
243282 '/messenger_sync_create_queue' ,
@@ -246,10 +285,15 @@ export default class Client extends (EventEmitter as { new(): ClientEmitter }) {
246285 }
247286
248287 private async connectQueue ( seqId ) {
288+
289+ // If createQueue() uses sync_api_version 10, this does not need to be called, and you will not receive json payloads.
290+ // If this does not use sync_api_version 10, you will not receive all messages (e.g. reactions )
291+ // Send the thrift-equivalent payload to /t_ms_gd and you will receive mostly thrift-encoded payloads instead.
292+
249293 const obj = {
250294 delta_batch_size : 125 ,
251295 max_deltas_able_to_process : 1250 ,
252- sync_api_version : 3 ,
296+ sync_api_version : 10 , // Must be 10 to receive some messages
253297 encoding : 'JSON' ,
254298
255299 last_seq_id : seqId ,
0 commit comments