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

Companion server upload events #3544

Merged
merged 16 commits into from
Mar 24, 2022
Merged

Companion server upload events #3544

merged 16 commits into from
Mar 24, 2022

Conversation

mifi
Copy link
Contributor

@mifi mifi commented Mar 8, 2022

Expose companion emitter to allow the consumer to subscribe to upload success/failure events

fixes #3435

example code for how to listen to upload events: (can add to companion documentation)

const companionApp = companion.app(options)
const { companionEmitter: emitter } = companionApp

emitter.on('upload-start', ({ token }) => {
  console.log('Upload started', token)

  function onUploadEvent(message) {
    if (message.action === 'success') {
      emitter.off(token, onUploadEvent)
      console.log('Upload finished', token, message.payload.url);
    } else if (message.action === 'error') {
      emitter.off(token, onUploadEvent)
      console.error('Upload failed', message.payload);
    }
  }
  emitter.on(token, onUploadEvent)
})

Other improvements:

  • timeout waiting for client connection - fixes memory leak
  • fix test

@Murderlon
Copy link
Member

Can emitter.off also disable internal events which companion relies on? We have this problem in Uppy

mifi added 2 commits March 8, 2022 23:09
or jest will wait for them to time out
also fix broken test 'uploader respects maxFileSize with unknown size'
dynamic requires seem to cause flaky tests with jest.resetModules()
@mifi
Copy link
Contributor Author

mifi commented Mar 8, 2022

Can emitter.off also disable internal events which companion relies on? We have this problem in Uppy

As far as I know it will only remove the listener function that you specify

From https://nodejs.org/api/events.html#emitterremovelistenereventname-listener :

Removes the specified listener from the listener array for the event named eventName.

@mifi
Copy link
Contributor Author

mifi commented Mar 8, 2022

While working on this I got hit by a lot of issues related to tests depending on global state, so I created an issue about this: #3545

Base automatically changed from companion-refactor to main March 15, 2022 04:45
@mifi mifi changed the title Companion upload events Companion server upload events Mar 16, 2022
mifi and others added 2 commits March 24, 2022 19:45
@aduh95 aduh95 merged commit 0033b9f into main Mar 24, 2022
@aduh95 aduh95 deleted the companion-upload-events branch March 24, 2022 12:14
@github-actions github-actions bot mentioned this pull request Mar 24, 2022
github-actions bot added a commit that referenced this pull request Mar 24, 2022
| Package           | Version | Package           | Version |
| ----------------- | ------- | ----------------- | ------- |
| @uppy/companion   |   3.5.0 | @uppy/webcam      |   2.1.0 |
| @uppy/status-bar  |   2.1.3 | @uppy/robodog     |   2.5.0 |
| @uppy/transloadit |   2.1.2 | uppy              |   2.9.0 |
| @uppy/tus         |   2.2.1 |                   |         |

- @uppy/transloadit: close assembly if upload is cancelled (Antoine du Hamel / #3591)
- @uppy/companion: Companion server upload events (Mikael Finstad / #3544)
- @uppy/tus: fix double requests sent when rate limiting (Antoine du Hamel / #3595)
- website: fix linter error on blog post (Antoine du Hamel / #3596)
- @uppy/companion: fix `yarn test` command (Antoine du Hamel / #3590)
- @uppy/webcam: Mime types in webcam options type (Sobakin Sviatoslav / #3593)
- website: Some polish and a better (?) intro for the recent update post (AJvanLoon / #3588)
- @uppy/companion: Allow setting no ACL (Mikael Finstad / #3577)
- @uppy/companion: Small companion code and doc changes (Mikael Finstad / #3586)
- @uppy/robodog: fix CDN bundle (Antoine du Hamel / #3587)
- website: Fix broken link (YukeshShr / #3581)
HeavenFox pushed a commit to docsend/uppy that referenced this pull request Jun 27, 2023
* modernise code

* pull out config related functions and middleware

* make test more readable

* Expose companion emitter

to allow the consumer to subscribe to upload success/failure events

fixes transloadit#3435

* disable client socket timeout for tests

or jest will wait for them to time out
also fix broken test 'uploader respects maxFileSize with unknown size'

* document the event emitter usage
HeavenFox pushed a commit to docsend/uppy that referenced this pull request Jun 27, 2023
| Package           | Version | Package           | Version |
| ----------------- | ------- | ----------------- | ------- |
| @uppy/companion   |   3.5.0 | @uppy/webcam      |   2.1.0 |
| @uppy/status-bar  |   2.1.3 | @uppy/robodog     |   2.5.0 |
| @uppy/transloadit |   2.1.2 | uppy              |   2.9.0 |
| @uppy/tus         |   2.2.1 |                   |         |

- @uppy/transloadit: close assembly if upload is cancelled (Antoine du Hamel / transloadit#3591)
- @uppy/companion: Companion server upload events (Mikael Finstad / transloadit#3544)
- @uppy/tus: fix double requests sent when rate limiting (Antoine du Hamel / transloadit#3595)
- website: fix linter error on blog post (Antoine du Hamel / transloadit#3596)
- @uppy/companion: fix `yarn test` command (Antoine du Hamel / transloadit#3590)
- @uppy/webcam: Mime types in webcam options type (Sobakin Sviatoslav / transloadit#3593)
- website: Some polish and a better (?) intro for the recent update post (AJvanLoon / transloadit#3588)
- @uppy/companion: Allow setting no ACL (Mikael Finstad / transloadit#3577)
- @uppy/companion: Small companion code and doc changes (Mikael Finstad / transloadit#3586)
- @uppy/robodog: fix CDN bundle (Antoine du Hamel / transloadit#3587)
- website: Fix broken link (YukeshShr / transloadit#3581)
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.

How to track the completion of upload to s3 via companion
3 participants