Skip to content

Add pg dependency #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ Related packages:
## Installation

```
npm install @socket.io/postgres-adapter pg
npm install @socket.io/postgres-adapter
```

For TypeScript users, you might also need `@types/pg`.

## Usage

```js
Expand Down
7 changes: 4 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Adapter, BroadcastOptions, Room } from "socket.io-adapter";
import { randomBytes } from "crypto";
import { encode, decode } from "@msgpack/msgpack";
import { Pool } from "pg";

const randomId = () => randomBytes(8).toString("hex");
const debug = require("debug")("socket.io-postgres-adapter");
Expand Down Expand Up @@ -118,7 +119,7 @@ export interface PostgresAdapterOptions {
* @public
*/
export function createAdapter(
pool: any,
pool: Pool,
opts: Partial<PostgresAdapterOptions> = {}
) {
return function (nsp) {
Expand All @@ -136,7 +137,7 @@ export class PostgresAdapter extends Adapter {
public payloadThreshold: number;
public cleanupInterval: number;

private readonly pool: any;
private readonly pool: Pool;
private client: any;
private nodesMap: Map<string, number> = new Map<string, number>(); // uid => timestamp of last message
private heartbeatTimer: NodeJS.Timeout | undefined;
Expand All @@ -152,7 +153,7 @@ export class PostgresAdapter extends Adapter {
*
* @public
*/
constructor(nsp: any, pool: any, opts: Partial<PostgresAdapterOptions> = {}) {
constructor(nsp: any, pool: Pool, opts: Partial<PostgresAdapterOptions> = {}) {
super(nsp);
this.pool = pool;
this.uid = opts.uid || randomId();
Expand Down
Loading