(handler: (metadata: Metadata) => Metadata)
| 921 | } |
| 922 | |
| 923 | updateMetadata(handler: (metadata: Metadata) => Metadata) { |
| 924 | this.metadataLock.inLock(async () => { |
| 925 | await backoff(async () => { |
| 926 | let updated = handler(this.metadata!); // Weird state if metadata is null - should never happen but here we are |
| 927 | const answer = await this.socket.emitWithAck('update-metadata', { sid: this.sessionId, expectedVersion: this.metadataVersion, metadata: encodeBase64(encrypt(this.encryptionKey, this.encryptionVariant, updated)) }); |
| 928 | if (answer.result === 'success') { |
| 929 | this.metadata = decrypt(this.encryptionKey, this.encryptionVariant, decodeBase64(answer.metadata)); |
| 930 | this.metadataVersion = answer.version; |
| 931 | } else if (answer.result === 'version-mismatch') { |
| 932 | if (answer.version > this.metadataVersion) { |
| 933 | this.metadataVersion = answer.version; |
| 934 | this.metadata = decrypt(this.encryptionKey, this.encryptionVariant, decodeBase64(answer.metadata)); |
| 935 | } |
| 936 | throw new Error('Metadata version mismatch'); |
| 937 | } else if (answer.result === 'error') { |
| 938 | // Hard error - ignore |
| 939 | } |
| 940 | }); |
| 941 | }); |
| 942 | } |
| 943 | |
| 944 | /** |
| 945 | * Update session agent state |
no test coverage detected