---
url: https://gudhub.com/ru/docs/core-api/pipe-server/
title: "Pipe\n                #"
description: "Roughly speaking, pipe is data layer that ensures data exchange. All methods that allow to pull data are contained in Pipe Server . It is a set of events that a"
lang: uk
updated: 2026-09-12T04:41:24.036Z
---

# Pipe [#](https://gudhub.com/ru/docs/core-api/pipe-server/#pipe)

Roughly speaking, pipe is data layer that ensures data exchange.

All methods that allow to pull data are contained in **Pipe Server**. It is a set of events that allows to listen to the events and deliver data.It is based on Node.js Event Emitters & Observer Pattern.

The PipeServer works due to the subscriptions. They help to exchange data. Every field can subscribes to the events.

PipeService has tree methods:

-   [`gudhub.on(event, address, fn)`](#on)
-   [`gudhub.emit(event, destination, address, params)`](#emit)
-   [`gudhub.destroy(event, address, fn)`](#destroy)

| Name | Type | Description |
| :-- | :-- | :-- |
| event | `string` | _accepts the name of the event_ |
| address | `object` | _accepts address of the field where the event located_ |
| fn | `function` | _accepts the function_ |
| destination | `object` | _event recipient_ |
| params | `-` | _parameters that are passed to the function_ |

> Any type of data can be passed as a _parameter_.

## On() [#](https://gudhub.com/ru/docs/core-api/pipe-server/#on)

This is the method that is called for getting subscription.

It accepts three arguments:

-   event
-   address
-   function

Копировать

```js
import GudHub from '@gudhub/core';
const gudhub = new GudHub();
let address = {
    app_id: newApp.app_id;
};


// the function will be executed when event happens 
function myFunction(event, value){
    console.log('new app name', value.app_name);

    //if you do not want listen the event anymore, you can destroy it  
    gudhub.destroy('gh_app_info_update', address, myFunction);
};

gudhub.on('gh_app_info_update', address, myFunction);
```

Also, you can subscribe to several events at the same time:

Копировать

```js
import GudHub from '@GudHub/core';
const gudhub = new GudHub();
let address = {
    app_id: 12345;
};


// function for passing two values of the argument
function myFunction(event, value){
    switch(event) {

        case 'gh_item_update':
            alert( 'Updated Item Event!' );
            break;

        case 'gh_model_update': 
            alert( 'Updated Model Event!' );
            break
    }
    //if you do not want listen the event anymore, you can destroy it  
    gudhub.destroy('gh_item_update gh_model_update', address, myFunction);
};

gudhub.on('gh_item_update gh_model_update', model_address, myFunction)
```

## Emit() [#](https://gudhub.com/ru/docs/core-api/pipe-server/#emit)

This is the method that is used by GudHub itself. It is called for getting existing subscription. Emit can work without recipient. That means it is called even if no one has subscribed.

It takes four arguments:

-   event
-   destination
-   address
-   params

In addition to existing events, you can devise your own event and emit it.

| Event name | Address | Description |
| :-- | :-- | :-- |
| gh\_apps\_list\_update | \- | allows to update the application list |
| gh\_apps\_list\_refreshed | \- | allows to refresh app list |
| gh\_app\_info\_update | `app_id` | updates application information |
| gh\_app\_views\_update | `app_id` | updates application views |
| gh\_document\_insert\_one | `app_id`, `item_id`, `element_id` | adds a document or updates a document if it exists |
| gh\_filter\_items | \- | allows to filter items in the application |
| gh\_items\_add | `app_id` | adds items to the item list |
| gh\_item\_update | `app_id`, `item_id` | updates the value of any item field |
| gh\_items\_update | `app_id` | updates the value of items field |
| gh\_model\_update | `app_id`, `field_id` | updates field model in field\_list |
| gh\_model\_delete | \- | deletes field model from field\_list and from items |
| gh\_file\_upload | `app_id`, `item_id`, `file_id` | allows to add file to the file list |
| gh\_file\_update | `app_id`, `file_id` | updates file data in the file list |
| gh\_file\_delete | `app_id`, `file_id` | deletes file from the file list |
| gh\_value\_update | `app_id`, `item_id`, `field_id` | updates field value in item |

The example of using the emit method:

Копировать

```js
this.pipeService.emit(
    "gh_app_views_update",
    { app_id: newApp.app_id },
    newApp.views_list
);
```

## WebSocket Bridge (`/ws/emit-to-user`) [#](https://gudhub.com/ru/docs/core-api/pipe-server/#websocket-bridge-ws-emit-to-user)

In addition to the built-in events listed above, `gudhub.pipeService` is also used as a bridge for real-time messages received through the [`/ws/emit-to-user`](https://gudhub.com/ru/docs/rest-api/web-sockets/#ws-emit-to-user) WebSocket message.

When such a message arrives, `WebsocketHandler` parses its `response` and re-emits it through the pipe:

Копировать

```js
const emitToUserData = JSON.parse(message.response);
gudhub.pipeService.emit(emitToUserData.service_id, { user_id: message.user_id }, emitToUserData);
```

To receive these messages, a service must:

-   send data via `gudhub.emitToUser(user_id, data)` with a unique **`service_id`** always included in `data` (e.g. `"gudhub_messenger"`). It is used as the pipe **event name**.
-   subscribe with `gudhub.pipeService.on(service_id, { user_id }, fn)`, where `user_id` is the ID of the other participant - the same value that arrives in the WebSocket message as `message.user_id` (the message sender, from the recipient's perspective).

| Property | Type | Description |
| :-- | :-- | :-- |
| service\_id | `string` | **required**. Identifies the service/feature the message belongs to (e.g. `"gudhub_messenger"`). Used as the pipe event name. |
| user\_id | `string` or `number` | ID of the other participant. Used as the pipe address (`{ user_id }`). |

_**Example**_

Sending a message from the server:

Копировать

```js
await gudhub.emitToUser(recipient_id, {
    conversation_id: "f47ac10b-58cc-4372-a567-0e02b2c3d479",
    message: { message_id: "...", user_id: sender_id, content: "Hello", type: "text", timestamp: Date.now() },
    service_id: "gudhub_messenger"
});
```

Subscribing to it on the client:

Копировать

```js
function handleNewMessage(error, data){
    console.log('new message', data.message);
};

gudhub.pipeService.on('gudhub_messenger', { user_id: otherUserId }, handleNewMessage);

// if you do not want to listen to the event anymore, you can destroy it
gudhub.pipeService.destroy('gudhub_messenger', { user_id: otherUserId }, handleNewMessage);
```

## Destroy() [#](https://gudhub.com/ru/docs/core-api/pipe-server/#destroy)

For some time, all of subscriptions are accumulated in memory. And they do not know that they must be destroyed for optimum work. So, the destroy method exists for ruining extra subscriptions and for optimization the process.

If the destroy method is contained in a function, it means that the event is a one-time event.

Destroy takes the same arguments as the [on](#on) method: event, address, function.

Копировать

```js
import GudHub from '@gudhub/core';
const gudhub = new GudHub();
let address = {
    app_id: newApp.app_id;
};


// the function will be executed when event happens 
function myFunction(event, value){
    console.log('new app name', value.app_name);

    //if you do not want listen the event anymore, you can destroy it  
    gudhub.destroy('gh_app_views_update', address, myFunction);
};

gudhub.on('gh_app_views_update', address, myFunction);
```
