# Class: NodeSocket

## NodeSocket(node, direction, category, name)

#### new NodeSocket(node, direction, category, name)

Represents a node hook point. Is attached to the node element and represented visually. Can be used as a node input, output or as a bidirectional connection.

##### Parameters:

Name | Type | Description
--- | --- | ---
`node` | Node | Node of this hook.
`direction` | number | Direction of the hook.
`category` | string | Data category of the node socket.
`name` | string | Name of the node socket.

Source:
  - objects/node/NodeSocket.js, line 19

### Extends

- Circle

### Members

#### (static, constant) INPUT :number

Input hook can only be connected to an output. Is used to read data from the output.

##### Type:

- number

Source:
  - objects/node/NodeSocket.js, line 121

#### (static, constant) OUTPUT :number

Output hook can only be connected to an input. Writes data to the output.

##### Type:

- number

Source:
  - objects/node/NodeSocket.js, line 131

#### beingDragged :boolean

Flag to indicate if the object is currently being dragged.

##### Type:

- boolean

Inherited From:
  - Object2D#beingDragged
Source:
  - Object2D.js, line 201

#### category :string

Category of data available from this socket. Only sockets of the same category can be connected. Should directly store the data type name (e.g. "string", "number", "Object", etc).

##### Type:

- string

Source:
  - objects/node/NodeSocket.js, line 41

#### children :Array.<Object2D>

List of children objects attached to the object.

##### Type:

- Array.<Object2D>

Inherited From:
  - Object2D#children
Source:
  - Object2D.js, line 28

#### connectors :Array.<NodeConnector>

Node connector used to connect this socket to another node socket. Can be used to access the adjacent node. If the socket allows for multiple connections this array can have multiple elements.

##### Type:

- Array.<NodeConnector>

Source:
  - objects/node/NodeSocket.js, line 77

#### creatingConnection :boolean

Indicates if the user is currently creating a new connection from this node socket.

##### Type:

- boolean

Source:
  - objects/node/NodeSocket.js, line 84

#### direction :number

Direction of the node hook, indicates the data flow of the socket. Can be INPUT or OUTPUT.

##### Type:

- number

Source:
  - objects/node/NodeSocket.js, line 59

#### draggable :boolean

Draggable controls if its possible to drag the object around. Set this true to enable dragging events on this object. The onPointerDrag callback is used to update the state of the object while being dragged, by default it just updates the object position.

##### Type:

- boolean

Overrides:
  - Circle#draggable
Source:
  - Object2D.js, line 155

#### draw

Draw the object into the canvas, this is called transform() and style(), should be where the content is actually drawn into the canvas. Should be implemented by underlying classes.

Inherited From:
  - Object2D#draw
Source:
  - Object2D.js, line 487

#### fillStyle :Style

Background color of the circle. If set null it is ignored.

##### Type:

- Style

Inherited From:
  - Circle#fillStyle
Source:
  - objects/Circle.js, line 47

#### globalMatrix :Matrix

Global transformation matrix multiplied by the parent matrix. Used to transform the object before projecting into screen coordinates.

##### Type:

- Matrix

Inherited From:
  - Object2D#globalMatrix
Source:
  - Object2D.js, line 110

#### ignoreViewport :boolean

Flag to indicate whether this object ignores the viewport transformation.

##### Type:

- boolean

Inherited From:
  - Object2D#ignoreViewport
Source:
  - Object2D.js, line 171

#### inverseGlobalMatrix :Matrix

Inverse of the global (world) transform matrix. Used to convert pointer input points (viewport space) into object coordinates.

##### Type:

- Matrix

Inherited From:
  - Object2D#inverseGlobalMatrix
Source:
  - Object2D.js, line 119

#### layer :number

Layer of this object, objects are sorted by layer value. Lower layer value is draw first, higher layer value is drawn on top.

##### Type:

- number

Overrides:
  - Circle#layer
Source:
  - Object2D.js, line 94

#### level :number

Depth level in the object tree, objects with higher depth are drawn on top. The layer value is considered first.

##### Type:

- number

Inherited From:
  - Object2D#level
Source:
  - Object2D.js, line 44

#### lineWidth :number

Line width, only used if a valid strokeStyle is defined.

##### Type:

- number

Inherited From:
  - Circle#lineWidth
Source:
  - objects/Circle.js, line 38

#### masks :Array.<Mask>

Mask objects being applied to this object. Used to mask/subtract portions of this object when rendering. Multiple masks can be used simultaneously. Same mask might be reused for multiple objects.

##### Type:

- Array.<Mask>

Inherited From:
  - Object2D#masks
Source:
  - Object2D.js, line 128

#### matrix :Matrix

Local transformation matrix applied to the object.

##### Type:

- Matrix

Inherited From:
  - Object2D#matrix
Source:
  - Object2D.js, line 101

#### matrixAutoUpdate :boolean

Indicates if the transform matrix should be automatically updated every frame. Set this false for better performance. But if you do so dont forget to set matrixNeedsUpdate every time that a transform attribute is changed.

##### Type:

- boolean

Inherited From:
  - Object2D#matrixAutoUpdate
Source:
  - Object2D.js, line 137

#### matrixNeedsUpdate :boolean

Indicates if the matrix needs to be updated, should be set true after changes to the object position, scale or rotation. The matrix is updated before rendering the object, after the matrix is updated this attribute is automatically reset to false.

##### Type:

- boolean

Inherited From:
  - Object2D#matrixNeedsUpdate
Source:
  - Object2D.js, line 146

#### multiple :boolean

Allow to connect a OUTPUT node to multiple INPUT sockets. A INPUT socket can only take one connection, this value is ignored for INPUT sockets.

##### Type:

- boolean

Source:
  - objects/node/NodeSocket.js, line 50

#### name :string

Name of the socket presented to the user.

##### Type:

- string

Source:
  - objects/node/NodeSocket.js, line 32

#### node :Node

Node where this socket is attached to. Should be used to get data from node GUI and from other sockets.

##### Type:

- Node

Source:
  - objects/node/NodeSocket.js, line 68

#### onAdd

Method called when the object its added to a parent.

Inherited From:
  - Object2D#onAdd
Source:
  - Object2D.js, line 529

#### onButtonDown

Callback method called when the pointer button is pressed down (single time).

Inherited From:
  - Object2D#onButtonDown
Source:
  - Object2D.js, line 595

#### onButtonPressed

Method called while the pointer button is pressed.

Inherited From:
  - Object2D#onButtonPressed
Source:
  - Object2D.js, line 579

#### onButtonUp

Method called when the pointer button is released (single time).

Inherited From:
  - Object2D#onButtonUp
Source:
  - Object2D.js, line 603

#### onDoubleClick

Method called while the pointer button is double clicked.

Inherited From:
  - Object2D#onDoubleClick
Source:
  - Object2D.js, line 587

#### onPointerDragEnd

Callback method called when the pointer drag ends after the button has been released.

Overrides:
  - Circle#onPointerDragEnd
Source:
  - Object2D.js, line 522

#### onPointerDragStart

Callback method called when the pointer drag start after the button was pressed

Overrides:
  - Circle#onPointerDragStart
Source:
  - Object2D.js, line 514

#### onPointerEnter

Callback method called when the pointer enters the object. It is not called while the pointer is inside of the object, just on the first time that the pointer enters the object for that use onPointerOver()

Inherited From:
  - Object2D#onPointerEnter
Source:
  - Object2D.js, line 555

#### onPointerLeave

Method called when the was inside of the object and leaves the object.

Inherited From:
  - Object2D#onPointerLeave
Source:
  - Object2D.js, line 563

#### onPointerOver

Method while the pointer is over (inside) of the object.

Inherited From:
  - Object2D#onPointerOver
Source:
  - Object2D.js, line 571

#### onRemove

Method called when the object gets removed from its parent

Inherited From:
  - Object2D#onRemove
Source:
  - Object2D.js, line 536

#### onUpdate

Callback method called every time before the object is draw into the canvas. Should be used to run object logic, any preparation code, move the object, etc. This method is called for every object before rendering.

Inherited From:
  - Object2D#onUpdate
Source:
  - Object2D.js, line 545

#### origin :Vector2

Origin of the object used as point of rotation.

##### Type:

- Vector2

Inherited From:
  - Object2D#origin
Source:
  - Object2D.js, line 60

#### parent :Object2D

Parent object, the object position is affected by its parent position.

##### Type:

- Object2D

Inherited From:
  - Object2D#parent
Source:
  - Object2D.js, line 35

#### pointerEvents :boolean

Indicates if this object uses pointer events. Can be set false to skip the pointer interaction events, better performance if pointer events are not required.

##### Type:

- boolean

Inherited From:
  - Object2D#pointerEvents
Source:
  - Object2D.js, line 164

#### pointerInside :boolean

Flag indicating if the pointer is inside of the element. Used to control object event.

##### Type:

- boolean

Inherited From:
  - Object2D#pointerInside
Source:
  - Object2D.js, line 194

#### position :Vector2

Position of the object. The world position of the object is affected by its parent transform.

##### Type:

- Vector2

Inherited From:
  - Object2D#position
Source:
  - Object2D.js, line 53

#### radius :number

Radius of the circle.

##### Type:

- number

Overrides:
  - Circle#radius
Source:
  - objects/Circle.js, line 22

#### restoreContextState :boolean

Flag to indicate if the context of canvas should be restored after render.

##### Type:

- boolean

Inherited From:
  - Object2D#restoreContextState
Source:
  - Object2D.js, line 185

#### rotation :number

Rotation of the object relative to its center. The world rotation of the object is affected by the parent transform.

##### Type:

- number

Inherited From:
  - Object2D#rotation
Source:
  - Object2D.js, line 78

#### saveContextState :boolean

Flag to indicate if the context of canvas should be saved before render.

##### Type:

- boolean

Inherited From:
  - Object2D#saveContextState
Source:
  - Object2D.js, line 178

#### scale :Vector2

Scale of the object. The world scale of the object is affected by the parent transform.

##### Type:

- Vector2

Inherited From:
  - Object2D#scale
Source:
  - Object2D.js, line 69

#### serializable :boolean

Indicates if the object should be serialized or not as a child of another object. Used to prevent duplicate serialization data on custom objects. Should be set false for objects added on constructor.

##### Type:

- boolean

Inherited From:
  - Object2D#serializable
Source:
  - Object2D.js, line 210

#### strokeStyle :Style

Style of the object border line. If set null it is ignored.

##### Type:

- Style

Inherited From:
  - Circle#strokeStyle
Source:
  - objects/Circle.js, line 31

#### style

Style is called right before draw() it should not draw any content into the canvas, all context styling should be applied here (colors, fonts, etc). The draw() and style() methods can be useful for objects that share the same styling attributes but are drawing differently. Should be implemented by underlying classes.

Inherited From:
  - Object2D#style
Source:
  - Object2D.js, line 476

#### text :Text

Text object used to present the name of the socket. Depending on the socket direction the text is aligned to the left or to the right.

##### Type:

- Text

Source:
  - objects/node/NodeSocket.js, line 93

#### type :string

Type of the object, used for data serialization and/or checking the object type. The name used should match the object constructor name. But it is not required. If this type is from an external library you can add the library name to the object type name to prevent collisions.

##### Type:

- string

Overrides:
  - Circle#type
Source:
  - Object2D.js, line 224

#### uuid :string

UUID of the object.

##### Type:

- string

Inherited From:
  - Object2D#uuid
Source:
  - Object2D.js, line 21

#### visible :boolean

Indicates if the object is visible.

##### Type:

- boolean

Inherited From:
  - Object2D#visible
Source:
  - Object2D.js, line 85

### Methods

#### add(object)

Attach a children to this object. The object is set as children of this object and the transformations applied to this object are traversed to its children.

##### Parameters:

Name | Type | Description
--- | --- | ---
`object` | Object2D | Object to attach to this object.

Inherited From:
  - Object2D#add
Source:
  - Object2D.js, line 368

#### attachConnector(connector)

Attach a node connector to this socket. Sets the correct input/output attributes on the socket and the connector. Automatically adds the connector to the same parent and the node socket if no parent defined for the connector.

##### Parameters:

Name | Type | Description
--- | --- | ---
`connector` | NodeConnector | Connector to be attached to this socket.

Source:
  - objects/node/NodeSocket.js, line 183

#### canAddConnector() → {boolean}

Check if this node socket can have a new connector attached to it. Otherwise it might be necessary to destroy old connectors before adding a new connector.

Source:
  - objects/node/NodeSocket.js, line 229

##### Returns:

True if its possible to add a new connector to the socket, false otherwise.

Type
  boolean

#### canConnect(socket) → {boolean}

Check if this socket can be connected with another socket, they have to be compatible and have space for a new connector.

##### Parameters:

Name | Type | Description
--- | --- | ---
`socket` | NodeSocket | Socket to verify connectivity with.

Source:
  - objects/node/NodeSocket.js, line 240

##### Returns:

Returns true if the two sockets can be connected.

Type
  boolean

#### connectTo(socket) → {NodeConnector}

Connect this node socket to another socket. Sockets have to be compatible otherwise the connection cannot be made and an error will be thrown.

##### Parameters:

Name | Type | Description
--- | --- | ---
`socket` | NodeSocket | Socket to be connected with this

Source:
  - objects/node/NodeSocket.js, line 163

##### Returns:

Node connector created.

Type
  NodeConnector

#### destroy()

Destroy the object, removes it from the parent object.

Overrides:
  - Circle#destroy
Source:
  - Object2D.js, line 317

#### destroyConnectors()

Destroy all connectors attached to this socket. Should be called when destroying the object or to clean up the object.

Source:
  - objects/node/NodeSocket.js, line 263

#### getChildByUUID(uuid) → {Object2D}

Get a object from its children list by its UUID.

##### Parameters:

Name | Type | Description
--- | --- | ---
`uuid` | string | UUID of the object to get.

Inherited From:
  - Object2D#getChildByUUID
Source:
  - Object2D.js, line 346

##### Returns:

The object that has the UUID specified, null if the object was not found.

Type
  Object2D

#### getValue() → {Object}

Get value stored or calculated in node socket, it should be the calculated from node logic, node inputs, user input, etc. For input nodes the value should be fetched trough the connector object that is connected to an output node elsewhere. By default it the socket is an INPUT it gets the value trough the connector if available. Inputs will recursively propagate the method trough the graph to get their value. If the socket is an OUTPUT or there is no connection the method returns null by default, in this case the method should be extended by implementations of this class to process data.

Source:
  - objects/node/NodeSocket.js, line 144

##### Returns:

Return data calculated from the node.

Type
  Object

#### getWorldPointIntersections(point, list) → {Array.<Object2D>}

Check if a point in world coordinates intersects this object or its children and get a list of the objects intersected.

##### Parameters:

Name | Type | Description
--- | --- | ---
`point` | Vector2 | Point in world coordinates.
`list` | Array.<Object2D> | List of objects intersected passed to children objects recursively.

Inherited From:
  - Object2D#getWorldPointIntersections
Source:
  - Object2D.js, line 259

##### Returns:

List of object intersected by this point.

Type
  Array.<Object2D>

#### isCompatible(socket) → {boolean}

Check if this socket is compatible (type and direction) with another socket. For two sockets to be compatible the data flow should be correct (one input and a output) and they should carry the same data type.

##### Parameters:

Name | Type | Description
--- | --- | ---
`socket` | NodeSocket | Socket to verify compatibility with.

Source:
  - objects/node/NodeSocket.js, line 217

##### Returns:

Returns true if the two sockets are compatible.

Type
  boolean

#### isInside(point) → {boolean}

Check if a point is inside of the object. Used by the renderer check for pointer collision (required for the object to properly process pointer events). Point should be in local object coordinates. To check if a point in world coordinates intersects the object the inverseGlobalMatrix should be applied to that point before calling this method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`point` | Vector2 | Point in local object coordinates.

Inherited From:
  - Object2D#isInside
Source:
  - Object2D.js, line 423

##### Returns:

True if the point is inside of the object.

Type
  boolean

#### isWorldPointInside(point, recursive) → {boolean}

Check if a point in world coordinates intersects this object or some of its children.

##### Parameters:

Name | Type | Description
--- | --- | ---
`point` | Vector2 | Point in world coordinates.
`recursive` | boolean | If set to true it will also check intersections with the object children.

Inherited From:
  - Object2D#isWorldPointInside
Source:
  - Object2D.js, line 289

##### Returns:

Returns true if the point in inside of the object.

Type
  boolean

#### onPointerDrag(pointer, viewport, delta, positionWorld)

Callback method while the object is being dragged across the screen. By default is adds the delta value to the object position (making it follow the mouse movement). Delta is the movement of the pointer already translated into local object coordinates. To detect when the object drag stops the onPointerDragEnd() method can be used.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pointer` | Pointer | Pointer object that receives the user input.
`viewport` | Viewport | Viewport where the object is drawn.
`delta` | Vector2 | Pointer movement diff in world space since the last frame.
`positionWorld` | Vector2 | Position of the dragging pointer in world coordinates.

Overrides:
  - Circle#onPointerDrag
Source:
  - Object2D.js, line 503

#### parse(data, root)

Parse serialized object data and fill the object attributes. Implementations of this method should only load the attributes added to the structure, the based method already loads common attributes. Dont forget to register object types using the Object2D.register() method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | Object data loaded from JSON.
`root` | Object2D | Root object being loaded can be used to get references to other objects.

Overrides:
  - Circle#parse
Source:
  - Object2D.js, line 668

#### remove(children)

Remove object from the children list. Resets the parent of the object to null and resets its level.

##### Parameters:

Name | Type | Description
--- | --- | ---
`children` | Object2D | Object to be removed.

Inherited From:
  - Object2D#remove
Source:
  - Object2D.js, line 391

#### removeConnector()

Destroy a connector attached to this socket, calls the destroy() method of the connection.

Source:
  - objects/node/NodeSocket.js, line 248

#### serialize(recursive) → {Object}

Serialize the object data into a JSON object. That can be written into a file, sent using HTTP request etc. All required attributes to recreate the object in its current state should be stored. Relations between children should be stored by their UUID only. Data has to be parsed back into a usable object.

##### Parameters:

Name | Type | Description
--- | --- | ---
`recursive` | boolean | If set false the children list is not serialized, otherwise all children are serialized.

Overrides:
  - Circle#serialize
Source:
  - Object2D.js, line 615

##### Returns:

Serialized object data.

Type
  Object

#### transform(context, viewport, canvas, renderer)

Apply the transform to the rendering context, it is assumed that the viewport transform is pre-applied to the context. This is called before style() and draw(). It can also be used for some pre-rendering logic.

##### Parameters:

Name | Type | Description
--- | --- | ---
`context` | CanvasRenderingContext2D | Canvas 2d drawing context.
`viewport` | Viewport | Viewport applied to the canvas.
`canvas` | Element | DOM canvas element where the content is being drawn.
`renderer` | Renderer | Renderer object being used to draw the object into the canvas.

Inherited From:
  - Object2D#transform
Source:
  - Object2D.js, line 460

#### traverse(callback)

Traverse the object tree and run a function for all objects.

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | function | Callback function that receives the object as parameter.

Inherited From:
  - Object2D#traverse
Source:
  - Object2D.js, line 330

#### updateMatrix(context)

Update the transformation matrix of the object.

##### Parameters:

Name | Type | Description
--- | --- | ---
`context` | CanvasRenderingContext2D | Canvas 2d drawing context.

Inherited From:
  - Object2D#updateMatrix
Source:
  - Object2D.js, line 433