MCPcopy Create free account
hub / github.com/Comfy-Org/litegraph.js / connectSlots

Method connectSlots

src/LGraphNode.ts:2602–2700  ·  view source on GitHub ↗

* Connect two slots between two nodes * @param output The output slot to connect * @param inputNode The node that the input slot is on * @param input The input slot to connect * @param afterRerouteId The reroute ID to use for the link * @returns The link that was created, or null if t

(
    output: INodeOutputSlot,
    inputNode: LGraphNode,
    input: INodeInputSlot,
    afterRerouteId: RerouteId | undefined,
  )

Source from the content-addressed store, hash-verified

2600 * @returns The link that was created, or null if the connection was blocked
2601 */
2602 connectSlots(
2603 output: INodeOutputSlot,
2604 inputNode: LGraphNode,
2605 input: INodeInputSlot,
2606 afterRerouteId: RerouteId | undefined,
2607 ): LLink | null | undefined {
2608 const { graph } = this
2609 if (!graph) throw new NullGraphError()
2610
2611 const outputIndex = this.outputs.indexOf(output)
2612 if (outputIndex === -1) {
2613 console.warn("connectSlots: output not found")
2614 return
2615 }
2616 const inputIndex = inputNode.inputs.indexOf(input)
2617 if (inputIndex === -1) {
2618 console.warn("connectSlots: input not found")
2619 return
2620 }
2621
2622 // check targetSlot and check connection types
2623 if (!LiteGraph.isValidConnection(output.type, input.type)) {
2624 this.setDirtyCanvas(false, true)
2625 return null
2626 }
2627
2628 // Allow nodes to block connection
2629 if (inputNode.onConnectInput?.(inputIndex, output.type, output, this, outputIndex) === false)
2630 return null
2631 if (this.onConnectOutput?.(outputIndex, input.type, input, inputNode, inputIndex) === false)
2632 return null
2633
2634 // if there is something already plugged there, disconnect
2635 if (inputNode.inputs[inputIndex]?.link != null) {
2636 graph.beforeChange()
2637 inputNode.disconnectInput(inputIndex, true)
2638 }
2639
2640 const link = new LLink(
2641 ++graph.state.lastLinkId,
2642 input.type || output.type,
2643 this.id,
2644 outputIndex,
2645 inputNode.id,
2646 inputIndex,
2647 afterRerouteId,
2648 )
2649
2650 // add to graph links list
2651 graph._links.set(link.id, link)
2652
2653 // connect in output
2654 output.links ??= []
2655 output.links.push(link.id)
2656 // connect in input
2657 inputNode.inputs[inputIndex].link = link.id
2658
2659 // Reroutes

Callers 2

connectMethod · 0.95
convertToSubgraphMethod · 0.45

Calls 10

setDirtyCanvasMethod · 0.95
isValidConnectionMethod · 0.80
beforeChangeMethod · 0.80
disconnectInputMethod · 0.80
setMethod · 0.80
addMethod · 0.80
getMethod · 0.80
afterChangeMethod · 0.80
removeFloatingLinkMethod · 0.65
getReroutesMethod · 0.45

Tested by

no test coverage detected