private function emitMessage( $data ) {
		$msg = "event: message\n";
		$msg .= 'data: ' . wp_json_encode( $data ) . "\n\n";
		$msg .= ':' . str_repeat( ' ', 2048 ) . "\n\n";
		// Buffers are nested. While one buffer is active, flushing from child buffers are not really sent to the browser,
		// but rather to the parent buffer. Only when there is no parent buffer are contents sent to the browser.
		if ( ob_get_level() ) {
			// Keep for later
			$this->msgStack[] = $msg;
		} else {
			// Flush to browser
			foreach ( $this->msgStack as $stack ) {
				echo $stack;
			}
			$this->msgStack = []; // Reset
			echo $msg;
			flush();
		}
	}
private function emitMessage( $data ) {
		$msg = "event: message\n";
		$msg .= 'data: ' . wp_json_encode( $data ) . "\n\n";
		$msg .= ':' . str_repeat( ' ', 2048 ) . "\n\n";
		// Buffers are nested. While one buffer is active, flushing from child buffers are not really sent to the browser,
		// but rather to the parent buffer. Only when there is no parent buffer are contents sent to the browser.
		if ( ob_get_level() ) {
			// Keep for later
			$this->msgStack[] = $msg;
		} else {
			// Flush to browser
			foreach ( $this->msgStack as $stack ) {
				echo $stack;
			}
			$this->msgStack = []; // Reset
			echo $msg;
			flush();
		}
	}
private function emitMessage ( $ data ) { $ msg = "event: message\n" ; $ msg .= 'data: ' . wp_json_encode ( $ data ) . "\n\n" ; $ msg .= ':' . str_repeat ( ' ' , 2048 ) . "\n\n" ; // Buffers are nested. While one buffer is active, flushing from child buffers are not really sent to the browser, // but rather to the parent buffer. Only when there is no parent buffer are contents sent to the browser. if ( ob_get_level ( ) ) { // Keep for later $ this -> msgStack [ ] = $ msg ; } else { // Flush to browser foreach ( $ this -> msgStack as $ stack ) { echo $ stack ; } $ this -> msgStack = [ ] ; // Reset echo $ msg ; flush ( ) ; } }
Emit a Server-Sent Events message.

@param mixed $data Data to be JSON-encoded and sent in the message.
Emit a Server - Sent Events message .