The endOfStream() method of the MediaSource interface signals the end of the stream.
endOfStream()
MDN Reference