# Implement a shairport-sync Airplay server into Node-Red

**URL:** https://discourse.nodered.org/t/implement-a-shairport-sync-airplay-server-into-node-red/61321
**Category:** General
**Created:** [15 April 2022 08:19 UTC](https://discourse.nodered.org/t/implement-a-shairport-sync-airplay-server-into-node-red/61321 "2022-04-15T08:19:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pagaille](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pagaille/32/18808_2.png) [@pagaille](https://discourse.nodered.org/u/pagaille)
#### Post date: [15 April 2022 08:19 UTC](https://discourse.nodered.org/t/implement-a-shairport-sync-airplay-server-into-node-red/61321/1 "2022-04-15T08:19:45Z")

</div>

Hi there,

I would like to integrate a shairport-sync instance into my node-red flow.

The goal is being able to start / stop an airplay server listening to streams coming for iDevices and send that stream to the speaker output of a raspberry.

I (very naively) tried to import the shairport-sync module into a function node and piping the output stream to msg.speech and output it to a node-red-contrib-speakerpi-output node.

```auto
[
    {
        "id": "10ba55bf0ff143a6",
        "type": "function",
        "z": "c472a0f874cdcb87",
        "name": "",
        "func": "const airplay = new shairportSync();\nairplay.name = 'My Airplay Receiver';\nairplay.start();\nairplay.output.stream.pipe(msg.speech);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [
            {
                "var": "shairportSync",
                "module": "shairport-sync"
            }
        ],
        "x": 400,
        "y": 140,
        "wires": [
            [
                "3186abae45bab32d",
                "cc194a98caec879a"
            ]
        ]
    },
    {
        "id": "cc194a98caec879a",
        "type": "speakerpi-output",
        "z": "c472a0f874cdcb87",
        "choose": "streambased",
        "filename": "",
        "channels": "2",
        "bitdepth": "16",
        "samplerate": "44100",
        "name": "",
        "x": 640,
        "y": 140,
        "wires": [
            []
        ]
    }
]

```

As naive as it is, it doesn't work 😊 The function node claims that `"TypeError: shairportSync is not a constructor"`.

Yet the module is installed as expected by node-red :

```auto
[info] Installing module: shairport-sync, version: latest
[info] Installed module: shairport-sync

```

Any idea ?

Thanks

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [15 April 2022 09:27 UTC](https://discourse.nodered.org/t/implement-a-shairport-sync-airplay-server-into-node-red/61321/2 "2022-04-15T09:27:41Z")

</div>

> [@pagaille](#):
>
> `const airplay = new shairportSync();`

It is likely the constructor is inside the import e.g....

```auto
const airplay = new shairportSync.shairportSync();

```

... But I don't know it's name.

Try adding it to the msg so you can inspect it in the debug sidebar...

```auto
msg.payload = shairportSync;
return msg;

```

---

<div class="post-metadata">

### Author: ![pagaille](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pagaille/32/18808_2.png) [@pagaille](https://discourse.nodered.org/u/pagaille)
#### Post date: [15 April 2022 09:44 UTC](https://discourse.nodered.org/t/implement-a-shairport-sync-airplay-server-into-node-red/61321/3 "2022-04-15T09:44:44Z")

</div>

Good idea, thanks.

I tried `const airplay = new shairportSync.ShairportSync();` but it crashed node-red :

```auto
[red] Uncaught Exception:
[error] Error: spawn shairport-sync ENOENT

```

I'm not fluent in js and therefore might not understand exactly what I'm doing 😊

Inspecting reports this :

```auto
object :
ShairportSync: function
Output: function
Stream: function
Pipe: function
Stdout: function

```

The source code for the module is here : [GitHub - JJK801/node-shairport-sync: Node.js wrapper for shairport-sync](https://github.com/JJK801/node-shairport-sync/), maybe it will give you some idea ?

---

<div class="post-metadata">

### Author: ![pagaille](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pagaille/32/18808_2.png) [@pagaille](https://discourse.nodered.org/u/pagaille)
#### Post date: [15 April 2022 15:02 UTC](https://discourse.nodered.org/t/implement-a-shairport-sync-airplay-server-into-node-red/61321/4 "2022-04-15T15:02:23Z")

</div>

A bit more details :

So I do this in setup :

```auto
import shairport-sync as shairportsync

```

(first field : `shairport-sync`, second field : `shairportsync`)

then

```auto
const airplay = new shairportsync.ShairportSync();
airplay.name = 'My Airplay Receiver';
airplay.start();
airplay.output.stream.pipe(msg.speech);
return msg;

```

Nodered crashes and reports this in the logs :

```auto
 node-red[3053]: 15 Apr 16:47:21 - [error] Error: spawn shairport-sync ENOENT
 node-red[3053]: at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
 node-red[3053]: at onErrorNT (node:internal/child_process:476:16)
 node-red[3053]: at processTicksAndRejections (node:internal/process/task_queues:83:21)

```

The module's documentation suggest to import like this :

```auto
import {ShairportSync} from 'shairport-sync';

```

Tried to add the braces in the setup tab but that didn't work.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [14 June 2022 15:03 UTC](https://discourse.nodered.org/t/implement-a-shairport-sync-airplay-server-into-node-red/61321/5 "2022-06-14T15:03:09Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
