Skip to content
ozanturgut edited this page Jan 22, 2013 · 10 revisions

Exported Module

module(Object options)

When Queen is `require`'d into another project, this function is what is returned. > **Param: Object _options_** A map of options: * **_callback_ (Function)** A callback that will receive the Queen instance once it's ready. * **_captureHost_ (String, default=[IP ADDRESS]:80** The host at which to capture browsers. * **_log_ (Function)** A logging function which takes in a string as the first parameter
* **_debug_ (Function)** A debug logging function which takes in a string as the first parameter
* **_registerationTimeout_ (Number, default=10000)** How many miliseconds to allow a connection to register itself before closing it. * **_heartbeatInterval_ (Number, default=60000)** How many miliseconds to allow a connected browser has to send a heartbeat until it's considered unresponsive.

Queen Instance

'workforce' event

> **Fires** Whenever a new workforce is spawned
**Emits: [Workforce](#workforce)**The new workforce

'workerProvider' event

> **Fires** Whenever a new worker provider connects and registers
**Emits: [WorkerProvider](#workerProvider)** The new worker provider

'dead' event

> **Fires** When this instance is killed.
**Emits: undefined**

queen(Object workforceConfig)

Sets up and returns a workforce instance given a configuration object. > **Param: Object _workforceConfig_** A configuration object which defines workforce behavior, only the scripts value is required: > * **_run_ (Array<String>, required)** An ordered array of URLs for scripts the workers will load. * **_killOnStop_ (boolean, default=true)** Whether the workforce should kill itself as soon as it's worker count reaches 0 * **_populate_ (String, default="once")** * "manual": The workforce will not be automatically populated. * "once": The workforce will be populated by all currently available worker providers. * "continuous": The workforce will be populated by all currently available worker providers AND all future worker providers. * **_timeout_ (Number, default=Infinity)** The number of milliseconds each worker has until it's .kill()'d automatically. * **_handler_ (Function([Worker](#worker)))** A function which receives any workers which are added to the workforce. * **_stop_ (Function())** A function which gets called when all workforce no longer has any workers connected. * **_autoStart_ (Boolean, default=true)** Whether the workforce should start immediately. If not, need to manually call the `.start()` method. * **_filter_ (Function([WorkerProvider Attributes](#workerProvider)))** A filter function which returns true or false given a worker provider, determining whether the workforce should attempt to get workers from that provider. * **_uniqueness_ (Function([WorkerProvider Attributes](#workerProvider)))** A function which returns a string to use to determine if two browsers should be considered the "same" and therefore, only one will end up executing the test. This means if the function returned the browser family name, only one browser connected per browser family will run this script. > **Returns: [Workforce](#workforce)** The workforce for the given worker config

queen.on(String eventName, Function callback)

> **Param: String _eventName_** The event to listen to
**Param: Function _callback_** The function to execute when the event fires
**Returns: undefined**

queen.removeListener(String eventName [, Function boundCallback])

If a bound callback function is not provided, all listeners will be removed for the given event. > **Param: String _eventName_** The event to stop listening to
**Optional Param: Function _boundCallback_** The bound function to remove from the listener
**Returns: undefined**

queen.kill()

Kills this queen and all of it's workforces. > **Returns: undefined**

queen.log()

Outputs a log message to the console (you need to provide the new line characters). This message is only shown if queen is not running in quiet mode. > **Returns: undefined**

queen.debug()

Outputs a debug message to the console (you need to provide the new line characters). This message is only shown if queen is running in verbose mode. > **Returns: undefined**

queen.workerProviders

The connected worker providers > **Type: Array<[WorkerProvider](#workerProvider)>**

Workforce Instance

'message' event

> **Fires** Whenever a worker in the workforce sends a message
**Emits: (Object, [Worker](#worker))** The message object and the worker it was sent from

'dead' event

> **Fires** When this instance is killed
**Emits: undefined**

workforce(anything message)

Broadcasts a message to all workers currently in the workforce. > **Param: Anything _message_** The message to broadcast to workers
**Returns: undefined**

workforce.on(String eventName, Function callback)

> **Param: String _eventName_** The event to listen to
**Param: Function _callback_** The function to execute when the event fires
**Returns: undefined**

workforce.removeListener(String eventName [, Function boundCallback])

If a bound callback function is not provided, all listeners will be removed for the given event. > **Param: String _eventName_** The event to stop listening to
**Optional Param: Function _boundCallback_** The bound function to remove from the listener
**Returns: undefined**

workforce.populate(WorkerProvider workerProvider)

> **Param: [WorkerProvider](#workerProvider) _workerProvider_** The worker provider to attempt to spawn a worker from.
**Returns: undefined**

workforce.populate(Array<WorkerProvider> workerProviders)

> **Param: Array<[WorkerProvider](#workerProvider)> _workerProviders_** The worker providers to attempt to spawn workers from.
**Returns: undefined**

workforce.kill()

Kills this workforce, along with all of it's workers. > **Returns: undefined**

Worker Instance

'message' event

> **Fires** When the client-side worker sends a message
**Emits: anything** Whatever JSON serializable data the client-side worker sent

'dead' event

> **Fires** When this worker is dead
**Emits: undefined**

worker(anything message)

Sends a message to the worker. > **Param: Anything _message_** The message to send to the worker
**Returns: undefined**

worker.on(String eventName, Function callback)

> **Param: String _eventName_** The event to listen to
**Param: Function _callback_** The function to execute when the event fires
**Returns: undefined**

worker.removeListener(String eventName [, Function boundCallback])

If a bound callback function is not provided, all listeners will be removed for the given event. > **Param: String _eventName_** The event to stop listening to
**Optional Param: Function _boundCallback_** The bound function to remove from the listener
**Returns: undefined**

worker.kill()

Kills this worker. > **Returns: undefined**

worker.id

A universally-unique identifier for this instance > **Type: String**

worker.provider

The provider instance that spawned this worker > **Type: [WorkerProvider](#workerProvider)**

WorkerProvider Instance

'available' event

> **Fires** When the worker provider is ready to spawn additional workers.
**Emits: undefined**

'unavailable' event

> **Fires** When the worker provider is unavailable to spawn additional workers.
**Emits: undefined**

'worker' event

> **Fires** whenever a new worker is spawned.
**Emits: [Worker](#worker)** A worker instance

'workerDead' event

> **Fires** whenever a worker spawned by this worker provider is dead.
**Emits: String** The id of the dead worker instance

'dead' event

> **Fires** when this worker provider is dead.
**Emits: undefined**

workerProvider(Object workerConfig, Function callback)

Attempts to spawn a new worker, if the worker provider is unavailable, the callback will get an undefined result. > **Param: Object _workerConfig_** A configuration object for an individual worker. * **_scripts_ (Array<String>, required)** An ordered array of URLs for scripts the worker will load. * **_timeout_ (Number, default=Infinity)** The number of milliseconds the worker has until it's .kill()'d automatically.

Param: Function callback A callback to call with a worker when it is created. If the worker provider is unavailable to spawn workers, the callback value will be undefined.
Returns: undefined

workerProvider.on(String eventName, Function callback)

> **Param: String _eventName_** The event to listen to
**Param: Function _callback_** The function to execute when the event fires
**Returns: undefined**

workerProvider.removeListener(String eventName [, Function boundCallback])

If a bound callback function is not provided, all listeners will be removed for the given event. > **Param: String _eventName_** The event to stop listening to
**Optional Param: Function _boundCallback_** The bound function to remove from the listener
**Returns: undefined**

workerProvider.kill()

Kills this workerProvider and all of it's active workers. > **Returns: undefined**

workerProvider.id

The universally-unique identifier for this instance. > **Type: String**

workerProvider.attributes

A map of attributes. > **Type: Object** * **userAgent (String)** The user agent string of the worker provider * **name (String)** Browser family and version as determined by user agent * **family (String)** Browser family as determined by user agent * **os (String)** Browser OS as determined by user agent * **version (Object)** * **_major_ (Number)** Major release id of browser as determined by user agent * **_minor_ (Number)** Minor release id of browser as determined by user agent * **_patch_ (Number)** Patch release of browser as determined by user agent * **capabilities (Object)** An object of the browsers capabilities as determined by [Modernizr](http://modernizr.com/docs/#s2). * **applicationcache (boolean)** * **audio(Boolean)** The strings below will be empty (not supported), "maybe", or "probably". * **m4a (String)** * **mp3 (String)** * **ogg (String)** * **wav (String)** * **backgroundsize (boolean)** * **borderimage (boolean)** * **borderradius (boolean)** * **boxshadow (boolean)** * **canvas (boolean)** * **canvastext (boolean)** * **cssanimations (boolean)** * **csscolumns (boolean)** * **cssgradients (boolean)** * **cssreflections(boolean)** * **csstransforms (boolean)** * **csstransforms3d (boolean)** * **csstransitions (boolean)** * **draganddrop (boolean)** * **flexbox (boolean)** * **fontface (boolean)** * **generatedcontent (boolean)** * **geolocation (boolean)** * **hashchange (boolean)** * **history(boolean)** * **hsla (boolean)** * **indexeddb (boolean)** * **inlinesvg (boolean)** * **input (Object)** * **autocomplete (boolean)** * **autofocus(boolean)** * **list (boolean)** * **max (boolean)** * **min (boolean)** * **multiple (boolean)** * **pattern (boolean)** * **placeholder (boolean)** * **required (boolean)** * **step (boolean)** * **inputtypes (Object)** * **color (boolean)** * **date (boolean)** * **datetime (boolean)** * **datetime-local (boolean)** * **email (boolean)** * **month (boolean)** * **number (boolean)** * **range (boolean)** * **search (boolean)** * **tel (boolean)** * **time (boolean)** * **url (boolean)** * **week (boolean)** * **localstorage (boolean)** * **multiplebgs (boolean)** * **opacity (boolean)** * **postmessage (boolean)** * **rgba (boolean)** * **sessionstorage (boolean)** * **smil (boolean)** * **svg(boolean)** * **svgclippaths (boolean)** * **textshadow (boolean)** * **touch (boolean)** * **video (Boolean)** The strings below will be empty (not supported), "maybe", or "probably". * **h264 (String)** * **ogg (String)** * **webm (String)** * **webgl (boolean)** * **websockets (boolean)** * **websqldatabase (boolean)** * **webworkers (boolean)**

Clone this wiki locally