1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-17 23:54:25 +00:00
gitea/web_src/js/features
zeripath e46dbec294
Move EventSource to SharedWorker (#12095) (#12130)
* Move EventSource to SharedWorker (#12095)

Backport #12095

Move EventSource to use a SharedWorker. This prevents issues with HTTP/1.1
open browser connections from preventing gitea from opening multiple tabs.

Also allow setting EVENT_SOURCE_UPDATE_TIME to disable EventSource updating

Fix #11978

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>

* Bugfix for shared event source

For some reason our eslint configuration is not working correctly
and a bug has become apparent when trying to backport this to 1.12.

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Re-fix #12095 again

Unfortunately some of the suggested changes to #12095 introduced
bugs which due to caching behaviour of sharedworkers were not caught
on simple tests.

These are as follows:

* Changing from simple for loop to use includes here:

```js
  register(port) {
    if (!this.clients.includes(port)) return;

    this.clients.push(port);

    port.postMessage({
      type: 'status',
      message: `registered to ${this.url}`,
    });
  }
```

The additional `!` prevents any clients from being added and should
read:

```js
    if (this.clients.includes(port)) return;
```

* Dropping the use of jQuery `$(...)` selection and using DOM
`querySelector` here:

```js
async function receiveUpdateCount(event) {
  try {
    const data = JSON.parse(event.data);

    const notificationCount = document.querySelector('.notification_count');
    if (data.Count > 0) {
      notificationCount.classList.remove('hidden');
    } else {
      notificationCount.classList.add('hidden');
    }

    notificationCount.text() = `${data.Count}`;
    await updateNotificationTable();
  } catch (error) {
    console.error(error, event);
  }
}
```

Requires that `notificationCount.text()` be changed to use `textContent`
instead.

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2020-07-05 01:08:03 +03:00
..
clipboard.js Misc JS linting and naming tweaks (#10652) 2020-03-11 21:34:54 +02:00
codeeditor.js Switch code editor to Monaco (#11366) 2020-05-14 19:06:01 +03:00
contextpopup.js Support unicode emojis and remove emojify.js (#11032) 2020-04-28 15:05:39 -03:00
datetimepicker.js move jquery-datetimepicker to npm/webpack (#10713) 2020-03-17 15:08:15 -04:00
dropzone.js Misc JS linting and naming tweaks (#10652) 2020-03-11 21:34:54 +02:00
emoji.js Support unicode emojis and remove emojify.js (#11032) 2020-04-28 15:05:39 -03:00
eventsource.sharedworker.js Move EventSource to SharedWorker (#12095) (#12130) 2020-07-05 01:08:03 +03:00
gitgraph.js Misc JS linting and naming tweaks (#10652) 2020-03-11 21:34:54 +02:00
highlight.js Move syntax highlighting to web worker (#11017) 2020-04-13 16:02:31 +03:00
highlight.worker.js Move syntax highlighting to web worker (#11017) 2020-04-13 16:02:31 +03:00
notification.js Move EventSource to SharedWorker (#12095) (#12130) 2020-07-05 01:08:03 +03:00
serviceworker.js Fix serviceworker output file and misc improvements (#11562) (#11610) 2020-05-25 00:12:02 +03:00
tribute.js Support unicode emojis and remove emojify.js (#11032) 2020-04-28 15:05:39 -03:00
userheatmap.js Migrate ActivityHeatmap to Vue SFC (#10953) 2020-04-06 09:31:11 +08:00