OpenVeo Publish server

API Docs for: 8.0.0
Show:

Watcher

Summary

Defines a watcher to be aware of new resources added to one or several directories.

Constructor

Watcher

Syntax

Watcher

(
  • [options]
)

Summary

Parameters:

  • [options] Object optional

    Watcher options

    • [stabilityThreshold] Number optional

      Number of milliseconds to wait before considering a file as stable

Example:

// Create a new watcher
var watcher = new Watcher();

// Listen to watcher events
watcher.on('create', function(resourcePath) {
  console.log('A new file has been added : ' + resourcePath);
});

watcher.on('delete', function(resourcePath) {
  console.log('A file has been removed : ' + resourcePath);
});

watcher.on('watch', function(directoryPath) {
  console.log('A watcher is now running for directory ' + directoryPath);
});

watcher.on('error', function(error) {
  console.log(error);
});

// Ask watcher to watch directories
watcher.add([
  '/tmp/hotFolder1',
  '/tmp/hotFolder2',
  '/tmp/hotFolder3'
], function(results) {
  console.log(results);
});

// Ask watcher to stop watching directories
watcher.remove([
  '/tmp/hotFolder3'
]);

Item Index

Methods

Methods

add

Syntax

add

(
  • directoriesPaths
  • callback
)
async

Summary

Adds new directories to watch.

Parameters:

  • directoriesPaths Array

    The list of absolute directories paths to watch

  • callback Function

    The function to call when directories are being watched

    • Array The list of results with a property "error" if something went wrong

isWatched

Syntax

isWatched

(
  • directoryPath
)
Boolean private

Summary

Checks if a directory is actually being watched.

Parameters:

  • directoryPath String

    The absolute path of the directory to check

Returns:

Boolean:

true if directory is actually being watched, false otherwise

remove

Syntax

remove

(
  • [directoriesPaths]
)

Summary

Stops watching directories.

Parameters:

  • [directoriesPaths] Array optional

    The list of absolute directories' paths to stop watching. If no directories are specified all watching directories won't be watched anymore

Properties

directoriesWatchers

Syntax

directoriesWatchers

Array final

Summary

The list of directories' watchers actually running.

options

Syntax

options

Object final

Summary

Watcher options.

Events

create

Syntax

create

Summary

Fired when a new resource (file or directory) has been added to one of the watched folders.

Event Payload:

  • Path String

    of the added resource

delete

Syntax

delete

Summary

Fired when a resource (file or directory) has been deleted from one of the watched folders.

Event Payload:

  • Path String

    of the resource before it has been removed

error

Syntax

error

Summary

Fired when an error occurred.

Event Payload:

watch

Syntax

watch

Summary

Fired when a directory is added to watched directories.

Fired after "create" event in case the directory is added to an already watched directory.

Event Payload:

  • Path String

    of the directory