@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
69 lines (38 loc) • 1.18 kB
Markdown
---
lang: en
title: 'API docs: socketio.socketio.subscribe'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/extensions/socketio
permalink: /doc/en/lb4/apidocs.socketio.socketio.subscribe.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/socketio](./socketio.md) > [socketio](./socketio.socketio.md) > [subscribe](./socketio.socketio.subscribe.md)
## socketio.subscribe() function
Decorate a method to subscribe to socketio events. For example,
```ts
@socketio.subscribe('chat message')
async function onChat(msg: string) {
}
```
**Signature:**
```typescript
function subscribe(...messageTypes: (string | RegExp)[]): MethodDecorator;
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td markdown="1">
messageTypes
</td><td markdown="1">
(string \| RegExp)\[\]
</td><td markdown="1">
</td></tr>
</tbody></table>
**Returns:**
MethodDecorator