Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server sent events #5279

Merged
merged 23 commits into from
Jan 15, 2021

Conversation

NicolasPetton
Copy link
Contributor

This is a follow-up to the original PR by @Arlen22 here: #4609.


Original PR description

This is related to Issue #4608 and also fixes Issue #4605.

To test this, run node tiddlywiki.js editions/server --listen then open two pages side-by-side and watch changes propagate in almost real time.

@pmario
Copy link
Member

pmario commented Dec 28, 2020

@Jermolene ... bump

@NicolasPetton
Copy link
Contributor Author

@Jermolene are there any changes you'd like me to do?

@NicolasPetton NicolasPetton force-pushed the add-server-sent-events branch 2 times, most recently from 469dbef to 979b3ee Compare January 13, 2021 10:28
@NicolasPetton
Copy link
Contributor Author

@Jermolene I just rebased the branch.

I can also rerwite the history if that's too many commits (I kept the commits from @Arlen22 but I can squash some of them to make the history cleaner).

Copy link
Member

@Jermolene Jermolene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @NicolasPetton apologies for the delay. Although I've been merging new stuff as it pops up, I haven't yet had a chance to methodically go back through the tickets we identified in #5231.

There's a couple of minor coding style comments. I'm also wondering if we need a configuration setting to turn off the SSE server; it could conceivably be a vector for DDOS attacks. We also need documentation updates.

Finally, I'm wondering if it's worth merging this without updating the syncer/syncadaptor to take advantage of it.

@NicolasPetton
Copy link
Contributor Author

There's a couple of minor coding style comments.

I'll fix them.

I'm also wondering if we need a configuration setting to turn off the SSE server; it could conceivably be a vector for DDOS attacks.

Would you accept that improvement in a separate PR?

We also need documentation updates.

Would you like documentation updates as part of this PR? If so, could you point out which tiddlers need updating?

Finally, I'm wondering if it's worth merging this without updating the syncer/syncadaptor to take advantage of it.

Sorry, I'm not following. The PR adds a route /events/plugins/tiddlywiki/tiddlyweb for tiddlyweb SSE in sse-server.js. Have I missed something else?

@pmario
Copy link
Member

pmario commented Jan 13, 2021

@Jermolene from the OP

To test this, run node tiddlywiki.js editions/server --listen then open two pages side-by-side and watch changes propagate in almost real time.

I think it does take advantage of the new funtionality

@pmario
Copy link
Member

pmario commented Jan 13, 2021

I think the configuration may be a new parameter to the --listen command see: https://tiddlywiki.com/#ListenCommand

For compatibility and security reasons, it may be switched OFF by default. So if the new parameter is present it will be switched on

@Jermolene
Copy link
Member

I'll fix them.

Thanks.

Would you accept that improvement in a separate PR?

Would you like documentation updates as part of this PR? If so, could you point out which tiddlers need updating?

It's generally best to include the docs in the same PR but we do fairly often merge them separately.

Finally, I'm wondering if it's worth merging this without updating the syncer/syncadaptor to take advantage of it.

Sorry, I'm not following. The PR adds a route /events/plugins/tiddlywiki/tiddlyweb for tiddlyweb SSE in sse-server.js. Have I missed something else?

The integration with the syncer is primitive; the client calls $tw.syncer.syncFromServer() when it receives changes from the server, but we don't do anything to disable the usual polling based syncing.

@Jermolene
Copy link
Member

I think the configuration may be a new parameter to the --listen command see: https://tiddlywiki.com/#ListenCommand

For compatibility and security reasons, it may be switched OFF by default. So if the new parameter is present it will be switched on

That makes sense. The client will need to be able to run correctly with either setting.

@NicolasPetton NicolasPetton force-pushed the add-server-sent-events branch 2 times, most recently from 41ba026 to 1e70cfb Compare January 13, 2021 19:32
Arlen22 and others added 10 commits January 13, 2021 21:59
* Extract helper functions for handling wikis and connections.
* Replace JSDoc comments.
* Fix formatting according to TW core.
* Simplify the logic for adding and removing connections.
Fix formatting according to TW core.
Fix formatting and comments following TW core guidelines.
startsWith is part of ES2015, while TiddlyWiki uses the 5.1 dialect.
* If not set to "yes", disabled SSE request handling.
* Add documentation for the parameter in core/language/en-GB/Help/listen.tid
* Add new tiddler editions/tw5.com/tiddlers/webserver/WebServer Parameter_ sse-enabled.tid
* Add sse_enabled to /status JSON response
* Store syncer polling status in $:/config/SyncDisablePolling
* Handled disabling polling in core/modules/syncer.js
@NicolasPetton NicolasPetton force-pushed the add-server-sent-events branch from 1e70cfb to 5a9ae03 Compare January 13, 2021 20:59
@NicolasPetton
Copy link
Contributor Author

@Jermolene I've fixed all the styling issues, plus:

  • Added a new WebServer parameter sse-enabled, which is disabled by default.
  • When enabled, polling is disabled in syncer.js. The /status JSON response now contains a new sse_enabled field.
  • I documented the new sse-enabled param in a new tiddler and added a list item in core/language/en-GB/Help/listen.tid

Copy link
Member

@pmario pmario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good to me

@Jermolene
Copy link
Member

Bravo, and thank you @NicolasPetton looks great.

@linonetwo
Copy link
Contributor

Wow, amazing feature, will this make #3060 possible?

@Jermolene
Copy link
Member

Wow, amazing feature, will this make #3060 possible?

Sadly no: #3060 is about syncing between the serverside wiki and the file system, while SSE just improve things between the clientside wiki and the serverside wiki.

@Jermolene
Copy link
Member

As discussed in #5853 (comment), I'm reverting this PR in favour of a slightly different approach: we will add the hooks required to enable SSE implementations to be undertaken in plugins.

@Jermolene
Copy link
Member

Apologies, to clarify that the reverting is being done in #5853

@Jermolene Jermolene mentioned this pull request Jul 14, 2021
Arlen22 added a commit to Arlen22/TiddlyWiki5 that referenced this pull request Jul 14, 2021
This reverts commit 17b4f53 according to Github Desktop.

git checkout that commit
revert commit in GitHub Desktop
git switch -c revert-sse
uncommit in Github Desktop
switch to master, bringing changes
resolve deletions with command line
@pmario
Copy link
Member

pmario commented Jul 14, 2021

Wow, amazing feature, will this make #3060 possible?

@linonetwo ... You can user curl or an other tool to send new files to the server instead of creating them with an editor. So if the serve gets the info about new tiddlers that way all the syncing should be done automatically. See the discussion on GG

Jermolene pushed a commit that referenced this pull request Jul 14, 2021
This reverts commit 17b4f53 according to Github Desktop.

git checkout that commit
revert commit in GitHub Desktop
git switch -c revert-sse
uncommit in Github Desktop
switch to master, bringing changes
resolve deletions with command line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants