|
| 1 | +import Payload from './Payload' |
| 2 | +import { Thrift, TCompactProtocol, Int64 } from 'thrift' |
| 3 | +import FacebookCapFlags from '../../types/FacebookCapFlags' |
| 4 | +import Long from 'long' |
| 5 | +import AuthTokens from '../../types/AuthTokens' |
| 6 | +import DeviceId from '../../types/DeviceId' |
| 7 | + |
| 8 | +export default class ConnectRequest extends Payload { |
| 9 | + deviceId: DeviceId |
| 10 | + tokens: AuthTokens |
| 11 | + userAgent: string |
| 12 | + |
| 13 | + constructor (deviceId: DeviceId, tokens: AuthTokens, userAgent: string) { |
| 14 | + super() |
| 15 | + this.deviceId = deviceId |
| 16 | + this.tokens = tokens |
| 17 | + this.userAgent = userAgent |
| 18 | + } |
| 19 | + |
| 20 | + encode (proto: TCompactProtocol): Promise<void> { |
| 21 | + proto.writeFieldBegin('clientIdentifier', Thrift.Type.STRING, 1) |
| 22 | + proto.writeString(this.deviceId.clientId) |
| 23 | + |
| 24 | + proto.writeFieldBegin('clientInfo', Thrift.Type.STRUCT, 4) |
| 25 | + proto.writeStructBegin('clientInfo') |
| 26 | + |
| 27 | + // Write user id |
| 28 | + proto.writeFieldBegin('userId', Thrift.Type.I64, 1) |
| 29 | + proto.writeI64(new Int64(Buffer.from(Long.fromString(this.tokens.uid.toString()).toBytes()))) |
| 30 | + |
| 31 | + // Write information |
| 32 | + proto.writeFieldBegin('userAgent', Thrift.Type.STRING, 2) |
| 33 | + proto.writeString(this.userAgent) |
| 34 | + |
| 35 | + // Write some random int (?) |
| 36 | + proto.writeFieldBegin('clientCapabilities', Thrift.Type.I64, 3) |
| 37 | + proto.writeI64( |
| 38 | + FacebookCapFlags.FB_CP_ACKNOWLEDGED_DELIVERY | |
| 39 | + FacebookCapFlags.FB_CP_PROCESSING_LASTACTIVE_PRESENCEINFO | |
| 40 | + FacebookCapFlags.FB_CP_EXACT_KEEPALIVE | |
| 41 | + FacebookCapFlags.FB_CP_LARGE_PAYLOAD_SUPPORTED | |
| 42 | + FacebookCapFlags.FB_CP_DELTA_SENT_MESSAGE_ENABLED) |
| 43 | + |
| 44 | + proto.writeFieldBegin('endpointCapabilities', Thrift.Type.I64, 4) |
| 45 | + proto.writeI64(26) // 0011010 libfb default |
| 46 | + // proto.writeI64(90) // 1011010 used by app |
| 47 | + |
| 48 | + // 1: ZLIB |
| 49 | + // 2: ZLIB_OPTIONAL |
| 50 | + // 3: RAW |
| 51 | + proto.writeFieldBegin('publishFormat', Thrift.Type.I32, 5) |
| 52 | + proto.writeI32(1) |
| 53 | + |
| 54 | + // Write no_auto_fg boolean |
| 55 | + proto.writeFieldBegin('noAutomaticForeground', Thrift.Type.BOOL, 6) |
| 56 | + proto.writeBool(false) |
| 57 | + |
| 58 | + // Write visibility state |
| 59 | + proto.writeFieldBegin('makeUserAvailableInForeground', Thrift.Type.BOOL, 7) |
| 60 | + proto.writeBool(true) |
| 61 | + |
| 62 | + // Write device id |
| 63 | + proto.writeFieldBegin('deviceId', Thrift.Type.STRING, 8) |
| 64 | + proto.writeString(this.deviceId.deviceId) |
| 65 | + |
| 66 | + // Write fg boolean |
| 67 | + proto.writeFieldBegin('isInitiallyForeground', Thrift.Type.BOOL, 9) |
| 68 | + proto.writeBool(true) |
| 69 | + |
| 70 | + // nwt int |
| 71 | + proto.writeFieldBegin('networkType', Thrift.Type.I32, 10) |
| 72 | + proto.writeI32(1) |
| 73 | + |
| 74 | + // nwst int |
| 75 | + proto.writeFieldBegin('networkSubtype', Thrift.Type.I32, 11) |
| 76 | + proto.writeI32(0) |
| 77 | + |
| 78 | + // write mqtt id |
| 79 | + proto.writeFieldBegin('clientMqttSessionId', Thrift.Type.I64, 12) |
| 80 | + proto.writeI64(this.deviceId.mqttId) |
| 81 | + |
| 82 | + // Topics subscribed to by the app. |
| 83 | + // libfb sends a separate subscribe message later, so this is effectively unused. |
| 84 | + // const topics = [155, 107, 150, 140, 174, 34, 59, 195, 92, 131, 75, 103, 90, 62, 98, 72, 85, 100, 86, 65, 63]; |
| 85 | + const topics = [] |
| 86 | + proto.writeFieldBegin('subscribeTopics', Thrift.Type.LIST, 14) |
| 87 | + proto.writeListBegin(Thrift.Type.I32, topics.length) |
| 88 | + { |
| 89 | + for (const topic of topics) { |
| 90 | + proto.writeI32(topic) |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + // Meaning of value not known |
| 95 | + proto.writeFieldBegin('clientType', Thrift.Type.STRING, 15) |
| 96 | + proto.writeString('') |
| 97 | + |
| 98 | + // Meaning of value not known |
| 99 | + proto.writeFieldBegin('regionPreference', Thrift.Type.STRING, 19) |
| 100 | + proto.writeString('ATN') |
| 101 | + |
| 102 | + // Meaning of value not known |
| 103 | + proto.writeFieldBegin('deviceSecret', Thrift.Type.STRING, 20) |
| 104 | + proto.writeString('') |
| 105 | + |
| 106 | + // Meaning of value not known |
| 107 | + proto.writeFieldBegin('clientStack', Thrift.Type.BYTE, 21) |
| 108 | + proto.writeByte(4) |
| 109 | + |
| 110 | + // Meaning of value not known |
| 111 | + proto.writeFieldBegin('networkTypeInfo', Thrift.Type.I32, 27) |
| 112 | + proto.writeI32(7) |
| 113 | + |
| 114 | + // End of object |
| 115 | + proto.writeByte(0) |
| 116 | + |
| 117 | + proto.writeStructEnd() |
| 118 | + |
| 119 | + proto.writeFieldBegin('password', Thrift.Type.STRING, 5) |
| 120 | + proto.writeString(this.tokens.access_token) |
| 121 | + |
| 122 | + proto.writeFieldBegin('combinedPublishes', Thrift.Type.LIST, 8) |
| 123 | + proto.writeListBegin(Thrift.Type.STRUCT, 0) |
| 124 | + |
| 125 | + proto.writeFieldBegin('phpOverride', Thrift.Type.STRUCT, 11) |
| 126 | + proto.writeStructBegin('phpOverride') |
| 127 | + |
| 128 | + proto.writeFieldBegin('port', Thrift.Type.I32, 2) |
| 129 | + proto.writeI32(0) |
| 130 | + |
| 131 | + // End of object |
| 132 | + proto.writeByte(0) |
| 133 | + |
| 134 | + proto.writeStructEnd() |
| 135 | + |
| 136 | + proto.writeByte(0) |
| 137 | + |
| 138 | + return null |
| 139 | + } |
| 140 | +} |
0 commit comments