/**
 * Copyright 2024 Phenix Real Time Solutions, Inc. Confidential and Proprietary. All Rights Reserved.
 */
if (!ReadableStream.prototype[Symbol.asyncIterator]) {
  Object.defineProperty(ReadableStream.prototype, Symbol.asyncIterator, {
    value: function () {
      const reader = this.getReader();

      return {
        next: async () => {
          const {done, value} = await reader.read();

          return {
            value,
            done
          };
        },
        return: async () => {
          reader.releaseLock();

          return {
            value: undefined,
            done: true
          };
        },
        throw: async e => {
          reader.releaseLock();

          throw e;
        },
        [Symbol.asyncIterator]: function () {
          return this;
        }
      };
    },
    writable: true,
    configurable: true
  });
}
