Compare commits

...

1084 Commits
0.9.4 ... 4.5.1

Author SHA1 Message Date
Damien Arrachequesne
5ab8289c0a chore(release): 4.5.1
Diff: https://github.com/socketio/socket.io/compare/4.5.0...4.5.1
2022-05-17 23:38:07 +02:00
Damien Arrachequesne
30430f0985 fix: forward the local flag to the adapter when using fetchSockets()
Related:

- https://github.com/socketio/socket.io/issues/4359
- https://github.com/socketio/socket.io-redis-adapter/issues/454
2022-05-03 15:41:24 +02:00
h110m
9b43c9167c fix(typings): add HTTPS server to accepted types (#4351) 2022-05-03 08:15:22 +02:00
Damien Arrachequesne
8ecfcba5c1 chore(release): 4.5.0
Diff: https://github.com/socketio/socket.io/compare/4.4.1...4.5.0
2022-04-24 00:45:57 +02:00
Damien Arrachequesne
572133a58d docs(examples): update example with webpack 2022-04-22 23:10:01 +02:00
Damien Arrachequesne
6e1bb62982 chore: bump engine.io to version 6.2.0
Release notes: https://github.com/socketio/engine.io/releases/tag/6.2.0
Diff: https://github.com/socketio/engine.io/compare/6.1.3...6.2.0
2022-04-22 22:43:31 +02:00
Damien Arrachequesne
06e6838b18 docs(examples): add server bundling example with rollup
Related: https://github.com/socketio/socket.io/issues/4329
2022-04-22 22:40:15 +02:00
WD
1f03a44d1f docs(examples): update create-react-app example (#4347) 2022-04-20 22:47:34 +02:00
Damien Arrachequesne
be3d7f0f1f docs(examples): add TODO example with Postgres and Node.js cluster 2022-04-07 12:35:00 +02:00
Damien Arrachequesne
d12aab2d69 docs(examples): add example with express-session
Related: https://github.com/socketio/socket.io/issues/3933
2022-04-02 11:08:26 +02:00
Damien Arrachequesne
9f758689f6 docs(examples): pin the version of karma-jasmine-html-reporter
Related:

- https://github.com/socketio/socket.io/issues/4325
- https://github.com/dfederm/karma-jasmine-html-reporter/issues/54
2022-04-01 14:42:34 +02:00
Damien Arrachequesne
0b35dc77c0 refactor: make the protocol implementation stricter
This commit handles several edge cases that were silently ignored
before:

- receiving several CONNECT packets during a session
- receiving any packet without CONNECT packet first
2022-03-31 12:24:31 +02:00
Damien Arrachequesne
531104d332 feat: add support for catch-all listeners for outgoing packets
This is similar to `onAny()`, but for outgoing packets.

Syntax:

```js
socket.onAnyOutgoing((event, ...args) => {
  console.log(event);
});
```
2022-03-31 10:35:09 +02:00
Damien Arrachequesne
8b204570a9 feat: broadcast and expect multiple acks
Syntax:

```js
io.timeout(1000).emit("some-event", (err, responses) => {
  // ...
});
```

The adapter exposes two additional methods:

- `broadcastWithAck(packets, opts, clientCountCallback, ack)`

Similar to `broadcast(packets, opts)`, but:

* `clientCountCallback()` is called with the number of clients that
  received the packet (can be called several times in a cluster)
* `ack()` is called for each client response

- `serverCount()`

It returns the number of Socket.IO servers in the cluster (1 for the
in-memory adapter).

Those two methods will be implemented in the other adapters (Redis,
Postgres, MongoDB, ...).

Related:

- https://github.com/socketio/socket.io/issues/1811
- https://github.com/socketio/socket.io/issues/4163
- https://github.com/socketio/socket.io-redis-adapter/issues/445
2022-03-31 07:49:09 +02:00
Damien Arrachequesne
0b7d70ca42 chore: bump lockfile to v2 2022-03-30 08:15:41 +02:00
Szegedi Ádám
2f96438952 chore: bump engine.io version to fix CVE-2022-21676 (#4262)
Related: https://github.com/socketio/engine.io/security/advisories/GHSA-273r-mgr4-v34f
2022-01-25 22:18:18 +01:00
Chris Swithinbank
02c87a8561 fix(typings): ensure compatibility with TypeScript 3.x (#4259)
Labeled tuple elements were added in TypeScript 4.0.

Reference: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#labeled-tuple-elements

Related: 44e20ba5bf
2022-01-25 01:25:05 +01:00
Damien Arrachequesne
37b6d8fff0 chore: update default label for bug reports 2022-01-10 08:55:56 +01:00
Damien Arrachequesne
af54565b2d docs: remove broken badges
Related: https://github.com/socketio/socket.io/issues/4242
2022-01-10 08:03:53 +01:00
Damien Arrachequesne
aa5312a4b6 chore: revert to lockfile v1
Updating to v2 fails in the CI on Node.js 12 & 14 with the following
error:

> npm ERR! Error while executing:
> npm ERR! /usr/bin/git ls-remote -h -t ssh://git@github.com/uNetworking/uWebSockets.js.git
> npm ERR!
> npm ERR! Warning: Permanently added the RSA host key for IP address '140.82.113.3' to the list of known hosts.
> npm ERR! git@github.com: Permission denied (publickey).
> npm ERR! fatal: Could not read from remote repository.
> npm ERR!
> npm ERR! Please make sure you have the correct access rights
> npm ERR! and the repository exists.
> npm ERR!
> npm ERR! exited with error code: 128

So we will revert the change for now.
2022-01-06 08:01:00 +01:00
Damien Arrachequesne
c82a4bdf1f chore(release): 4.4.1
Diff: https://github.com/socketio/socket.io/compare/4.4.0...4.4.1
2022-01-06 07:32:03 +01:00
Orkhan Alikhanov
770ee5949f fix(types): make RemoteSocket.data type safe (#4234)
Related:

- https://github.com/socketio/socket.io/issues/4229
- fe8730ca0f
2022-01-06 07:14:55 +01:00
Damien Arrachequesne
3bf5d92735 refactor: add note about fetchSockets() for parent namespaces
Related: https://github.com/socketio/socket.io/issues/4235
2022-01-05 08:50:40 +01:00
Shayan Yousefi
fc82e44f73 refactor(typings): export Event type (#4215)
So that it can be used by the end users:

```ts
const myMiddleware = ([eventName, ...args]: Event, next: (err?: Error) => void) => {
  console.log(eventName); // inferred as string
  next();
}

io.on("connection", (socket) => {
  socket.use(myMiddleware);
});
```
2022-01-05 08:08:18 +01:00
Damien Arrachequesne
c840bad43a test: fix flaky tests 2022-01-05 08:00:55 +01:00
Orkhan Alikhanov
f2b8de7191 fix(typings): pass SocketData type to custom namespaces (#4233)
The `SocketData` type was only available on the main namespace.

Related: https://github.com/socketio/socket.io/issues/4229
See also: fe8730ca0f
2022-01-04 09:09:42 +01:00
Gray Zhang
51784d0305 chore: add types to exports field to be compatible with nodenext module resolution (#4228)
See [1] for detail, in `nodenext` module resolution it requires a
`types` field in `exports` with full filename including extension.

[1]: https://github.com/microsoft/TypeScript/issues/46770#issuecomment-966612103
2021-12-28 10:27:08 +01:00
Damien Arrachequesne
c196689545 docs: fix basic crud example
Related: https://github.com/socketio/socket.io/issues/4213
2021-12-16 23:00:20 +01:00
Mikhail Dudin
7a70f63499 docs: fix reconnection handling in the chat demo app (#4189) 2021-12-01 00:03:43 +01:00
anderslatif
e5897dd7dc docs: add usage with ES modules (#4195) 2021-12-01 00:02:13 +01:00
Damien Arrachequesne
2071a66c5a docs: simplify nginx cluster example
- remove useless Dockerfile
- clean format
- migrate to @socket.io/redis-adapter
2021-11-24 18:15:26 +01:00
Damien Arrachequesne
0f11c4745f chore(release): 4.4.0
Diff: https://github.com/socketio/socket.io/compare/4.3.2...4.4.0
2021-11-18 14:10:19 +01:00
Damien Arrachequesne
b839a3b400 fix: prevent double ack when emitting with a timeout
The ack was not properly removed upon timeout, and could be called
twice.

Related: f0ed42f18c
2021-11-18 14:03:07 +01:00
Damien Arrachequesne
f0ed42f18c feat: add timeout feature
Usage:

```js
socket.timeout(5000).emit("my-event", (err) => {
  if (err) {
    // the client did not acknowledge the event in the given delay
  }
});
```
2021-11-16 20:07:53 +01:00
Damien Arrachequesne
b7213e71e4 test: fix flaky test
`srv.close()` only closes the underlying HTTP server, but this does not
terminate the existing WebSocket connections.

Reference: https://nodejs.org/api/http.html#serverclosecallback
2021-11-16 15:58:55 +01:00
Damien Arrachequesne
2da82103d2 test: add test for volatile packet with binary
See also: 88eee5948a
2021-11-16 15:57:32 +01:00
Damien Arrachequesne
02b0f73e2c fix: only set 'connected' to true after middleware execution
The Socket instance is only considered connected when the "connection"
event is emitted, and not during the middleware(s) execution.

```js
io.use((socket, next) => {
  console.log(socket.connected); // prints "false"
  next();
});

io.on("connection", (socket) => {
  console.log(socket.connected); // prints "true"
});
```

Related: https://github.com/socketio/socket.io/issues/4129
2021-11-12 07:31:52 +01:00
Damien Arrachequesne
c0d8c5ab23 feat: add an implementation based on uWebSockets.js
Usage:

```js
const { App } = require("uWebSockets.js");
const { Server } = require("socket.io");

const app = new App();
const server = new Server();

server.attachApp(app);

app.listen(3000);
```

The Adapter prototype is updated so we can benefit from the publish
functionality of uWebSockets.js, so this will apply to all adapters
extending the default adapter.

Reference: https://github.com/uNetworking/uWebSockets.js

Related:

- https://github.com/socketio/socket.io/issues/3601
- https://github.com/socketio/engine.io/issues/578
2021-11-12 07:01:55 +01:00
Nikita Kolmogorov
fe8730ca0f feat: add type information to socket.data (#4159)
Usage:

```js
interface SocketData {
  name: string;
  age: number;
}

const io = new Server<ClientToServerEvents, ServerToClientEvents, InterServerEvents, SocketData>();

io.on("connection", (socket) => {
  socket.data.name = "john";
  socket.data.age = 42;
});
```
2021-11-08 15:21:48 +01:00
Damien Arrachequesne
ed8483da4d chore(release): 4.3.2
Diff: https://github.com/socketio/socket.io/compare/4.3.1...4.3.2
2021-11-08 06:39:20 +01:00
Sebastiaan Marynissen
9d86397243 fix: fix race condition in dynamic namespaces (#4137)
Using an async operation with `io.use()` could lead to the creation of
several instances of a same namespace, each of them overriding the
previous one.

Example:

```js
io.use(async (nsp, auth, next) => {
  await anOperationThatTakesSomeTime();
  next();
});
```

Related: https://github.com/socketio/socket.io/pull/4136
2021-10-24 07:46:29 +02:00
Naseem
44e20ba5bf refactor: add event type for use() (#4138) 2021-10-24 07:19:43 +02:00
Damien Arrachequesne
ccc5ec39a8 chore(release): 4.3.1
Diff: https://github.com/socketio/socket.io/compare/4.3.0...4.3.1
2021-10-17 00:02:16 +02:00
Josh Field
0ef2a4d02c fix: fix server attachment (#4127)
The check excluded an HTTPS server from being properly attached.

Related: https://github.com/socketio/socket.io/issues/4124
2021-10-16 23:58:55 +02:00
Damien Arrachequesne
95810aa62d chore(release): 4.3.0
Diff: https://github.com/socketio/socket.io/compare/4.2.0...4.3.0
2021-10-14 14:59:13 +02:00
Damien Arrachequesne
60edecb3bd feat: serve ESM bundle
Related:

- 0661564dc2
- https://github.com/socketio/socket.io-client/issues/1198
2021-10-13 18:17:12 +02:00
Damien Arrachequesne
eb5fdbd03e chore: bump engine.io to version 6.0.0
Release notes: https://github.com/socketio/engine.io/releases/tag/6.0.0
Diff: https://github.com/socketio/engine.io/compare/5.2.0...6.0.0
2021-10-12 00:05:10 +02:00
roh-kan
4974e9077c docs: update .NET client library link (#4115) 2021-10-08 14:18:03 +02:00
douira
033c5d399a fix(typings): add name field to cookie option (#4099)
Reference: 18a6eb89fb/lib/server.js (L355)
2021-09-20 09:13:38 +02:00
Damien Arrachequesne
7a74b66872 test: remove hardcoded ports
Related: https://github.com/socketio/socket.io/issues/3447
2021-09-09 08:57:11 +02:00
Damien Arrachequesne
dc81fcf461 fix: send volatile packets with binary attachments
The binary attachments of volatile packets were discarded (only the
header packet was sent) due to a bug introduced by [1].

Related: https://github.com/socketio/socket.io/issues/3919

[1]: dc381b72c6
2021-09-09 08:55:51 +02:00
Damien Arrachequesne
c100b7b61c chore(release): 4.2.0
Diff: https://github.com/socketio/socket.io/compare/4.1.3...4.2.0
2021-08-30 09:21:00 +02:00
Damien Arrachequesne
f03eeca39a chore: bump dependencies 2021-08-30 08:27:46 +02:00
Damien Arrachequesne
d8cc8aef7e docs: update the link of the Repl.it badge
The link will now point towards a sample project, instead of the root
repository.

Related: https://github.com/socketio/socket.io/issues/3934
2021-08-30 08:03:55 +02:00
Damien Arrachequesne
ccfd8caba6 fix(typings): allow async listener in typed events
So that:

```ts
socket.on("my-event", async () => {
  // ...
});
```

is valid under the @typescript-eslint/no-misused-promises rule.

Related: https://github.com/socketio/socket.io-client/issues/1486
2021-08-30 08:01:29 +02:00
Tim Düsterhus
24fee27ba3 feat: ignore the query string when serving client JavaScript (#4024)
Related: https://github.com/socketio/socket.io/issues/4023
2021-08-30 07:59:47 +02:00
brownman
310f8557a7 docs(examples): add missing module (#4018)
Fixes the following error:

> test/todo-management/todo.tests.ts:275:3 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.

Co-authored-by: brownman <brownman@users.noreply.github.com>
2021-07-15 21:48:20 +02:00
Damien Arrachequesne
dbd2a07cda chore(release): 4.1.3
Diff: https://github.com/socketio/socket.io/compare/4.1.2...4.1.3
2021-07-10 12:13:15 +02:00
Damien Arrachequesne
94e27cd072 fix: fix io.except() method
Previously, calling `io.except("theroom").emit(...)` did not exclude
the sockets in the given room.

This method was forgotten in [1].

[1]: ac9e8ca6c7
2021-07-10 11:48:46 +02:00
Damien Arrachequesne
a4dffc6527 fix: remove x-sourcemap header
This header is useless, as the client bundle already contains a
sourceMappingURL field.

Besides, Firefox prints the following warning:

> <url> is being assigned a //# sourceMappingURL, but already has one

Related: https://github.com/socketio/socket.io/issues/3958
2021-07-04 00:51:41 +02:00
Damien Arrachequesne
7c44893d78 chore: bump dependencies 2021-07-04 00:37:35 +02:00
Daniele TDC
b833f918c8 ci: update to node 16 (#3990)
See also: https://github.com/nodejs/Release#release-schedule
2021-06-28 09:09:44 +02:00
Daniele TDC
24d8d1f67f ci: update setup-node step (#3986) 2021-06-24 14:53:46 +02:00
Damien Arrachequesne
6f2a50b932 docs(examples): update example to webpack 5 2021-06-15 22:35:06 +02:00
Damien Arrachequesne
1633150b2b chore(release): 4.1.2
Diff: https://github.com/socketio/socket.io/compare/4.1.1...4.1.2
2021-05-17 23:17:31 +02:00
Damien Arrachequesne
0cb6ac95b4 fix(typings): ensure compatibility with TypeScript 3.x
Labeled tuple elements were added in TypeScript 4.0.

Reference: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#labeled-tuple-elements

Related: https://github.com/socketio/socket.io/issues/3916
2021-05-17 23:15:22 +02:00
Damien Arrachequesne
a2cf2486c3 fix: ensure compatibility with previous versions of the adapter
Using `socket.io@4.1.0` with `socket.io-adapter@2.2.0` would lead to
the following error:

> Uncaught Error: unknown packet type NaN

Because the packet would be encoded twice, resulting in "undefined".

See also:

- 5579d40c24
- dc381b72c6

Related:

- https://github.com/socketio/socket.io/issues/3922
- https://github.com/socketio/socket.io/issues/3927
2021-05-17 23:14:36 +02:00
Damien Arrachequesne
995f38f4cc chore(release): 4.1.1
Diff: https://github.com/socketio/socket.io/compare/4.1.0...4.1.1
2021-05-12 00:04:52 +02:00
Damien Arrachequesne
891b1870e9 fix(typings): properly type the adapter attribute
Related: https://github.com/socketio/socket.io/issues/3796
2021-05-11 23:59:44 +02:00
Damien Arrachequesne
b84ed1e41c fix(typings): properly type server-side events
See also: 93cce05fb3
2021-05-11 23:59:18 +02:00
Damien Arrachequesne
fb6b0efec9 chore(release): 4.1.0
Diff: https://github.com/socketio/socket.io/compare/4.0.2...4.1.0
2021-05-11 09:27:52 +02:00
Damien Arrachequesne
95d9e4a42f test: fix randomly failing test 2021-05-11 00:06:03 +02:00
Damien Arrachequesne
499c89250d feat: notify upon namespace creation
A "new_namespace" event will be emitted when a new namespace is created:

```js
io.on("new_namespace", (namespace) => {
  // ...
});
```

This could be used for example for registering the same middleware for
each namespace.

See https://github.com/socketio/socket.io/issues/3851
2021-05-11 00:09:18 +02:00
Damien Arrachequesne
93cce05fb3 feat: add support for inter-server communication
Syntax:

```js
// server A
io.serverSideEmit("hello", "world");

// server B
io.on("hello", (arg) => {
  console.log(arg); // prints "world"
});
```

With acknowledgements:

```js
// server A
io.serverSideEmit("hello", "world", (err, responses) => {
  console.log(responses); // prints ["hi"]
});

// server B
io.on("hello", (arg, callback) => {
  callback("hi");
});
```

This feature replaces the customHook/customRequest API from the Redis
adapter: https://github.com/socketio/socket.io-redis/issues/370
2021-05-11 00:07:20 +02:00
Damien Arrachequesne
dc381b72c6 perf: add support for the "wsPreEncoded" writing option
Packets that are sent to multiple clients will now be pre-encoded for
the WebSocket transport (which means simply prepending "4" - which is
the "message" packet type in Engine.IO).

Note: buffers are not pre-encoded, since they are sent without
modification over the WebSocket connection

See also: 7706b123df

engine.io diff: https://github.com/socketio/engine.io/compare/5.0.0...5.1.0
2021-05-11 00:06:03 +02:00
Damien Arrachequesne
9fff03487c chore(release): 4.0.2
Diff: https://github.com/socketio/socket.io/compare/4.0.1...4.0.2
2021-05-06 14:38:26 +02:00
Damien Arrachequesne
b81ce4c9d0 fix(typings): make "engine" attribute public 2021-05-06 14:36:25 +02:00
Damien Arrachequesne
d65b6ee84c fix: properly export the Socket class
Before this change, `require("socket.io").Socket` would return
"undefined".

Note: having access to the Socket class allows users to modify its
prototype.

Related: https://github.com/socketio/socket.io/issues/3726
2021-05-06 14:36:12 +02:00
Damien Arrachequesne
3665aada47 docs(examples): basic CRUD application
See also: https://socket.io/get-started/basic-crud-application/
2021-04-23 00:08:18 +02:00
Damien Arrachequesne
1faa7e3aea chore(release): 4.0.1
Diff: https://github.com/socketio/socket.io/compare/4.0.0...4.0.1
2021-04-01 01:25:56 +02:00
Maxime Kjaer
a11152f42b fix(typings): add fallback to untyped event listener (#3834)
Related: https://github.com/socketio/socket.io/issues/3833
2021-03-31 11:37:37 +02:00
Maxime Kjaer
259f29720b docs(examples): remove unnecessary type annotations (#3855)
Typed events in Socket.IO 4.0 remove the need for writing type
annotations in callbacks of reserved events.
2021-03-24 23:12:22 +01:00
Damien Arrachequesne
b4ae8d2e19 docs(examples): update all examples to Socket.IO v4 2021-03-18 15:07:04 +01:00
Adán Toscano
64be1c9985 docs(examples): fix chat example (#3787) 2021-03-18 14:06:13 +01:00
Solomon English
1a72ae4fe2 fix(typings): update return type from emit (#3843)
```
(channel ? io.to(channel) : io).emit("stuff", message);
```

would no longer compile.

Related: https://github.com/socketio/socket.io/issues/3844
2021-03-18 11:36:34 +01:00
Damien Arrachequesne
5eaeffc8e2 chore(release): 4.0.0
Diff: https://github.com/socketio/socket.io/compare/3.1.2...4.0.0
2021-03-10 12:43:53 +01:00
Damien Arrachequesne
1b6d6de4ed chore: include Engine.IO v5
Release notes: https://github.com/socketio/engine.io/releases/tag/5.0.0
2021-03-10 11:14:33 +01:00
Maxime Kjaer
0107510ba8 feat: add support for typed events (#3822)
Syntax:

```ts
interface ClientToServerEvents {
  "my-event": (a: number, b: string, c: number[]) => void;
}

interface ServerToClientEvents {
  hello: (message: string) => void;
}

const io = new Server<ClientToServerEvents, ServerToClientEvents>(httpServer);

io.emit("hello", "world");

io.on("connection", (socket) => {
  socket.on("my-event", (a, b, c) => {
    // ...
  });

  socket.emit("hello", "again");
});
```

The events are not typed by default (inferred as any), so this change
is backward compatible.

Note: we could also have reused the method here ([1]) to add types to
the EventEmitter, instead of creating a StrictEventEmitter class.

Related: https://github.com/socketio/socket.io/issues/3742

[1]: https://github.com/binier/tiny-typed-emitter
2021-03-10 00:18:13 +01:00
Damien Arrachequesne
b25495c069 feat: add some utility methods
This commit adds the following methods:

- fetchSockets: returns the matching socket instances

Syntax:

```js
// return all Socket instances
const sockets = await io.fetchSockets();

// return all Socket instances of the "admin" namespace in the "room1" room
const sockets = await io.of("/admin").in("room1").fetchSockets();
```

- socketsJoin: makes the matching socket instances join the specified rooms

Syntax:

```js
// make all Socket instances join the "room1" room
io.socketsJoin("room1");

// make all Socket instances of the "admin" namespace in the "room1" room join the "room2" room
io.of("/admin").in("room1").socketsJoin("room2");
```

- socketsLeave: makes the matching socket instances leave the specified rooms

Syntax:

```js
// make all Socket instances leave the "room1" room
io.socketsLeave("room1");

// make all Socket instances of the "admin" namespace in the "room1" room leave the "room2" room
io.of("/admin").in("room1").socketsLeave("room2");
```

- disconnectSockets: makes the matching socket instances disconnect

Syntax:

```js
// make all Socket instances disconnect
io.disconnectSockets();

// make all Socket instances of the "admin" namespace in the "room1" room disconnect
io.of("/admin").in("room1").disconnectSockets();
```

Those methods share the same semantics as broadcasting. They will also
work with multiple Socket.IO servers when using the Redis adapter. In
that case, the fetchSockets() method will return a list of RemoteSocket
instances, which expose a subset of the methods and attributes of the
Socket class (the "request" attribute cannot be mocked, for example).

Related:

- https://github.com/socketio/socket.io/issues/3042
- https://github.com/socketio/socket.io/issues/3418
- https://github.com/socketio/socket.io/issues/3570
- https://github.com/socketio/socket.io-redis/issues/283
2021-03-02 11:17:21 +01:00
Damien Arrachequesne
085d1de9df feat: allow to pass an array to io.to(...)
In some cases it is necessary to pass an array of rooms instead of a single room.

New syntax:

```
io.to(["room1", "room2"]).except(["room3"]).emit(...);

socket.to(["room1", "room2"]).except(["room3"]).emit(...);
```

Related: https://github.com/socketio/socket.io/issues/3048
2021-03-01 23:20:46 +01:00
Damien Arrachequesne
ac9e8ca6c7 fix: make io.to(...) immutable
Previously, broadcasting to a given room (by calling `io.to()`) would
mutate the io instance, which could lead to surprising behaviors, like:

```js
io.to("room1");
io.to("room2").emit(...); // also sent to room1

// or with async/await
io.to("room3").emit("details", await fetchDetails()); // random behavior: maybe in room3, maybe to all clients
```

Calling `io.to()` (or any other broadcast modifier) will now return an
immutable instance.

Related:

- https://github.com/socketio/socket.io/issues/3431
- https://github.com/socketio/socket.io/issues/3444
2021-03-01 23:17:08 +01:00
Sebastiaan Marynissen
7de2e87e88 feat: allow to exclude specific rooms when broadcasting (#3789)
New syntax:

```
io.except("room1").emit(...);
io.to("room1").except("room2").emit(...);

socket.broadcast.except("room1").emit(...);
socket.to("room1").except("room2").emit(...);
```

Related:

- https://github.com/socketio/socket.io/issues/3629
- https://github.com/socketio/socket.io/issues/3657
2021-03-01 09:30:58 +01:00
Damien Arrachequesne
225ade062a chore(release): 3.1.2
Diff: https://github.com/socketio/socket.io/compare/3.1.1...3.1.2
2021-02-26 01:18:42 +01:00
Damien Arrachequesne
494c64e44f fix: ignore packet received after disconnection
Related: https://github.com/socketio/socket.io/issues/3095
2021-02-26 00:58:30 +01:00
Damien Arrachequesne
67a61e39e6 chore: loosen the version requirement of @types/node
Related: https://github.com/socketio/socket.io/issues/3793
2021-02-26 00:58:01 +01:00
Damien Arrachequesne
7467216e02 docs(examples): 4th and final part of the "private messaging" example
See also: https://socket.io/get-started/private-messaging-part-4/
2021-02-17 00:24:23 +01:00
Damien Arrachequesne
7247b4051f docs(examples): 3rd part of the "private messaging" example
See also: https://socket.io/get-started/private-messaging-part-3/
2021-02-17 00:22:55 +01:00
Damien Arrachequesne
992c9380c3 docs(examples): 2nd part of the "private messaging" example
See also: https://socket.io/get-started/private-messaging-part-2/
2021-02-15 01:09:12 +01:00
Damien Arrachequesne
8b404f424b docs(examples): 1st part of the "private messaging" example 2021-02-10 00:33:39 +01:00
Damien Arrachequesne
12221f296d chore(release): 3.1.1
Diff: https://github.com/socketio/socket.io/compare/3.1.0...3.1.1
2021-02-03 22:57:21 +01:00
Damien Arrachequesne
6f4bd7f8e7 fix: properly parse the CONNECT packet in v2 compatibility mode
In Socket.IO v2, the Socket query option was appended to the namespace
in the CONNECT packet:

{
  type: 0,
  nsp: "/my-namespace?abc=123"
}

Note: the "query" option on the client-side (v2) will be found in the
"auth" attribute on the server-side:

```
// client-side
const socket = io("/nsp1", {
  query: {
    abc: 123
  }
});
socket.query = { abc: 456 };

// server-side
const io = require("socket.io")(httpServer, {
  allowEIO3: true // enable compatibility mode
});

io.of("/nsp1").on("connection", (socket) => {
  console.log(socket.handshake.auth); // { abc: 456 } (the Socket query)
  console.log(socket.handshake.query.abc); // 123 (the Manager query)
});

More information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/#Add-a-clear-distinction-between-the-Manager-query-option-and-the-Socket-query-option

Related: https://github.com/socketio/socket.io/issues/3791
2021-02-03 22:54:07 +01:00
Damien Arrachequesne
4f2e9a716d fix(typings): update the types of "query", "auth" and "headers"
Related: https://github.com/socketio/socket.io/issues/3770
2021-02-03 22:53:38 +01:00
david-fong
9e8f288ca9 fix(typings): add return types and general-case overload signatures (#3776)
See also: https://stackoverflow.com/questions/52760509/typescript-returntype-of-overloaded-function/52760599#52760599
2021-02-02 11:50:08 +01:00
Damien Arrachequesne
86eb4227b2 docs(examples): add example with traefik
Reference: https://doc.traefik.io/traefik/v2.0/
2021-01-31 23:47:23 +01:00
Damien Arrachequesne
cf873fd831 docs(examples): update cluster examples to Socket.IO v3 2021-01-28 11:21:38 +01:00
Damien Arrachequesne
0d10e6131b docs(examples): update the nginx cluster example
Related: https://github.com/socketio/socket.io/discussions/3778

Reference: http://nginx.org/en/docs/http/ngx_http_upstream_module.html#hash
2021-01-28 10:52:26 +01:00
JPSO
10aafbbc16 ci: add Node.js 15 (#3765) 2021-01-20 22:34:51 +01:00
Hamdi Bayhan
f34cfca26d docs: fix broken link (#3759) 2021-01-17 22:10:37 +01:00
PrashoonB
d412e876b8 docs: add installation with yarn (#3757) 2021-01-15 22:20:04 +01:00
Damien Arrachequesne
f05a4a6f82 chore(release): 3.1.0
Diff: https://github.com/socketio/socket.io/compare/3.0.5...3.1.0
2021-01-15 02:21:54 +01:00
Damien Arrachequesne
2c883f5d4e chore: bump socket.io-adapter version
Diff: https://github.com/socketio/socket.io-adapter/compare/2.0.3...2.1.0

Includes:

- add room events ([155fa63](155fa6333a))
- make rooms and sids public ([313c5a9](313c5a9fb6))
2021-01-15 01:41:37 +01:00
Jakob Ackermann
161091dd4c feat: confirm a weak but matching ETag (#3485)
When handling compression at the proxy server level, the client receives a weak ETag.
Weak ETags are prefixed with `W/`, e.g. `W/"2.2.0"`.
Upon cache validation we should take care of these too.

Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
2021-01-15 01:04:55 +01:00
汪心禾 Wang, Xinhe
d52532b7be docs: add other client implementations (#3593)
Reference: https://socket.io/docs/#Other-client-implementations
2021-01-15 00:37:40 +01:00
Sergio Lenza
6b1d7901db docs(examples): Improve the chat example with more ES6 features (#3240) 2021-01-15 00:36:17 +01:00
EloniX-X
b55892ae80 docs: add run on repl.it badge to README (#3617) 2021-01-15 00:30:17 +01:00
Pablo Tejada
233650c222 feat(esm): export the Namespace and Socket class (#3699) 2021-01-15 00:28:20 +01:00
Damien Arrachequesne
9925746c8e feat: add support for Socket.IO v2 clients
In order to ease the migration to Socket.IO v3, the Socket.IO server
can now communicate with v2 clients.

```js
const io = require("socket.io")({
  allowEIO3: true
});
```

This feature is disabled by default.
2021-01-14 23:38:24 +01:00
Rohan Chougule
de8dffd252 refactor: strict type check in if expressions (#3744) 2021-01-08 14:58:37 +01:00
Damien Arrachequesne
f8a66fd11a chore(release): 3.0.5
Diff: https://github.com/socketio/socket.io/compare/3.0.4...3.0.5
2021-01-05 12:08:15 +01:00
Damien Arrachequesne
752dfe3b1e chore: bump debug version 2021-01-05 11:53:27 +01:00
Damien Arrachequesne
bf54327421 revert: restore the socket middleware functionality
This functionality was removed in [1] (included in 3.0.0), but
catch-all listeners and socket middleware features are complementary
rather than mutually exclusive.

The only difference with the previous implementation is that passing an
error to the `next` handler will create an error on the server-side,
and not on the client-side anymore.

```js
io.on("connection", (socket) => {

  socket.use(([ event, ...args ], next) => {
    next(new Error("stop"));
  });

  socket.on("error", (err) => {
    // to restore the previous behavior
    socket.emit("error", err);

    // or close the connection, depending on your use case
    socket.disconnect(true);
  });
});
```

This creates additional possibilities about custom error handlers, which
may be implemented in the future.

```js
// user-defined error handler
socket.use((err, [ event ], next) => {
  // either handle it
  socket.disconnect();

  // or forward the error to the default error handler
  next(err);
});

// default error handler
socket.use((err, _, next) => {
  socket.emit("error", err);
});
```

Related: https://github.com/socketio/socket.io/issues/3678

[1]: 5c73733985
2021-01-05 11:51:50 +01:00
Damien Arrachequesne
170b739f14 fix: properly clear timeout on connection failure
Related: https://github.com/socketio/socket.io/issues/3720
2021-01-05 11:51:08 +01:00
Stijn de Witt
230cd19164 chore: bump dependencies 2021-01-04 10:28:17 +01:00
Damien Arrachequesne
a0a3481c64 test: fix random test failure 2021-01-04 10:27:57 +01:00
Damien Arrachequesne
f773b4889c chore: update GitHub issue templates 2020-12-30 11:34:30 +01:00
Damien Arrachequesne
292d62ea69 docs(examples): update TypeScript example
Includes b3de861a92
2020-12-30 09:45:22 +01:00
Damien Arrachequesne
178e899f48 docs(examples): add Angular TodoMVC + Socket.IO example 2020-12-17 12:42:23 +01:00
David Fong
d1bfe40dbb refactor: add more typing info and upgrade prettier (#3725)
This upgrades prettier to 2.2.0 to gain support for TypeScript's new
type-only-imports feature.
2020-12-11 12:19:20 +01:00
Damien Arrachequesne
81c1f4e819 chore(release): 3.0.4
Diff: https://github.com/socketio/socket.io/compare/3.0.3...3.0.4
2020-12-07 12:01:24 +01:00
Damien Arrachequesne
1fba399b17 ci: migrate to GitHub Actions
Due to the recent changes to the Travis CI platform (see [1]), we will
now use GitHub Actions to run the tests.

Reference: https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-nodejs

[1]: https://blog.travis-ci.com/2020-11-02-travis-ci-new-billing
2020-12-07 11:37:03 +01:00
Stijn de Witt
4e6d40493d chore: make tests work on Windows (#3708) 2020-11-28 01:55:19 +01:00
Pablo Tejada
28c7cc0856 style(issue-template): fix typo (#3700)
[skip ci]
2020-11-25 11:09:17 +01:00
Damien Arrachequesne
06a2bd313a chore(release): 3.0.3
Diff: https://github.com/socketio/socket.io/compare/3.0.2...3.0.3
2020-11-19 01:31:31 +01:00
Damien Arrachequesne
85ebd356e9 chore: cleanup dist folder before compilation 2020-11-19 01:28:27 +01:00
Damien Arrachequesne
9b6f9711da chore(release): 3.0.2
Diff: https://github.com/socketio/socket.io/compare/3.0.1...3.0.2
2020-11-18 00:53:51 +01:00
Damien Arrachequesne
43705d7a91 fix: merge Engine.IO options
So that the following example:

```js
const io = require('socket.io')({
  pingTimeout: 10000
});

io.listen(3000);
```

behaves the same as:

```js
const io = require('socket.io')(3000, {
  pingTimeout: 10000
});
```

Before this change, the options in the first example were not forwarded
to the Engine.IO constructor, which is not really intuitive.

The previous syntax (which is still valid):

```js
const io = require('socket.io')();

io.listen(3000, {
  pingTimeout: 10000
});
```
2020-11-17 23:33:18 +01:00
Damien Arrachequesne
118cc686a1 chore: add 3rd party types in the list of dependencies
Those types are mandatory for TypeScript users.

Related:

- https://github.com/socketio/socket.io/issues/3690
- https://github.com/microsoft/types-publisher/issues/81#issuecomment-234051345
2020-11-17 11:55:41 +01:00
Damien Arrachequesne
c596e54343 docs(examples): update React Native example
This includes `engine.io-client@4.0.3`, which fixes two issues with
React Native.

See also:

- 177b95fe46
- ccb99e3718

[skip ci]
2020-11-17 09:44:05 +01:00
Damien Arrachequesne
f7e0009120 docs(examples): update TypeScript example
In order to test 50671d984a

[skip ci]
2020-11-09 10:47:50 +01:00
Damien Arrachequesne
e69d0ad602 chore: bump socket.io-client version 2020-11-09 10:32:10 +01:00
Damien Arrachequesne
0317a077be chore(release): 3.0.1
Diff: https://github.com/socketio/socket.io/compare/3.0.0...3.0.1
2020-11-09 10:27:58 +01:00
Damien Arrachequesne
d00c0c0d9d docs(examples): update examples to Socket.IO v3
Other examples need some additional work (Redis adapter migration, ...).
2020-11-09 10:19:40 +01:00
Avi Vahl
f62f180eda fix: export ServerOptions and Namespace types (#3684)
@types/socket.io used to export these.
2020-11-09 08:58:14 +01:00
Damien Arrachequesne
50671d984a fix(typings): update the signature of the emit method
The previous signature was not compatible with EventEmitter.emit(). The typescript compilation threw:

```
node_modules/socket.io/dist/namespace.d.ts(89,5): error TS2416: Property 'emit' in type 'Namespace' is not assignable to the same property in base type 'EventEmitter'.
  Type '(ev: string, ...args: any[]) => Namespace' is not assignable to type '(event: string | symbol, ...args: any[]) => boolean'.
    Type 'Namespace' is not assignable to type 'boolean'.
node_modules/socket.io/dist/socket.d.ts(84,5): error TS2416: Property 'emit' in type 'Socket' is not assignable to the same property in base type 'EventEmitter'.
  Type '(ev: string, ...args: any[]) => this' is not assignable to type '(event: string | symbol, ...args: any[]) => boolean'.
    Type 'this' is not assignable to type 'boolean'.
      Type 'Socket' is not assignable to type 'boolean'.
```

Note: the emit calls cannot be chained anymore:

```js
socket.emit("hello").emit("world"); // will not work anymore
```
2020-11-08 00:07:56 +01:00
Damien Arrachequesne
8a69f15437 chore: restore package-lock.json file 2020-11-05 22:25:35 +01:00
Damien Arrachequesne
1af3267e3f chore(release): 3.0.0
Diff: https://github.com/socketio/socket.io/compare/2.3.0...3.0.0
2020-11-05 22:07:47 +01:00
Damien Arrachequesne
02951c4391 chore(release): 3.0.0-rc4
Diff: https://github.com/socketio/socket.io/compare/3.0.0-rc3...3.0.0-rc4
2020-10-30 23:02:43 +01:00
Damien Arrachequesne
54bf4a44e9 feat: emit an Error object upon middleware error
This commit restores the ability to send additional data in the
middleware functions, which was removed during the rewrite to
Typescript ([1]).

The only difference with the previous implementation is that the client
will now emit a "connect_error" (previously, "error") event with an
actual Error object, with both the message and an optional "data"
attribute.

```js
// server-side
io.use((socket, next) => {
  const err = new Error("not authorized");
  err.data = { content: "Please retry later" };
  next(err);
});

// client-side
socket.on("connect_error", err => {
  console.log(err.message); // not authorized
  console.log(err.data.content); // Please retry later
});
```

[1]: a5581a9789
2020-10-30 22:52:08 +01:00
Damien Arrachequesne
aa7574f884 feat: serve msgpack bundle
See 71d60480af
2020-10-27 23:17:12 +01:00
Damien Arrachequesne
64056d6616 docs(examples): update TypeScript example 2020-10-27 22:18:07 +01:00
Damien Arrachequesne
cacad7029a chore(release): 3.0.0-rc3
Diff: https://github.com/socketio/socket.io/compare/3.0.0-rc2...3.0.0-rc3
2020-10-27 00:44:30 +01:00
Damien Arrachequesne
d16c035d25 refactor: rename ERROR to CONNECT_ERROR
The meaning is not modified: this packet type is still used by the
server when the connection to a namespace is refused.
2020-10-26 00:29:11 +01:00
Damien Arrachequesne
5c73733985 feat: add support for catch-all listeners
Inspired from EventEmitter2 [1]

```js
io.on("connect", socket => {

  socket.onAny((event, ...args) => {});

  socket.prependAny((event, ...args) => {});

  socket.offAny(); // remove all listeners

  socket.offAny(listener);

  const listeners = socket.listenersAny();
});
```

Breaking change: the socket.use() method is removed

This method was introduced in [2] for the same feature (having a
catch-all listener), but there were two issues:

- the API is not very user-friendly, since the user has to know the structure of the packet argument
- it uses an ERROR packet, which is reserved for Namespace authentication issues (see [3])

[1]: https://github.com/EventEmitter2/EventEmitter2
[2]: https://github.com/socketio/socket.io/issues/434
[3]: https://github.com/socketio/socket.io-protocol
2020-10-25 23:44:01 +01:00
Damien Arrachequesne
129c6417bd feat: make Socket#join() and Socket#leave() synchronous
Depending on the adapter, Socket#join() may return:

- nothing (in-memory and Redis adapters)
- a promise (custom adapters)

Breaking change: Socket#join() and Socket#leave() do not accept a
callback argument anymore.

Before:

```js
socket.join("room1", () => {
 io.to("room1").emit("hello");
});
```

After:

```
socket.join("room1");
io.to("room1").emit("hello");
// or await socket.join("room1"); for custom adapters
```

Note: the need for an asynchronous method came from the Redis adapter,
which did override the Adapter#add() method in earlier versions, but
this is not the case anymore.

Reference:

- https://github.com/socketio/socket.io/blob/2.3.0/lib/socket.js#L236-L258
- https://github.com/socketio/socket.io-adapter/blob/1.1.2/index.js#L56-L65
- 05f926e13e

Related: https://github.com/socketio/socket.io/issues/3662
2020-10-22 01:50:13 +02:00
Damien Arrachequesne
0d74f290cd refactor(typings): export Socket class
In order to be able to cast it on the argument of the "connect" event:

```js
import { Socket } from "socket.io";

io.on("connect", (socket: Socket) => {
  // ...
});
```
2020-10-17 03:36:15 +02:00
Damien Arrachequesne
7603da71a5 feat: remove prod dependency to socket.io-client
The client bundles are included in the repository in order to remove
socket.io-client from the list of production dependencies and thus to
reduce the total number of dependencies when installing the server.

This means the release of the client and the server must now be in sync
(which is almost always the case actually).

The minified build is now served:

- /<path>/socket.io.js
- /<path>/socket.io.js.map
- /<path>/socket.io.min.js
- /<path>/socket.io.min.js.map

The content will now be compressed as well.
2020-10-17 02:11:15 +02:00
Damien Arrachequesne
a81b9f31cf docs(examples): add example with TypeScript
There are two issues with the typings:

- on the client-side, the Emitter class is not properly imported (hence the @ts-ignore)
- on the server-side, the Socket class is not exported (in order to cast it in the "connect" event)
2020-10-15 13:38:46 +02:00
Damien Arrachequesne
20ea6bd277 docs(examples): add example with ES modules 2020-10-15 13:26:55 +02:00
Damien Arrachequesne
0ce5b4ca68 chore(release): 3.0.0-rc2
Diff: https://github.com/socketio/socket.io/compare/3.0.0-rc1...3.0.0-rc2
2020-10-15 13:02:59 +02:00
Damien Arrachequesne
8a5db7fa36 refactor: remove duplicate _sockets map
Both the "connected" and the "_sockets" maps were used to track the
Socket instances in the namespace.

Let's merge them into "sockets". It's a breaking change, but:

- the "sockets" object did already exist in Socket.IO v2 (and appears in some examples/tutorials)
- "sockets" makes more sense than "connected" in my opinion
- there was already a breaking change regarding the "connected" property (from object to Map)

Breaking change: the "connected" map is renamed to "sockets"
2020-10-15 12:45:42 +02:00
Damien Arrachequesne
2a05042e2c refactor: add additional typings 2020-10-15 12:04:42 +02:00
Damien Arrachequesne
91cd255ba7 fix: close clients with no namespace
After a given timeout, a client that did not join any namespace will be
closed in order to prevent malicious clients from using the server
resources.

The timeout defaults to 45 seconds, in order not to interfere with the
Engine.IO heartbeat mechanism (30 seconds).
2020-10-15 11:54:06 +02:00
Damien Arrachequesne
58b66f8089 refactor: hide internal methods and properties
There is no concept of package-private methods in TypeScript, so we'll
just prefix them with "_" and mark them as private in the JSDoc.
2020-10-15 11:54:06 +02:00
Damien Arrachequesne
669592d120 feat: move binary detection back to the parser
See 285e7cd0d8

Breaking change: the Socket#binary() method is removed, as this use
case is now covered by the ability to provide your own parser.
2020-10-15 10:45:56 +02:00
Damien Arrachequesne
2d2a31e5c0 chore: publish the wrapper.mjs file 2020-10-14 01:53:37 +02:00
Damien Arrachequesne
ebb0575fa8 chore(release): 3.0.0-rc1
Diff: https://github.com/socketio/socket.io/compare/2.3.0...3.0.0-rc1
2020-10-13 23:36:21 +02:00
Damien Arrachequesne
c0d171f728 test: use the reconnect event of the Manager
Following 132f8ec918
2020-10-13 23:02:09 +02:00
Damien Arrachequesne
9c7a48d866 test: use the complete export name
Following fa7d41f55d

Ref: https://nodejs.org/dist/latest-v14.x/docs/api/packages.html#packages_subpath_exports
2020-10-13 23:02:09 +02:00
Damien Arrachequesne
4bd5b2339a feat: throw upon reserved event names
These events cannot be used by the end users, because they are part of
the Socket.IO public API, so using them will now throw an error
explicitly.
2020-10-13 23:02:09 +02:00
Damien Arrachequesne
a8c0600609 feat: remove the 'origins' option
The underlying Engine.IO server now supports a 'cors' option, which
will be forwarded to the cors module.

Breaking change: the 'origins' option is removed

Before:

```js
new Server(3000, {
  origins: ["https://example.com"]
});
```

The 'origins' option was used in the allowRequest method, in order to
determine whether the request should pass or not. And the Engine.IO
server would implicitly add the necessary Access-Control-Allow-xxx
headers.

After:

```js
new Server(3000, {
  cors: {
    origin: "https://example.com",
    methods: ["GET", "POST"],
    allowedHeaders: ["content-type"]
  }
});
```

The already existing 'allowRequest' option can be used for validation:

```js
new Server(3000, {
  allowRequest: (req, callback) => {
    callback(null, req.headers.referer.startsWith("https://example.com"));
  }
});
```
2020-10-13 23:02:08 +02:00
Damien Arrachequesne
8b6b100c28 feat: add ES6 module export
Both CommonJS and ES6 import are now supported:

- with `{ "type": "commonjs" }` in the package.json file

```js
const io = require("socket.io")(8080);
// or
const { Server } = require("socket.io");
const io = new Server(8080);
```

- with `{ "type": "module" }`

```js
import { Server } from "socket.io";

const io = new Server(8080);
```

Related: https://nodejs.org/api/packages.html#packages_dual_commonjs_es_module_packages
2020-10-13 23:02:08 +02:00
Damien Arrachequesne
83a2356648 refactor: properly delegate to the main namespace 2020-10-13 23:02:08 +02:00
Damien Arrachequesne
2875d2cfdf feat: do not reuse the Engine.IO id
In previous versions, the Socket#id attribute was equal (or derived,
for a non-default namespace) to the underlying Engine.IO id, which is
used as a mean to authenticate the user throughout the Engine.IO
session and thus is sensitive information that should be kept secret.

The problem with reusing the Engine.IO id is that users could be
tempted to transmit this id to other clients, in order to implement
private messaging for example.

So we'll now generate a new random id for each new socket.

Please note that this id will now be different from the one found in
the query parameters of the HTTP requests.
2020-10-13 23:02:07 +02:00
Damien Arrachequesne
3289f7ec37 feat: remove the implicit connection to the default namespace
In previous versions, a client was always connected to the default
namespace, even if it requested access to another namespace.

This meant that the middlewares registered for the default namespace
were triggered in any case, which is a surprising behavior for end
users.

This also meant that the query option of the Socket on the client-side
was not sent in the Socket.IO CONNECT packet for the default namespace:

```js
// default namespace: query sent in the query params
const socket = io({
  query: {
    abc: "def"
  }
});

// another namespace: query sent in the query params + the CONNECT packet
const socket = io("/admin", {
  query: {
    abc: "def"
  }
});
```

The client will now send a CONNECT packet in any case, and the query
option of the Socket is renamed to "auth", in order to make a clear
distinction with the query option of the Manager (included in the query
parameters of the HTTP requests).

```js
// server-side
io.use((socket, next) => {
  // not triggered anymore
});

io.of("/admin").use((socket, next => {
  // triggered
  console.log(socket.handshake.query.abc); // "def"
  console.log(socket.handshake.auth.abc); // "123"
});

// client-side
const socket = io("/admin", {
  query: {
    abc: "def"
  },
  auth: {
    abc: "123"
  }
});
```
2020-10-13 23:02:07 +02:00
Damien Arrachequesne
7a51c76413 refactor: migrate tests to TypeScript 2020-10-13 23:02:06 +02:00
Damien Arrachequesne
64bd9fb01a chore: include Engine.IO v4
Release notes: https://github.com/socketio/engine.io/releases/tag/4.0.0
2020-10-13 23:02:06 +02:00
Damien Arrachequesne
4396bd0b3d chore: point towards the develop branch of the client
The package-lock.json file is temporarily removed in order to include
the latest commits to the client and make the tests pass.
2020-10-13 23:02:06 +02:00
Alessandro Magionami
bb43ff2988 docs: add example with fastify (#3654)
See https://github.com/alemagio/fastify-socket.io
2020-10-04 23:20:05 +02:00
Damien Arrachequesne
0540c36510 refactor(typings): add server options
Greatly inspired from:

- https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/engine.io
- https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/socket.io
2020-09-29 02:04:27 +02:00
Damien Arrachequesne
1108ede120 chore: bump socket.io-parser
Breaking change:

- the encode() method is now synchronous

Please note that the exchange [protocol][1] is left untouched and thus
stays in version 4.

Diff: https://github.com/socketio/socket.io-parser/compare/3.4.1...4.0.0

[1] https://github.com/socketio/socket.io-protocol
2020-09-28 16:07:09 +02:00
Damien Arrachequesne
029f478992 feat: remove Server#set() method
This method was kept for backward-compatibility with pre-1.0 versions.
2020-09-26 01:47:17 +02:00
Damien Arrachequesne
424a473c22 refactor: use ES6 Maps instead of plain objects
These attributes were not part of the public API, so there's no
breaking change.
2020-09-26 01:21:51 +02:00
Damien Arrachequesne
1507b416d5 feat: remove Socket#rooms object
The value stored in the adapter will now be used, instead of
duplicating it in the Socket class.

Breaking change: Socket#rooms is now a Set instead of an object

Closes https://github.com/socketio/socket.io/issues/2890
2020-09-26 00:48:55 +02:00
Damien Arrachequesne
84437dc2a6 chore: bump socket.io-adapter
Breaking changes:

- Namespace#connected is now a Map instead of an object.

- Namespace#clients() is renamed to Namespace#allSockets() and now
returns a Promise

Diff: https://github.com/socketio/socket.io-adapter/compare/1.1.2...2.0.0
2020-09-26 00:24:54 +02:00
Damien Arrachequesne
2464de7d2b refactor: use prettier to format tests 2020-09-25 23:47:23 +02:00
Damien Arrachequesne
a5581a9789 refactor: migrate to TypeScript 2020-09-25 23:41:53 +02:00
Diego Molina
af165ae1c2 docs: adjusting Sauce Labs name (#3578) 2020-09-19 03:01:19 +02:00
Damien Arrachequesne
3d760b71d7 refactor: use ES6 syntax 2020-09-17 14:48:46 +02:00
Damien Arrachequesne
13cc07d6ad refactor: use prettier to format code 2020-09-17 14:31:06 +02:00
Damien Arrachequesne
d9bfcaeedb test: add Node.js 12 and 14 in the build matrix
Node.js 8 is removed, as it is now EOL.

Note: the node_modules folder is cached by default
2020-09-17 14:30:34 +02:00
Damien Arrachequesne
1238ddb995 chore: add package-lock.json file 2020-09-17 12:14:57 +02:00
Damien Arrachequesne
e0b35d054f docs: points towards the website
The website is now much more stable, so there's no need to keep two
copies of the same content (which must be manually kept in sync).
2020-09-01 09:37:29 +02:00
Damien Arrachequesne
a66f083d3e docs(examples): add create-react-app example
Related: https://github.com/socketio/socket.io-client/issues/1330
2020-07-09 11:32:48 +02:00
Damien Arrachequesne
f5a8f52f19 docs(examples/react-native): update video 2020-06-05 21:36:15 +02:00
Damien Arrachequesne
7a219f9459 docs(examples/react-native): add example with React Native
Includes e5bc1063cc
2020-06-05 08:57:04 +02:00
Damien Arrachequesne
5d16319692 docs(examples/webpack-build-server): update engine.io version
In order to include [0], which fixes the following error:

ERROR in ./node_modules/engine.io/lib/server.js
Module not found: Error: Can't resolve 'uws' in '/media/damien/git/other-bets/socket.io-parent/socket.io/examples/webpack-build-server/node_modules/engine.io/lib'
 @ ./node_modules/engine.io/lib/server.js 107:27-41
 @ ./node_modules/engine.io/lib/engine.io.js
 @ ./node_modules/socket.io/lib/index.js
 @ ./lib/index.js

[0] 85e544afd9
2020-06-04 16:36:19 +02:00
Damien Arrachequesne
8f90ba9c67 docs(examples): add example with passport authentication 2020-05-22 08:36:43 +02:00
Damien Arrachequesne
2a1aa1c59c docs(examples): bump dependencies
In order to include https://github.com/socketio/engine.io/releases/tag/3.4.1
2020-04-17 14:37:31 +02:00
Damien Arrachequesne
17747e4d69 docs(chat-example): bump dependencies
In order to include https://github.com/socketio/engine.io/releases/tag/3.4.1
2020-04-17 11:21:10 +02:00
Damien Arrachequesne
281de9ed47 docs(tweet-stream-example): migrate example
From https://github.com/darrachequesne/socket.io-tweet-stream
2020-04-14 10:17:47 +02:00
Damien Arrachequesne
edb95ea221 docs(whiteboard-example): update dependencies 2020-04-14 10:04:27 +02:00
Damien Arrachequesne
b74bb80122 docs(chat-example): remove dependency to the parent project 2020-04-14 09:56:42 +02:00
Damien Arrachequesne
47161a65d4 [chore] Release 2.3.0
Diff: https://github.com/socketio/socket.io/compare/2.2.0...2.3.0
2019-09-20 12:18:39 +02:00
Damien Arrachequesne
cf39362014 [chore] Bump socket.io-parser to version 3.4.0
Diff: https://github.com/socketio/socket.io-parser/compare/3.3.0...3.4.0
2019-09-20 11:04:11 +02:00
flaambe
4d01b2c84c test: remove deprecated Buffer usage (#3481) 2019-09-20 10:50:12 +02:00
Jonatan Juárez
82271921db [docs] Fix the default value of the 'origins' parameter (#3464)
Fix documentation about default origins value. The default should read `*:*` instead of `*
2019-09-20 10:37:54 +02:00
Damien Arrachequesne
1150eb50e9 [chore] Bump engine.io to version 3.4.0
Diff: https://github.com/socketio/engine.io/compare/3.3.1...3.4.0
2019-09-20 10:31:25 +02:00
Grant Timmerman
9c1e73c752 [chore] Update the license of the chat example (#3410)
There was no obvious reason to use BSD instead of MIT for that very basic chat app.

Closes #3411
2019-03-15 22:22:22 +01:00
Damien Arrachequesne
df05b73bb9 [chore] Release 2.2.0 2018-11-29 00:00:45 +01:00
Markko Legonkov
b00ae50be6 [feat] Add cache-control header when serving the client source (#2907) 2018-11-20 08:02:04 +01:00
Nadir Hussain Laskar
d3c653d876 [docs] Add Touch Support to the whiteboard example (#3104) 2018-11-20 08:01:09 +01:00
Antonio
a7fbd1ac4a [fix] Throw an error when trying to access the clients of a dynamic namespace (#3355)
Accessing the clients of a dynamic namespace throws because doing `io.of(/your-regex/g)` returns a namespace with no adapter and the clients methods tries to access `namespace.adapter.clients`.
2018-11-20 07:40:11 +01:00
Damien Arrachequesne
190d22b46e [chore] Bump dependencies
- engine.io: https://github.com/socketio/engine.io/compare/3.2.0...3.3.1
- socket.io-parser: https://github.com/socketio/socket.io-parser/compare/3.2.0..3.3.0
2018-11-20 07:33:41 +01:00
Damien Arrachequesne
7b8fba7ea2 [test] Update Travis configuration
Reference: https://github.com/nodejs/Release
2018-11-20 07:32:39 +01:00
Emmanuel DEMEY
e5f0ceaee0 [docs] Use new JavaScript syntax inside the README (#3360) 2018-11-08 00:26:54 +01:00
Damien Arrachequesne
7e35f901b8 [docs] fix this scope in the chat example
`user is typing` messages were not properly removed

Closes #3291
2018-08-28 09:05:44 +02:00
Damien Arrachequesne
2dbec77a38 [chore] Update issue template 2018-08-21 13:21:14 +02:00
Andrew Stelmach
d97d873aee [docs] update README.md (#3309) 2018-08-18 23:32:07 +02:00
Damien Arrachequesne
e0b2cb0c5a [chore] Release 2.1.1 2018-05-17 23:22:49 +02:00
Sleiman Sleiman
1decae341c [feat] Add local flag to the socket object (#3219)
To match the behaviour on the namespace (see #2628).
2018-04-27 13:03:25 +02:00
Donut
0279c47c8c [docs] Convert the chat example to ES6 (#3227) 2018-04-27 13:00:27 +02:00
Damien Arrachequesne
2917942b3e [docs] Clarify private messaging in the emit cheatsheet (#3232)
The previous version was confusing, as `socket.to(socket.id).emit()` does nothing.

Fixes #3220
2018-04-27 12:50:31 +02:00
Damien Arrachequesne
db831a3de4 [chore] Release 2.1.0 2018-03-29 23:30:03 +02:00
Damien Arrachequesne
ac945d1eba [feat] Add support for dynamic namespaces (#3195)
This follows #3187, with a slightly different API.

A dynamic namespace can be created with:

```js
io.of(/^\/dynamic-\d+$/).on('connect', (socket) => { /* ... */ });
```
2018-03-29 23:08:08 +02:00
Scott Gress
ad0c052eff [docs] Add note in docs for origins(fn) about error needing to be a string. (#2895) 2018-03-10 09:03:28 +01:00
Damien Arrachequesne
1f1d64bab6 [fix] Include the protocol in the origins check (#3198)
Previously, the protocol was not taken in account, which caused the following behaviour:

```js
io.origins('https://foo.example.com:443'); // ok as a string
io.origins(['https://foo.example.com:443'); // not ok as an array
```

Fixes #3190
2018-03-10 08:56:42 +01:00
Damien Arrachequesne
f4fc517e0f [fix] Properly emit 'connect' when using a custom namespace (#3197)
When using a custom namespace with a middleware, the client did not receive the 'connect' event.

Fixes #3082
2018-03-10 08:51:22 +01:00
Jumper Chen
be61ba0a20 [docs] Add link to a Dart client implementation (#2940) 2018-03-01 00:23:45 +01:00
Damien Arrachequesne
c0c79f019e [feat] Add support for dynamic namespaces (#3187) 2018-03-01 00:22:16 +01:00
Damien Arrachequesne
dea5214f21 [chore] Bump superagent and supertest versions (#3186) 2018-02-28 23:19:19 +01:00
Damien Arrachequesne
b1941d5dfe [chore] Bump engine.io to version 3.2.0 2018-02-28 23:10:40 +01:00
Miguel Piedrafita
a23007a635 [docs] Update license year (#3153) 2018-02-28 23:03:02 +01:00
Damien Arrachequesne
f48a06c040 [feat] Add a 'binary' flag (#3185)
So that the call to the `has-binary` method can be skipped. Usage:

```
// with binary data
socket.binary(true).emit("binary", obj);

// without binary data
socket.binary(false).emit("string", obj);

// call to hasBin
socket.emit("guess", obj);
```
2018-02-28 23:00:16 +01:00
Damien Arrachequesne
0539a2c4fd [test] Update travis configuration 2018-02-28 22:56:28 +01:00
Devlin Pajaron
c06ac071d0 [docs] Fix typo (#3157) 2018-02-25 09:26:24 +01:00
Damien Arrachequesne
52b09609db [chore] Bump debug to version 3.1.0 2018-02-25 09:22:40 +01:00
Damien Arrachequesne
1c108a35e4 [chore] Release 2.0.4 2017-10-22 15:16:29 +02:00
Thiago Santos
f333479080 [test] Use npm scripts instead of gulp (#3078) 2017-10-16 07:46:42 +02:00
Carson McKinstry
3f611654f2 [docs] Fix a grammar mistake in the API docs (#3076) 2017-10-07 15:08:14 +02:00
Vyacheslav Aristov
e26b71c78e [docs] Fix typo in API docs (#3066) 2017-10-07 14:36:02 +02:00
Haku
3386e155a8 [docs] Actually prevent input from having injected markup in chat example (#2987) 2017-08-27 08:40:26 +02:00
Stanley288
3684d590f5 [docs] Use path.join instead of concatenating paths (#3014) 2017-08-26 07:44:25 +02:00
Damien Arrachequesne
dd69abbeee [fix] Reset rooms object before broadcasting from namespace (#3039) 2017-08-26 07:36:26 +02:00
Damien Arrachequesne
1f0e64a6da [fix] Do not throw when receiving an unhandled error packet (#3038) 2017-08-26 07:35:57 +02:00
Gabriel Hautclocq
9d170a75d0 [docs] Add io.emit in the cheat sheet (#2992) 2017-07-01 07:57:34 +02:00
Nicolas Coden
7199d1b6ef [docs] Fix misnamed 'Object.keys' in API docs (#2979) 2017-06-19 12:16:26 +02:00
Damien Arrachequesne
bf7afb14cb [docs] Update Webpack server example (#2976) 2017-06-15 23:40:43 +02:00
Damien Arrachequesne
410f5bcb8e [docs] Update API documentation (#2973) 2017-06-13 23:05:26 +02:00
Damien Arrachequesne
65ece01135 [chore] Release 2.0.3 2017-06-12 14:05:46 +02:00
Damien Arrachequesne
db0c69969e [fix] Reset rooms object before broadcasting (#2970)
It seems packets could be delivered to wrong room in some case, if the
_rooms array was not reset before the next emit.
2017-06-12 14:01:35 +02:00
Damien Arrachequesne
94df7bcdfd [fix] Fix middleware initialization (#2969)
Fix "TypeError: Cannot convert undefined or null to object" when a
middleware is added before the engine is properly attached.
2017-06-12 14:00:48 +02:00
Ra'Shaun Stovall
9a014e2df4 [docs] Update slack badge (#2961)
Update badge to https://slackin-socketio.now.sh/badge.svg
2017-06-08 12:28:56 +02:00
Damien Arrachequesne
2b10f1b3a4 [docs] Update webpack example (#2960) 2017-06-03 13:53:03 +02:00
Damien Arrachequesne
a10dc8d92d [chore] Release 2.0.2 2017-06-01 14:01:24 +02:00
Damien Arrachequesne
2b216902e1 [fix] Fix timing issues with middleware (#2948)
Using a middleware could previously lead to a connecting client
receiving a connect event from the server before the server triggers
its own connect event.
2017-05-22 13:01:59 +02:00
Damien Arrachequesne
832b8fc6d9 [chore] Release 2.0.1 2017-05-09 01:40:46 +02:00
Damien Arrachequesne
a0056904c1 [fix] Update path of client file (#2934) 2017-05-09 01:36:40 +02:00
Damien Arrachequesne
3367eaa948 [chore] Release 2.0.0 2017-05-09 01:09:19 +02:00
Damien Arrachequesne
6c0705f733 [docs] Add an example of custom parser (#2929) 2017-05-09 00:46:01 +02:00
Damien Arrachequesne
1980fb4a03 [chore] Merge history of 1.7.x and 0.9.x branches (#2930) 2017-05-09 00:45:17 +02:00
Xavier Damman
0d07c47f81 [chore] Added backers and sponsors on the README (#2933) 2017-05-09 00:41:46 +02:00
Damien Arrachequesne
a086588747 [chore] Bump dependencies (#2926) 2017-04-28 22:33:40 +02:00
Damien Arrachequesne
87b06ad362 [feat] Move binary detection to the parser (#2923) 2017-04-25 00:38:07 +02:00
Caleb
199eec648e [docs] Replace non-breaking space with proper whitespace (#2913) 2017-04-19 22:19:57 +02:00
Faraz Patankar
f1b39a6b1d [docs] Update emit cheatsheet (#2906) 2017-04-03 07:20:38 +02:00
Damien Arrachequesne
240b154960 [docs] Explicitly document that Server extends EventEmitter (#2874) 2017-03-29 14:13:04 +02:00
efkan
c5b7738730 [docs] Add server.engine.generateId attribute (#2880) 2017-03-29 13:52:07 +02:00
Simen Bekkhus
03f3bc9ab3 [docs] Fix wrong space character in README (#2900) 2017-03-27 13:15:19 +02:00
SwhGo_oN
e40accf7a1 [docs] Fix documentation for 'connect' event (#2898) 2017-03-19 00:33:59 +01:00
Damien Arrachequesne
01a4623613 [feat] Allow to join several rooms at once (#2879) 2017-02-26 09:15:32 +01:00
Damien Arrachequesne
2d5b0026c5 [docs] Add webpack build example (#2828) 2017-02-22 12:48:46 +01:00
Damien Arrachequesne
5ae06e6285 [chore] Bump socket.io-adapter to version 1.0.0 (#2867) 2017-02-17 07:33:43 +01:00
sgress454
4d8f68c7dc [chore] Bump engine.io to version 2.0.2 (#2864)
Includes the following (from engine.io changelog):

* [fix] Initialize the WebSocket server in the Server constructor (#476)
* [chore] Bump ws to version 1.1.2 (vulnerability fix) (#480)
2017-02-16 22:01:53 +01:00
Tim Ruffles
5b79ab1af1 [docs] Update the wording to match the code example (#2853) 2017-02-13 23:52:07 +01:00
Damien Arrachequesne
54ff591b07 [feature] Merge Engine.IO and Socket.IO handshake packets (#2833) 2017-02-01 15:28:14 +01:00
H3rby7
e1facd5155 [docs] Small addition to the Express Readme Part (#2846) 2017-02-01 15:23:56 +01:00
Damien Arrachequesne
3b92cc2b26 [feature] Allow the use of custom parsers (#2829) 2017-01-24 07:10:19 +01:00
Damien Arrachequesne
3d695c60f1 [chore] Bump engine.io to version 2.0.0 (#2832) 2017-01-23 23:16:51 +01:00
Antoine LUCAS
3b5f4339a7 [fix] Use path.resolve by default and require.resolve as a fallback (#2797)
Browserify doesn't support require.resolve, and as a consequence, makes nexe fail the compilation. This PR attempts to get the path of the socket.io-client file via path.resolve and falls back to the original require.resolve if this file cannot be found.
2017-01-22 07:21:45 +01:00
Damien Arrachequesne
23c9dd34d5 [docs] Add a 'Features' section in the README (#2824) 2017-01-16 23:16:46 +01:00
Damien Arrachequesne
e28b475428 [docs] Add httpd cluster example (#2819) 2017-01-16 08:33:22 +01:00
Damien Arrachequesne
f7eed6e397 [docs] Add haproxy cluster example (#2818) 2017-01-16 08:33:09 +01:00
Damien Arrachequesne
988852986a [docs] Add nginx cluster example (#2817) 2017-01-16 08:32:53 +01:00
Damien Arrachequesne
8eaba085de [docs] Implement whiteboard example (#2810) 2017-01-16 08:32:33 +01:00
Tom Atkinson
2258a6a6e3 [fix] Properly close the connection on error (#2681) 2017-01-16 08:29:11 +01:00
Tom Atkinson
ad658b8cc2 [perf] Use shared instance of the encoder (#2825) 2017-01-16 08:25:52 +01:00
Tom Atkinson
e24434a0a0 [perf] Reset properties instead of deleting them (#2826)
Deleting properties is a v8 'optimization killer'
2017-01-16 08:23:22 +01:00
Damien Arrachequesne
b754cff2b4 [docs] Fix documentation for local flag (#2816) 2017-01-10 18:10:56 +01:00
Damien Arrachequesne
706ca2a0c1 [docs] Add emit cheatsheet (#2815) 2017-01-10 17:54:09 +01:00
Damien Arrachequesne
accd0bd64a [docs] Add pingInterval/pingTimeout/transports options in the API documentation (#2814) 2017-01-10 17:50:38 +01:00
Damien Arrachequesne
131a2befec [docs] Add an example for socket.join() method (#2813) 2017-01-10 17:46:54 +01:00
Damien Arrachequesne
0be865f614 [docs] Fix a typo on clients method in the API documentation (#2812) 2017-01-10 17:41:31 +01:00
Damien Arrachequesne
01b262fbe0 [chore] Update issue template with fiddle (#2811) 2017-01-10 10:16:27 +01:00
Bella
f260439933 [chore] Update copyright year LICENSE to 2017 (#2803) 2017-01-06 17:11:03 +01:00
Andrea Accardo
e04de3c2c8 [docs] Fix wrong argument name in API.md (#2802) 2017-01-04 06:37:12 +01:00
Ian Bro
a27802e19e [fix] Prevent null from being accepted as argument (#2606) 2016-12-30 16:22:16 +01:00
Gatsbill
c46d4481bd [perf] micro-optimisations (#2793) 2016-12-30 16:18:09 +01:00
bananaapple
d82190016f [docs] Add install script on Readme.md (#2780) 2016-12-30 16:11:26 +01:00
Damien Arrachequesne
255b845596 [docs] API documentation (#2784) 2016-12-30 16:10:54 +01:00
Damien Arrachequesne
1f59e4526a [chore] Release 1.7.2 (#2783) 2016-12-11 02:04:21 +01:00
Damien Arrachequesne
0a7afa85ea [chore] Bump engine.io to version 1.8.2 (#2782) 2016-12-11 01:27:19 +01:00
Serhii Sol
1e31769062 [fix] Fixes socket.use error packet (#2772)
* fix(socket): Fixes socket.use error packet which drops nodejs due to nuances of Nodejs' EventEmitter

* fix(socket): Fixes missing error event on socket

* fix(socket): test fix, should listen for clientSocket instead of server socket

* minor update
2016-12-01 02:25:13 +01:00
Damien Arrachequesne
797c9a3498 [chore] Release 1.7.1 (#2768) 2016-11-28 00:06:18 +01:00
Damien Arrachequesne
4f93a0b429 [chore] Release 1.7.0 (#2767) 2016-11-27 08:27:39 +01:00
Damien Arrachequesne
3c98130f15 [chore] Update client location and serve minified file (#2766)
Following https://github.com/socketio/socket.io-client/pull/1025, the
output files are now generated in the dist directory.
2016-11-27 08:24:27 +01:00
Damien Arrachequesne
9c23308c6e [chore] Bump engine.io to version 1.8.1 (#2765) 2016-11-27 07:55:02 +01:00
Tal Beja
955e5e0d91 [feature] Add a local flag (#2628)
That new flag will prevent the adapter (redis) from publishing the emit to the pub/sub server.

When several instances of a server receive the same event from a third party (not from a client), each server instance broadcasts the event to all his clients. With the local flag, and the change in the redis adapter, each server instance send the event only to his client, so each client receive only one unique event.
2016-11-24 23:44:52 +01:00
Zhu Liang
0ef55b26d4 [feature] serve sourcemap for socket.io-client (#2482) 2016-11-24 23:39:43 +01:00
Robbie Ferguson
4d8e2d342c [docs] Fixed grammar issues in the README.md (#2159)
Added a few periods and commas which were missing. Pluralised the word
'parameter' where it was incorrectly specified to singular on line 281.
Very minor edit. No source code changed.
2016-11-23 15:05:15 +01:00
Jérémy Lal
d48f848bb4 [docs] Comment connected socket availability for adapters (#2081) 2016-11-23 15:00:07 +01:00
Damien Arrachequesne
57b386385e [chore] Release 1.6.0 (#2757) 2016-11-20 04:26:56 +01:00
Damien Arrachequesne
9e7567daee [chore] Bump socket.io-adapter to version 0.5.0 (#2756) 2016-11-20 03:51:57 +01:00
Damien Arrachequesne
2e36799b17 [chore] Bump engine.io to version 1.8.0 (#2755) 2016-11-20 03:50:32 +01:00
Damien Arrachequesne
9bb5e9de2f [chore] Bump debug to version 2.3.3 (#2754) 2016-11-20 03:42:09 +01:00
Luca Tabone
ff2c15de68 [perf] Minor code optimizations (#2219) 2016-11-18 02:03:06 +01:00
Damien Arrachequesne
a483658607 [example] Add disconnection/reconnection logs to the chat example (#2675) 2016-11-18 01:52:45 +01:00
Julian Grinblat
4c5dbd8824 [fix] Don't drop query variables on handshake (#2745)
Parameters passed during handshake, such as tokens, were being dropped.
2016-11-16 01:17:19 +01:00
mhmeadows63
e14a10b7ce [feature] add support for Server#close(callback) (#2748) 2016-11-15 21:52:56 +01:00
Alex
5a123beea5 [feature] Add support for socket middleware (#2306) 2016-11-05 01:51:29 +01:00
Philip YoonShin
2ed5f0f5fb [chore] Update year to 2016 (#2456) 2016-11-05 01:19:15 +01:00
Julian Grinblat
e9f980c475 [feature] Add support for all event emitter methods (#2601) 2016-11-05 01:14:21 +01:00
Jamie Davis
6f44f3a8ef [test] Fix leaking clientSocket (#2721)
Test 'should be able to close sio sending a port' defined a clientSocket
but didn't set 'reconnection: false'.

Now, the default behavior of a clientSocket is 'reconnection: true'.
As a result, the clientSocket was "leaked" from the test case
and seemed to intermittently connect to the servers in subsequent
test cases. This would cause other tests to timeout unexpectedly.

It's not clear to me why this would happen, since the test case
assigns a unique port number to the socket.
However, if you go into socket.io-client and assign and log
unique IDs to each socket, then you'll see that this clientSocket
shows up in other test cases if the reconnectionDelay strikes
unluckily.
2016-11-05 01:06:04 +01:00
Atanas Palavrov
04fc0f3677 [feature] Loading client script on demand. (#2567)
Support for the serving of the client script mess with packagers like
browserify, webpack. Especcialy in projects where it is not used at all.
This patch is workaround to avoid that problem in the cases when client
script is not served.
2016-10-30 14:22:00 +01:00
Kenton Varda
d026c00d05 [fix] Make ETag header comply with standard. (#2603)
The standard says that an ETag must be surrounded in double quotes:

https://tools.ietf.org/html/rfc7232#section-2.3

Although browsers tend to be lenient, omitting the quotes can confuse/break some kinds of proxies and other tools that demand compliant formatting. For example, Sandstorm.io enforces strict HTTP usage for security reasons and will block responses with invalid ETags.
2016-10-30 14:19:00 +01:00
Damien Arrachequesne
fdf64cc38f [chore] Release 1.5.1 (#2735) 2016-10-24 03:31:32 +02:00
Damien Arrachequesne
5badb6436e [chore] Bump socket.io-parser to 2.3.1 (#2734) 2016-10-24 03:23:03 +02:00
Damien Arrachequesne
c20e0b26c9 [chore] Bump engine.io to 1.7.2 (#2729) 2016-10-24 03:21:11 +02:00
bananaapple
5c10c5439b [test] Use client function to unify client in test script (#2731) 2016-10-24 02:35:01 +02:00
Damien Arrachequesne
8182ecc61c [chore] Add Github issue and PR templates (#2733) 2016-10-22 09:19:08 +02:00
Feram Bot
ccd3376627 [docs] Minor fixes (#2526) 2016-10-21 03:21:45 +02:00
Damien Arrachequesne
58a73d39e9 [chore] Bump socket.io-parser to 2.3.0 (#2730) 2016-10-21 03:18:49 +02:00
Tom Atkinson
e60bd5a4da [fix] Avoid swallowing exceptions thrown by user event handlers (#2682) 2016-10-21 03:16:36 +02:00
Paul Meinhardt
21dffa4b58 [docs] Link readme npm package badge to npm registry page (#2612) 2016-10-21 03:10:33 +02:00
Marcio Puga
94852e3d23 [docs] Fix typo (#2724) 2016-10-21 03:06:59 +02:00
davidlondono
b8c60506a6 [docs] Fix JSDoc of optional parameters (#2465)
Making proper optional Docs for socketIO
2016-10-21 03:02:59 +02:00
syuilo⭐️
ecc76f48bc [docs] Add link to LICENSE (#2221) 2016-10-21 03:00:38 +02:00
Damien Arrachequesne
c94058f9b0 [chore] release 1.5.0 (#2711) 2016-10-07 00:13:33 +02:00
Damien Arrachequesne
43d9a4b55d [feature] Add a 'disconnecting' event to access to socket.rooms upon disconnection (#2332) 2016-10-06 23:23:26 +02:00
Alejandro Oviedo
df916172dd [chore] Link build badge to master branch (#2549) 2016-10-06 23:12:15 +02:00
Damien Arrachequesne
271c625243 [chore] Restrict files included in npm package (#2709) 2016-10-06 23:11:33 +02:00
Damien Arrachequesne
628fe8f1b2 [chore] Point towards current master of socket.io-client (#2710) 2016-10-06 23:10:54 +02:00
Damien Arrachequesne
db62e1bf67 [chore] Remove unused zuul-ngrok dependency (#2708) 2016-10-06 23:10:33 +02:00
YasharF
ba4c7921ef [chore] Bump engine.io to 1.7.0 (#2707) 2016-10-06 10:03:55 +02:00
Damien Arrachequesne
30ea0b8d7d Merge pull request #2599 from boazsegev/patch-1
Documentation update to help new programmers
2016-08-05 21:07:30 +02:00
Bo
2d141aff7c Prevent mixup for new programmers
The documentation, inadvertently, causes confusion for newer programmers, hindering their learning curve and ability to learn `socket.io` faster.

This proposed change aims at preventing this confusion to allow new programmers easier access to resources, especially when searching the web for more information.

The name `socket` in the documentation refers to the API gateway, or abstraction layer, related to the `client` and other properties. However, in the rest of the programming world, `sockets` usually refer to Berklee sockets or the lower-level communication channel that is used to implement Protocols such as the Websocket Protocol and HTTP.

New programmers often search for more informations using the `sockets` keyword when they are grappling with learning the `socket.io` API.

A good example is the stack overflow site, where newer programmers incorrectly tag their questions `sockets` and in turn don't get a fast response to their questions.

By simply changing the name of the variable used to describe socket.io's "Socket" class instances from `socket` to `client`, this mixup should be mitigated considerably.
2016-06-26 14:32:37 -04:00
Guillermo Rauch
40763d3962 1.4.8 2016-06-23 19:24:38 -07:00
Guillermo Rauch
2a092bd2fb Release 1.4.8 2016-06-23 19:22:41 -07:00
Guillermo Rauch
4137eb5c43 package: bump engine.io 2016-06-23 19:12:28 -07:00
Guillermo Rauch
e3207005da 1.4.7 2016-06-23 17:31:33 -07:00
Guillermo Rauch
42aa77614e Release 1.4.7 2016-06-23 17:25:46 -07:00
Guillermo Rauch
1491a96c95 package: bump engine.io 2016-06-23 17:11:15 -07:00
Guillermo Rauch
dcca01f5a4 Release 1.4.6 2016-05-02 20:57:44 -07:00
Guillermo Rauch
3b58fa04d5 package: bump engine.io 2016-05-02 20:56:15 -07:00
Naoyuki Kanezawa
0c6d50d9c0 Merge pull request #2416 from nus-fboa2016-si/chatexample
updated express version to express 4
2016-04-12 03:58:08 +09:00
Naoyuki Kanezawa
881f16553c Merge pull request #2508 from tw0517tw/quote-exec
add quote to exec paths, prevent error when spaces in path
2016-04-12 03:57:43 +09:00
Guillermo Rauch
e5a8d4d2d9 Merge pull request #2520 from nkzawa/fix/ignore-dist
Ignore dist directory for now
2016-04-11 08:45:11 -07:00
Guillermo Rauch
fb0253edea Merge pull request #2422 from nus-fboa2016-si/queryStringFix
Fix for Issue #331 on socket.io-client
2016-04-11 08:44:59 -07:00
tw0517tw
3c5f5a0864 use a bigger timeout for slower machine 2016-04-11 22:31:47 +08:00
tw0517tw
a23d26a617 add quote to exec paths, prevent error when spaces in path 2016-04-11 22:21:34 +08:00
Zhu Liang
910b5d77a6 fixed version notation 2016-04-11 22:19:49 +08:00
Naoyuki Kanezawa
438ad63cdf Merge pull request #2420 from revington/test-node-v5-stable
[Travis] Add Node 5.x (Stable) to the test matrix
2016-04-11 23:09:41 +09:00
Naoyuki Kanezawa
7e9a67d8ee Merge pull request #2415 from nus-fboa2016-si/documentation
Documentation
2016-04-11 23:05:33 +09:00
Naoyuki Kanezawa
0ae070885d Merge pull request #2477 from callahad/chat-layout-fix
Fix chat display in Firefox
2016-04-11 23:00:07 +09:00
Naoyuki Kanezawa
36d99d8d84 Merge pull request #2492 from westy92/master
Update package.json
2016-04-11 22:20:46 +09:00
nkzawa
0e63b0910e ignore dist for now 2016-04-11 22:11:19 +09:00
Guillermo Rauch
3c7350fa58 Merge pull request #2509 from tw0517tw/patch-1
stop prepend /# before id when no namespace
2016-04-10 11:24:42 -07:00
Guillermo Rauch
aadd5da655 Merge pull request #2496 from nus-fboa2016-si/compat-test
Added test for compat version transformed by babel
2016-04-02 18:31:30 -07:00
吳東曄 Wu, Dung-Ie
6d4128750b stop append /# before id when no namespace 2016-04-02 01:55:53 +08:00
Zhu Liang
6edcd1c6ba styling fixes 2016-03-31 12:55:42 +08:00
Zhu Liang
6b2394e612 disable loading lib by default to avoid syntax error due to lib containing new es6 syntax 2016-03-31 03:54:32 +08:00
Zhu Liang
677af3fa11 changed env var name, added testing documentation to readme 2016-03-21 13:11:03 +08:00
Zhu Liang
a1ff739b36 babel transpile before test, print error 2016-03-19 20:19:08 +08:00
Zhu Liang
de5b588e17 explicit distinction between current and compat in test so we can serve either compat or current as default 2016-03-19 20:13:57 +08:00
Zhu Liang
5a20c1195b set env vars in travis 2016-03-19 19:49:41 +08:00
Zhu Liang
5253bc400b use multiple npm scripts 2016-03-19 19:41:14 +08:00
Zhu Liang
1245a5639e added compat test 2016-03-19 19:21:54 +08:00
Zhu Liang
88161539a1 implement compat test using env variable 2016-03-17 13:42:29 +08:00
Zhu Liang
d99d4d15ae add compat test for babel-transformed codes 2016-03-17 13:11:20 +08:00
Seth Westphal
06ecfe5444 Explicit local gulp is unnecesary 2016-03-16 13:01:49 -05:00
Seth Westphal
e90b4eba1e Update repository URL 2016-03-16 12:58:59 -05:00
Guillermo Rauch
c7de1a1adf Merge pull request #2471 from nus-fboa2016-si/gulp-rebased
Add gulp and babel
2016-03-12 20:04:48 -08:00
Dan Callahan
7bae6ac636 Fix chat display in Firefox 2016-03-08 19:50:55 -06:00
Diga Widyaprana
355b5156fe Remove node 0.8 from travis 2016-03-09 09:36:51 +08:00
Diga Widyaprana
3e168ee0b8 Redirect make tasks to gulp 2016-03-06 11:40:57 +08:00
Diga Widyaprana
ed9ab77dcb Minor fixes to gulp tasks
- Only provide entry point as first argument of gulp.src
- {read:false} option for mocha tests
- change timeout:2000 to slow:200 to mirror makefile's mocha options
- replace var with const where appropriate
2016-03-06 11:40:57 +08:00
Diga Widyaprana
1104cd135e Use local instead of global gulp in npm test 2016-03-06 11:40:57 +08:00
Diga Widyaprana
0be915cd0f Add gulp task clean to clean transpile output
- Work done by @YijinL. Part of @05ad308
2016-03-06 11:40:57 +08:00
Diga Widyaprana
c6dd41b915 Minor refactoring to transpile task
- Transpiling is now gulp transpile
- Default redirects to transpile
- Refactor transpile output directory to a separate constant
- Work by @YijinL in @05ad308
2016-03-06 11:32:40 +08:00
Diga Widyaprana
0f14312d7b Add gulp help
Work was done by @YijinL in 2 separate commits (@9204125 and @05ad308)
2016-03-06 11:32:09 +08:00
Diga Widyaprana
97bd95f036 Don't use dynamic dependencies 2016-03-04 18:06:00 +08:00
Diga Widyaprana
11e0f19272 Inline babel configuration 2016-03-04 18:06:00 +08:00
Yijin
e388a3319d npm test script to use gulp 2016-03-04 18:06:00 +08:00
Zheng Weihan
b551ce9835 added test-cov task. 2016-03-04 18:06:00 +08:00
Zhu Liang
0bac96a6b2 added comment for babel 2016-03-04 14:46:08 +08:00
Zhu Liang
1d07b10339 integrated babel into gulp 2016-03-04 14:46:08 +08:00
Zheng Weihan
398b5479f0 delete unused dependency 2016-03-04 14:45:55 +08:00
Zheng Weihan
d9eb729eab implement gulp build system for test. 2016-03-04 14:45:03 +08:00
whattokingu
f9db72997f Merge pull request #10 from whattokingu/queryStringFix
Query string fix
2016-02-14 13:57:06 +08:00
Zheng Weihan
1293505dc2 update tests. 2016-02-14 13:48:28 +08:00
Zheng Weihan
f4e9e71c56 Merge branch 'queryStringFix' of https://github.com/whattokingu/socket.io into queryStringFix
# By whattokingu
# Via whattokingu
* 'queryStringFix' of https://github.com/whattokingu/socket.io:
  conform to style guide

Conflicts:
	lib/client.js
2016-02-14 13:47:59 +08:00
Zheng Weihan
045674de97 remove unnecessary decoder. url.parse already decodes string.
add test to test decoding function.
2016-02-14 13:46:26 +08:00
whattokingu
7091acf24c Merge pull request #9 from whattokingu/queryStringFix
Query string fix
2016-02-13 14:41:15 +08:00
whattokingu
19341051e8 conform to style guide 2016-02-13 14:35:12 +08:00
Zheng Weihan
e141e09aaf change decodeUriComponents calls 2016-02-13 14:28:21 +08:00
Zheng Weihan
5fabe4e780 call decodeURIComponent on query received from client.
update package.son to point to latest commit in socket.o-client package (with URI encoder)
2016-02-13 14:10:20 +08:00
whattokingu
7760a71d90 Merge pull request #8 from whattokingu/queryStringFix
add comments to code
2016-02-04 13:28:29 +08:00
Zheng Weihan
c077357eff add comments to code 2016-02-04 13:27:36 +08:00
whattokingu
2f26a2bdb4 Merge pull request #7 from whattokingu/queryStringFix
add test for issue #331 on socket.io-client.
2016-01-31 15:45:35 +08:00
Zheng Weihan
13af610f6d add test for issue #331 on socket.io-client. 2016-01-31 15:44:39 +08:00
whattokingu
abcedf53ec Merge pull request #6 from whattokingu/queryStringFix
sync to master branch
2016-01-31 11:23:02 +08:00
Zheng Weihan
24456fdcbe Merge branch 'master' into queryStringFix
* master:
  Release 1.4.5
  package: bump `engine.io`
  add a test for graceful shutdown
2016-01-31 11:21:30 +08:00
Pedro Narciso García Revington
25116ab179 test node 5 (stable) 2016-01-30 21:53:04 +01:00
Zhu Liang
a116d52e30 updated express version to express 4 2016-01-30 11:57:31 +08:00
whattokingu
cecf5f127e Merge pull request #5 from whattokingu/documentation
Added Documentation
2016-01-30 11:31:11 +08:00
Zheng Weihan
1c467e15e6 Issue #2400, added documentation 2016-01-30 11:28:40 +08:00
whattokingu
a110542563 Merge pull request #4 from whattokingu/queryStringFix
Fix for Issue #331 on socket.io-client
2016-01-30 10:16:19 +08:00
Zheng Weihan
7d55724468 refactor parsing of URL in CONNECT packet to use 'url' library. 2016-01-30 09:47:28 +08:00
Zheng Weihan
1d84c55743 fix to issue #331 on socket.o-client.
Parses CONNECT packet for query string and replaces query in socket.handshake.
2016-01-28 14:40:05 +08:00
Guillermo Rauch
b3fc530abe Release 1.4.5 2016-01-26 13:26:17 -08:00
Guillermo Rauch
d0dfa54dcb package: bump engine.io 2016-01-26 10:42:41 -08:00
Guillermo Rauch
198b836759 Merge pull request #2399 from nkzawa/graceful-close
Add a test for graceful shutdown
2016-01-21 09:15:36 -08:00
nkzawa
a75f46f06f add a test for graceful shutdown 2016-01-21 20:50:44 +09:00
Naoyuki Kanezawa
2a91fd57c7 Merge pull request #2344 from denghongcai/patch-2
fix wrong jsdoc
2016-01-17 15:25:32 +09:00
Naoyuki Kanezawa
fe891293b2 Merge pull request #2353 from faizalpribadi/patch-1
fix typo word :)
2016-01-17 15:23:35 +09:00
Naoyuki Kanezawa
6e450f75b4 Merge pull request #2374 from darrachequesne/patch-4
Add badges showing dependency status
2016-01-17 15:22:52 +09:00
Naoyuki Kanezawa
22c985cae6 Merge pull request #2380 from darrachequesne/patch-5
Document type change of Socket#rooms
2016-01-17 15:22:05 +09:00
Guillermo Rauch
fea3d79a2c Release 1.4.4 2016-01-10 22:36:31 -08:00
Guillermo Rauch
d3dde130b7 package: bump engine.io 2016-01-10 22:27:44 -08:00
Damien Arrachequesne
899de7f873 Document type change of Socket#rooms 2016-01-09 22:08:30 +01:00
Guillermo Rauch
f1a3e8db2a Release 1.4.3 2016-01-08 08:17:50 -08:00
Guillermo Rauch
dad82c3343 Release 1.4.2 2016-01-07 18:58:05 -08:00
Guillermo Rauch
a6cbf6b205 package: bump engine.io 2016-01-07 18:14:39 -08:00
Damien Arrachequesne
580100d491 Bump dev dependencies 2016-01-07 22:59:28 +01:00
Damien Arrachequesne
acb9cb421d Add badges showing dependency status 2016-01-07 22:58:59 +01:00
Guillermo Rauch
6d5d7e4411 Release 1.4.1 2016-01-07 12:52:27 -08:00
Guillermo Rauch
ddb3445f3d Release 1.4.0 2016-01-05 15:44:48 -08:00
Guillermo Rauch
6eb9807f17 package: bump engine.io for sec advisory 2016-01-05 13:40:54 -08:00
Faizal Pribadi
abe2394a24 fix typo word :)
update docs source code
2015-12-20 16:16:42 +07:00
Hongcai Deng
7012ba6c64 fix wrong jsdoc 2015-12-14 15:31:42 +08:00
Guillermo Rauch
7b0073c00f Merge pull request #2335 from nkzawa/patch-7
Improve the chat demo
2015-12-04 17:10:23 -08:00
nkzawa
0313ad0ea3 improve the chat demo 2015-12-05 10:07:08 +09:00
Guillermo Rauch
d310d42472 package: bump engine.io 2015-12-04 10:56:08 -08:00
Guillermo Rauch
709ceba00a package: bump socket.io-adapter for release 2015-12-03 10:28:33 -08:00
Guillermo Rauch
b29312bc61 package: bump engine.io for node 0.8 fix 2015-12-01 12:15:36 -08:00
Guillermo Rauch
51901160df package: temporarily revert version for tests 2015-12-01 11:24:06 -08:00
Guillermo Rauch
ab1b36e13f package: bump engine.io for ws memory fix 2015-11-30 08:16:21 -08:00
Guillermo Rauch
f7a2f35590 package: bump engine.io 2015-11-28 16:34:44 -08:00
Guillermo Rauch
c348737fe6 socket.io: increase large binary data test timeout 2015-11-28 15:13:13 -08:00
Guillermo Rauch
dde3737165 package: bump engine.io for release 2015-11-28 12:07:08 -08:00
Guillermo Rauch
8df4c7931b Merge pull request #2325 from darrachequesne/patch-2
Trigger callback even when joining an already joined room
2015-11-28 10:56:46 -08:00
Damien Arrachequesne
1dfacc6647 Trigger callback even when joining an already joined room 2015-11-27 22:08:18 +01:00
Guillermo Rauch
35a0fe0377 package: bump parser 2015-11-25 10:14:56 -08:00
Guillermo Rauch
3b00312fa7 namespace: clear rooms flag after a clients call (fixes #1978) 2015-11-23 09:40:57 -08:00
Guillermo Rauch
7b420295ef Merge pull request #2249 from pmq20/minqi-another
[Travis] Add Node 4.x to the test matrix
2015-11-23 09:31:48 -08:00
Guillermo Rauch
c504315982 Merge pull request #2322 from darrachequesne/issue-2199-clean
Add hasOwnProperty checks
2015-11-23 09:19:35 -08:00
Guillermo Rauch
520b5c37d5 Merge pull request #2321 from nkzawa/patch-6
Update redirects in README
2015-11-23 09:19:03 -08:00
Damien Arrachequesne
09f446eca0 Add hasOwnProperty checks 2015-11-23 15:12:21 +01:00
Naoyuki Kanezawa
aecf3bf71c Merge pull request #2218 from futbalguy/master
Clarified documentation of Socket.in
2015-11-23 17:37:07 +09:00
nkzawa
6c0a79e2b9 update redirects in README 2015-11-23 17:28:11 +09:00
Guillermo Rauch
8683206e31 Merge pull request #2239 from darrachequesne/issue-2199
converted arrays to objects
2015-11-22 10:34:57 -08:00
Guillermo Rauch
988d9d2346 Merge pull request #1999 from nkzawa/patch-3
Fix a few assertions are not executed properly
2015-11-22 10:17:02 -08:00
Damien Arrachequesne
b73d9bea4e converted arrays to objects 2015-11-22 11:12:40 +01:00
Naoyuki Kanezawa
d4fb6a5904 Merge pull request #2316 from tripu/master
Update “debug” to avoid vulnerability in “ms”
2015-11-22 10:39:23 +09:00
tripu
0517c609ba Avoid ^ in "debug" dependency (fixes #2314) 2015-11-21 23:59:16 +01:00
tripu
aa9438fee2 Update package "debug" to avoid "ms" vulnerability 2015-11-21 23:55:00 +01:00
Guillermo Rauch
aee466cc71 Update Readme.md 2015-11-21 10:54:19 -08:00
Guillermo Rauch
65f75d7732 Merge branch 'master' of github.com:socketio/socket.io 2015-11-21 10:46:26 -08:00
Guillermo Rauch
279c52a4c5 package: bump socket.io-parser 2015-11-21 10:45:43 -08:00
Naoyuki Kanezawa
67d1a67b1c Merge pull request #2319 from darrachequesne/patch-3
Minor fix
2015-11-21 23:21:39 +09:00
Damien Arrachequesne
aae68d74b1 Minor performance optimization 2015-11-20 22:03:03 +01:00
Damien Arrachequesne
bf5897cedc Fixed tests with large data 2015-11-20 22:01:16 +01:00
Damien Arrachequesne
a1a1c6657a Removed unused variable 2015-11-20 22:00:42 +01:00
Guillermo Rauch
2a4f7ae161 Merge pull request #2136 from nkzawa/patch-5
Don't set request property
2015-11-20 12:59:05 -08:00
Naoyuki Kanezawa
dba0576ca9 Merge pull request #2317 from ChaofengZhou/master
fixed a typo in the example code
2015-11-20 13:13:10 +09:00
Chaofeng
ba90f0991b fixed a typo in the example code 2015-11-19 21:09:34 -07:00
Guillermo Rauch
9a54e9cace package: bump mocha 2015-11-18 19:53:25 -08:00
Guillermo Rauch
9df4cb64b8 bump zuul-ngrok 2015-11-18 19:51:47 -08:00
Guillermo Rauch
c8f525868a package: bump has-binary 2015-11-18 16:56:06 -08:00
Guillermo Rauch
a39d7c2ae4 Merge pull request #2171 from KevinMartin/patch-1
Actually prevent double callbacks...
2015-11-18 12:56:01 -08:00
Guillermo Rauch
4ba266d404 Merge pull request #2307 from darrachequesne/patch-1
Upgrade npm version in order to fix node v0.8 build
2015-11-16 15:55:20 -08:00
Damien Arrachequesne
6b49779420 Upgrade npm version in order to fix node v0.8 build 2015-11-17 00:44:42 +01:00
Guillermo Rauch
b1775b1cb8 Merge pull request #2051 from tobalsgithub/master
Allowing a custom function for opts.allowRequest
2015-11-16 13:15:08 -08:00
Guillermo Rauch
ef52967301 Merge pull request #2271 from dazorni/master
Working travis build status
2015-11-16 13:12:26 -08:00
Guillermo Rauch
fde38b1bd7 Merge pull request #2208 from odeke-em/fix-legacy-repo-info
README: fixed up legacy repo links
2015-11-16 13:10:24 -08:00
Sebastian Zorn
75da57abb2 Working travis build status 2015-10-06 21:42:33 +02:00
Guillermo Rauch
21ea31a34e Merge branch '1.3.7-patch' 2015-09-21 04:30:59 +04:00
Guillermo Rauch
e2ebd4349b Release 1.3.7 2015-09-21 04:21:11 +04:00
Guillermo Rauch
b771f74a22 package: bump socket.io-client for node4 compatibility 2015-09-21 04:16:59 +04:00
Guillermo Rauch
8744007dc7 package: bump engine.io for node4 compatibility 2015-09-21 04:10:19 +04:00
P.S.V.R
3658928ee7 [Travis] Add Node 4.x to the test matrix 2015-09-16 17:39:26 +08:00
Guillermo Rauch
210e688732 package: bump engine.io 2015-09-09 15:47:14 -07:00
Guillermo Rauch
ae5420b727 package: bump engine.io and socket.io-client 2015-08-30 10:51:25 -07:00
futbalguy
d5b3bb46f8 Clarified documentation of Socket.in 2015-08-23 10:12:23 -07:00
Emmanuel Odeke
575d35a371 README: fixed up legacy repo links 2015-08-16 20:36:39 -06:00
Guillermo Rauch
e41483be9e Merge branch '1.3.6-patch' 2015-07-14 20:04:44 -07:00
Guillermo Rauch
c79e787671 test: better timeout for stress test 2015-07-14 19:58:42 -07:00
Guillermo Rauch
a2f6bb99d6 Merge branch '1.3.6-patch' 2015-07-14 18:02:56 -07:00
Guillermo Rauch
3e4061bfef Release 1.3.6 2015-07-14 17:59:50 -07:00
Guillermo Rauch
4c1d691fe5 package: bump engine.io to fix build on windows 2015-07-09 09:28:43 -07:00
Kevin Jose Martin
514aeb4fcd Actually prevent double callbacks...
We declare `sent = false` and even check `if (sent)` is truthy, but we never set it to truthy, therefore it never really *prevents double callbacks*...
2015-07-06 11:36:00 -04:00
Nathan Rajlich
876833198d Merge pull request #2111 from kemitchell/spdx-license
Use a Standard-Compliant License Identifier
2015-06-05 11:51:30 -07:00
Naoyuki Kanezawa
4d36d6c01a don't set request property 2015-05-30 03:34:05 +09:00
Guillermo Rauch
43fa075ec4 bump client 2015-05-27 22:56:15 -07:00
Guillermo Rauch
91c7bde34b Merge commit '342faf219793fc5c1f130fc33e3fb5422dab516d' 2015-05-27 22:55:15 -07:00
Guillermo Rauch
874a4a8535 package: bump client 2015-05-27 08:19:15 -07:00
Guillermo Rauch
93b571406e package: bump engine.io to fix build issues 2015-05-25 14:34:10 -07:00
Kyle Mitchell
98af793f07 use a valid SPDX license identifier 2015-05-05 00:08:44 +00:00
Guillermo Rauch
3f72dd3322 Merge pull request #2063 from kapouer/patch-1
Let adapter.add find connected socket
2015-04-10 21:38:41 -07:00
Guillermo Rauch
d0d38220fb Update Readme.md 2015-04-08 16:53:04 -07:00
Guillermo Rauch
f8aa157d5d remove proxy index file 2015-04-05 16:53:28 -07:00
Guillermo Rauch
0e13e9a268 bumped adapter 2015-04-05 15:52:59 -07:00
Guillermo Rauch
916872587f Merge pull request #2013 from nkzawa/namespace-flags
Supports flags on namespace
2015-04-05 15:51:54 -07:00
Guillermo Rauch
a7072845ea Merge pull request #2006 from nkzawa/patch-4
improve Socket#packet and Client#packet and enable volatile and compress when broadcast
2015-04-05 15:51:49 -07:00
Jérémy Lal
425409945b Let adapter.add find connected socket
When a socket connects, it joins its own room, resulting in a call to adapter.add.
The adapter in turn should be able to find the socket by id.
2015-03-24 14:54:52 +01:00
Guillermo Rauch
5826ef0bb5 Merge pull request #2059 from rase-/update/debug
Bump debug to 2.1.3
2015-03-17 16:42:00 -07:00
Tony Kovanen
14e32a9bad Bump debug to 2.1.3 2015-03-18 01:40:19 +02:00
TC
1dde0f3947 Allowing a custom function for opts.allowRequest 2015-03-12 15:50:31 -06:00
Guillermo Rauch
342faf2197 Release 1.3.5 2015-03-03 10:50:10 -08:00
Guillermo Rauch
12c6ee132d improve test 2015-03-03 10:34:56 -08:00
Guillermo Rauch
c9d909c993 package: bump socket.io-parser 2015-03-03 10:34:40 -08:00
Guillermo Rauch
125ab51338 test: added test for parser breakage 2015-03-03 10:08:26 -08:00
Guillermo Rauch
b31ac18554 test with 0.12 2015-02-19 15:38:35 -08:00
Naoyuki Kanezawa
53cdd8f1fc support flags on namespace 2015-02-20 03:34:09 +09:00
Naoyuki Kanezawa
81aea995ed improve Socket#packet and Client#packet 2015-02-15 04:33:20 +09:00
Guillermo Rauch
1b2d902f33 Release 1.3.4 2015-02-14 10:57:50 -08:00
Guillermo Rauch
9536437907 package: bump socket.io-client 2015-02-14 10:55:15 -08:00
Naoyuki Kanezawa
56fe26661d fix a few assertions 2015-02-12 06:09:30 +09:00
Guillermo Rauch
29974ac777 Release 1.3.3 2015-02-03 17:27:51 -08:00
Guillermo Rauch
ef23c74bea remove compression tests 2015-02-03 17:07:43 -08:00
Guillermo Rauch
49423d70bc added failing tests 2015-02-03 17:04:33 -08:00
Guillermo Rauch
715c7f99b4 socket: warn node_redis-style about missing error 2015-02-03 17:04:06 -08:00
Guillermo Rauch
f2ea965c6b package: bump parser 2015-02-03 16:32:48 -08:00
Guillermo Rauch
a93d05a9f3 package: bump parser 2015-02-03 16:30:49 -08:00
Guillermo Rauch
5ce06d3088 socket: warn node_redis-style about missing error 2015-02-03 16:26:21 -08:00
Guillermo Rauch
816bfec783 added failing tests 2015-02-03 16:26:08 -08:00
Guillermo Rauch
0a17c90d7a test: added failing test 2015-02-03 15:10:46 -08:00
Guillermo Rauch
3645741b86 test: increase timeout for large binary data test 2015-01-31 09:35:37 -08:00
Guillermo Rauch
f2a7322b5a update deps 2015-01-31 08:46:32 -08:00
Guillermo Rauch
97c6568f65 Merge pull request #1966 from cha0s/clients
Suggestion for implementation of clients API
2015-01-31 08:34:43 -08:00
Ruben Rodriguez II
8814825a35 Suggestion for implementation of clients API 2015-01-31 02:17:49 -06:00
Guillermo Rauch
58eaecad27 Merge branch 'master' of github.com:Automattic/socket.io 2015-01-29 20:39:00 -08:00
Guillermo Rauch
94157e650e point to master 2015-01-29 20:38:36 -08:00
Guillermo Rauch
0935b81da2 Merge pull request #1963 from michael-luo/bugfix/1956
bugfix/1956 test for don't reuse same-namespace connections
2015-01-29 20:34:38 -08:00
Michael Luo
afa871bb8a bugfix/1956 test for don't reuse same-namspace connections 2015-01-24 20:19:16 -08:00
Guillermo Rauch
1b01e16a6c fix broken previous commit 2015-01-24 08:02:05 -08:00
Guillermo Rauch
bd6f638c8f package: bump to work with all objects (fixes #1955) 2015-01-24 07:06:30 -08:00
Guillermo Rauch
83b36e54ac Merge pull request #1958 from nkzawa/compress
Support compression
2015-01-23 10:04:43 -08:00
Guillermo Rauch
2f0d9d05af fix origin verification default https port [evanlucas]
for PR #1693
2015-01-22 21:41:59 +00:00
Naoyuki Kanezawa
429eb0cb7c point to the specific commit 2015-01-22 05:26:37 +09:00
Naoyuki Kanezawa
ac8e8598d7 support compression 2015-01-22 05:01:45 +09:00
Guillermo Rauch
9ba6d47ec7 Release 1.3.2 2015-01-19 15:14:18 +00:00
Guillermo Rauch
3d49cafd03 Release 1.3.1 2015-01-19 11:37:14 +00:00
Guillermo Rauch
77ca2dcbda package: bump engine.io (noop) 2015-01-19 11:11:12 +00:00
Guillermo Rauch
7e4aa4fa64 Release 1.3.0 2015-01-19 10:25:49 +00:00
Guillermo Rauch
b46e480f65 Update Readme.md 2015-01-19 09:26:12 +00:00
Guillermo Rauch
5e92dd8663 package: bump socket.io-client 2015-01-18 19:42:43 +00:00
Guillermo Rauch
f981d3f050 package: bump engine.io 2015-01-18 19:41:45 +00:00
Guillermo Rauch
f57505fee7 Merge branch 'master' of github.com:Automattic/socket.io 2015-01-18 18:53:17 +00:00
Guillermo Rauch
f8f1b132a1 package: bump socket.io-client 2015-01-18 18:52:06 +00:00
Guillermo Rauch
f7f83bc09f package: bump engine.io 2015-01-18 18:51:27 +00:00
Guillermo Rauch
b8ded0d725 Merge pull request #1903 from rase-/add/volatile-tests
Added tests for volatile
2015-01-17 12:23:06 +00:00
Guillermo Rauch
086ccd2708 Merge pull request #1938 from fay-jai/license
update license with up-to-date year range
2015-01-17 12:22:11 +00:00
Guillermo Rauch
864857cb6f Merge pull request #1939 from rase-/add/test-for-emit-after-server-restart
Add test for reconnection after server restarts
2015-01-17 12:21:53 +00:00
Guillermo Rauch
e5a7e422f9 Merge pull request #1943 from eychu/patch-1
Add space in error message
2015-01-17 12:21:38 +00:00
Alexey Chuvashov
f5b75151bd Add space in error message 2015-01-15 01:24:19 +03:00
Tony Kovanen
0523b655da Add test for reconnection after server restarts 2015-01-14 17:22:50 +02:00
Willson Mock
d9415a38e4 update license with up-to-date year range 2015-01-11 00:11:55 -05:00
Roman Shtylman
ca82c09bf2 fix leaving unknown rooms
close #1670
2015-01-10 14:58:50 -08:00
Roman Shtylman
b9aaa1607c Merge pull request #1922 from smart--petea/patch-1
Update Readme.md
2015-01-10 14:48:59 -08:00
Roman Shtylman
d1304c5d82 Merge pull request #1926 from coderaiser/patch-1
package: debug v2.1.0
2015-01-10 14:33:21 -08:00
Guillermo Rauch
bd479a9cd6 Merge pull request #1936 from drewblaisdell/master
Allow null or undefined origins when allowed origins is a function
2015-01-09 16:36:38 -08:00
Drew Blaisdell
a116d7765a Allow null or undefined origins when allowed origins is a function
Requests without an Origin header previously caused an exception to be thrown if the allowed origins passed to the constructor was set to a dynamic function. Omitted origins are now set to an asterisk and passed properly to the origins function.

A test for this case is included in this commit.
2015-01-09 16:30:08 -08:00
Guillermo Rauch
1c6620d564 everything is fixed 2015-01-09 16:25:42 -08:00
Guillermo Rauch
dba462e6da fix tests on 0.11 2015-01-09 16:24:24 -08:00
Guillermo Rauch
19c4422361 package: fix npm test to run on windows 2015-01-09 13:57:45 -08:00
coderaiser
8242dd01ef package: debug v2.1.0 2014-12-26 14:16:27 +02:00
Badarau Petru
17960ed038 Update Readme.md
underylings to underlyings
2014-12-22 07:17:01 +02:00
Tony Kovanen
d9996f0470 Added tests for volatile 2014-12-08 11:19:49 +02:00
Guillermo Rauch
24d06d76dd Release 1.2.1 2014-11-21 04:59:14 +01:00
Guillermo Rauch
4e4bbf918e fix protocol violations and improve error handling (fixes #1880) 2014-11-21 04:16:37 +01:00
Guillermo Rauch
b49f5c82f2 syntax 2014-11-21 04:15:42 +01:00
Guillermo Rauch
5bd67195de Merge branch 'master' of github.com:Automattic/socket.io 2014-11-21 02:57:35 +01:00
Guillermo Rauch
73fe547956 package: bump engine.io for websocket leak fix 2014-11-21 02:56:28 +01:00
Guillermo Rauch
973e6cc982 Merge pull request #1813 from ogwiz2/patch-1
Made comments more consistent
2014-11-12 10:04:09 +01:00
Guillermo Rauch
4a0091b25a Release 1.2.0 2014-10-27 15:54:57 -07:00
Guillermo Rauch
a1bf85b57f package: bump socket.io-parser 2014-10-27 11:52:09 -07:00
Guillermo Rauch
62ad812ee5 package: use latest socket.io-client 2014-10-27 11:51:03 -07:00
Guillermo Rauch
9ae8ed6929 package: bump adapter 2014-10-27 11:46:44 -07:00
Guillermo Rauch
4a11c16cc2 package: bump socket.io-client 2014-10-27 11:09:44 -07:00
Guillermo Rauch
b88a758857 package: bump engine.io 2014-10-27 07:47:51 -07:00
Guillermo Rauch
3352d1d726 Merge branch 'master' of github.com:Automattic/socket.io 2014-10-13 08:52:46 -07:00
Guillermo Rauch
e68557fab6 downloads badge 2014-10-13 08:52:36 -07:00
Alex Jeng
136fe960b7 Made comments more consistent 2014-10-05 22:10:13 -07:00
Tony Kovanen
da358084f0 Merge pull request #1773 from AjayMT/master
Fix usage example for Server#close.
2014-09-26 01:13:18 +03:00
Tony Kovanen
1b4f6a5324 Merge pull request #1777 from akamensky/dynamic-cors
Dynamic cors
2014-09-22 13:38:14 -06:00
Tony Kovanen
99346eddc5 Merge pull request #1788 from jamesanthonyferguson/patch-1
Change grammar issues in the chat/README.md
2014-09-22 12:42:59 -06:00
Tony Kovanen
051ffa0440 Merge pull request #1626 from thanpolas/patch-1
http.Server is a constructor
2014-09-22 12:42:10 -06:00
Tony Kovanen
fa4fa3365a Merge pull request #1690 from rase-/fix/resource-option-bc
Fix resource option BC with the set function
2014-09-22 12:27:35 -06:00
Tony Kovanen
bafa184c6b Merge pull request #1792 from rase-/add/autopruning-test
Add room autopruning test
2014-09-22 12:25:23 -06:00
Tony Kovanen
e3149d5833 Bump adapter version. 2014-09-20 11:12:58 -06:00
Tony Kovanen
ae9d5277a9 Add test to check that empty rooms are autopruned. 2014-09-20 11:12:26 -06:00
James Ferguson
2e440722a6 Change grammar issues in the chat/README.md
Added a few periods and commas which were missing. Also added the word each to clarify how multiple users each enter a unique username.
Very minor edit. No source code changed.
2014-09-18 21:41:28 -07:00
Tony Kovanen
3fe6d4e8ec Merge pull request #1784 from matthewcanty/patch-1
Change "there're" to "there are"
2014-09-17 07:41:46 -06:00
Matthew Canty
3b93c1c562 Change "there're" to "there are"
Not a commonly used contraction and looks a bit odd.
2014-09-17 14:01:01 +01:00
akamensky
e89f82a9b0 Added Server#origins(v:Function) description for dynamic CORS 2014-09-12 11:32:20 +08:00
akamensky
1b90ae2587 Added test coverage for Server#origins(function) for dynamic CORS 2014-09-12 11:13:51 +08:00
akamensky
9658e32e7a Added optional Server#origins(function) for dynamic CORS 2014-09-12 10:53:14 +08:00
Tony Kovanen
99d76664aa Merge pull request #1766 from BrianGeppert/master
package: fix main file for example application 'chat'.
2014-09-11 18:05:58 +03:00
Ajay MT
23eefa527a Fix usage example for Server#close. 2014-09-10 18:11:56 +05:30
Brian Geppert
b49b35b26f package: fix main file for example application 'chat'. 2014-09-04 12:10:43 -05:00
Guillermo Rauch
16483375a7 Release 1.1.0 2014-09-04 12:06:06 +02:00
Guillermo Rauch
ec305bd8df examples: minor fix of escaping 2014-09-04 11:44:02 +02:00
Guillermo Rauch
af07a1c649 package: bump engine.io 2014-09-04 01:57:58 +02:00
Tony Kovanen
5863903d44 Merge pull request #1729 from anupbishnoi/patch-1
Take "" and "/" as equivalent namespaces on server
2014-08-20 11:27:46 +03:00
Anup Bishnoi
f56d4acce6 testing for equivalence of namespaces starting with / or without 2014-08-19 22:19:50 +00:00
Anup Bishnoi
8ea37b7351 Update index.js 2014-08-19 16:17:45 -04:00
Anup Bishnoi
b3cb18d910 Added relevant tests
"" and "/" namespaces are checked for equivalence on server and client
2014-08-18 22:47:06 -04:00
Anup Bishnoi
0e41561d56 Take "" and "/" as equivalent namespaces on server
On server, `.of(name)` should use the same key in `.nsps` object for "" and "/"

Important to use `String(name)` and `===` to keep out keys that don't cast to ""
2014-08-18 22:38:47 -04:00
Guillermo Rauch
83709e9487 Merge pull request #1714 from PeterDaveHello/patch-2
Use svg instead of png to get better image quality
2014-08-12 15:47:12 -07:00
Guillermo Rauch
6f4051aaa7 Merge pull request #1713 from PeterDaveHello/patch-1
make CI build faster
2014-08-12 15:45:58 -07:00
Peter Dave Hello
87bf6910b5 Use svg instead of png to get better image quality 2014-08-12 10:56:04 +08:00
Peter Dave Hello
8946b4ed4c make CI build faster 2014-08-12 10:51:01 +08:00
Guillermo Rauch
a40068b5f3 Merge pull request #1688 from fdellabetta/server_side_namespace
client cannot connect to non-existing namespaces
2014-08-01 13:45:32 +01:00
Guillermo Rauch
9e29ec9b2b Merge pull request #1700 from rase-/fix/rooms
Fix splice arguments and `socket.rooms` value update in `socket.leaveAll`
2014-08-01 13:45:01 +01:00
Tony Kovanen
624e7cb14f Fix splice arguments and socket.rooms value update in socket.leaveAll.
Hat tip @Marreck
2014-08-01 13:20:18 +02:00
Tony Kovanen
b4954d767a Take the instance stored path value into account when attaching to eio if no option specified to attach directly 2014-07-23 19:58:44 +03:00
Filippo Della Betta
f6eb53f5e1 client cannot connect to non-existing namespaces 2014-07-22 13:58:13 +02:00
Guillermo Rauch
9c80317574 Merge pull request #1685 from rase-/fix/remote-address-in-handshake-obj
Fix remote address in handshake obj
2014-07-18 19:47:26 -07:00
Tony Kovanen
d163d891ef Bump engine.io version to get the cached IP address 2014-07-19 04:49:51 +03:00
Tony Kovanen
54726105cb Fixed handshake object address property and made the test case more strict. 2014-07-19 04:43:03 +03:00
Guillermo Rauch
3d9e52cf93 Merge branch 'master' of github.com:Automattic/socket.io 2014-07-17 12:20:17 -07:00
Guillermo Rauch
ad74f2ff88 package: bump engine.io 2014-07-17 12:17:46 -07:00
Guillermo Rauch
cf1c1273b3 Merge pull request #1682 from kevin-roark/fix/disconnect-connectbuffer-crash
Fixed the failing test where server crashes on disconnect involving connectBuffer
2014-07-16 10:58:54 -07:00
Kevin Roark
1f43c4abb5 Fixed the failing test where server crashes on disconnect involving connectBuffer
Source of bug: after connection to nsp '/', the socket's connectBuffer
was being deleted. On attempt to reconnect to a different namespace,
the connect buffer was deleted and we attempted to push to it. Instead
of the deleting the connect buffer, it is now emptied.
2014-07-16 08:35:16 -07:00
Guillermo Rauch
d6e6e8a2f8 Merge pull request #1673 from bryanburgers/patch-1
Fix repo in package.json
2014-07-15 18:25:59 -07:00
Guillermo Rauch
fbd36b613d npmignore: ignore .gitignore (fixes #1607) 2014-07-15 10:55:34 -07:00
Guillermo Rauch
480b1a05bd test: added failing case for socket.disconnect and nsps 2014-07-15 10:52:23 -07:00
Bryan Burgers
ef729b72b4 Fix repo in package.json 2014-07-09 07:28:45 -05:00
Thanasis Polychronakis
63e197083b update README http ctor to createServer() 2014-07-01 10:41:53 +03:00
Guillermo Rauch
968e94e42b Merge pull request #1655 from ysmood/fix_etag_header
We should use the standard http protocol to handler the etag header
2014-06-30 23:32:23 -07:00
Guillermo Rauch
c18ed5fd4d Merge pull request #1646 from narcisoguillen/close_sio
Close sio
2014-06-30 19:10:26 -07:00
Narciso Guillen
1f7da938bd Improve Close documentation 2014-06-30 15:57:21 -05:00
Narciso Guillen
4b89bce182 use ephemeral ports 2014-06-30 15:49:08 -05:00
Yad Smood
8c19eef07a fix: We should use the standard http protocol to handler the etag
header.
2014-06-29 21:42:57 +08:00
Guillermo Rauch
662b30669b Merge pull request #1653 from acusti/patch-1
Override default browser font-family for inputs
2014-06-28 10:55:22 -07:00
Andrew Patton
001373ee17 Override default browser font-family for inputs
For consistent typography, explicitly declare font-family stack for `input` in addition to `html` (in Chrome and Safari on mac, the input will otherwise use default font for such elements, like Lucida Grande)
2014-06-28 13:14:33 -04:00
Guillermo Rauch
246f3bb5c3 Merge pull request #1648 from kevin-roark/update/has-binary-data
update has-binary-data to 1.0.3
2014-06-23 20:20:39 -07:00
Kevin Roark
68d06ec94c update has-binary-data to 1.0.3 2014-06-23 20:19:26 -07:00
Narciso Guillen
a1feca1bd3 Add close specs 2014-06-23 21:03:31 -05:00
Narciso Guillen
968105a239 Add ability to stop the http server even if not created inside socket.io 2014-06-23 21:03:12 -05:00
Narciso Guillen
2e8e26613a Update README 2014-06-23 20:02:39 -05:00
Narciso Guillen
fbdb94d146 make sure server gets close 2014-06-23 19:55:02 -05:00
Tony Kovanen
55572122f3 Merge pull request #1642 from rase-/add/test
Duplicate events test for `reconnect_failed`
2014-06-21 17:28:37 +03:00
Tony Kovanen
a1170a3aa6 Bump client 2014-06-21 17:26:55 +03:00
Tony Kovanen
0954301d7e Add test case for checking that reconnect_failed is fired only once upon failure 2014-06-21 17:14:15 +03:00
Guillermo Rauch
328a9df8eb package: bump socket.io-parser for component-emitter dep fix
cc @davglass @reid
2014-06-20 16:57:54 -07:00
Guillermo Rauch
d99e30fca7 Release 1.0.6 2014-06-19 14:57:50 -07:00
Guillermo Rauch
561dd6fd79 package: bump engine.io for utf8 fix (fixes #1622) 2014-06-19 14:51:37 -07:00
Guillermo Rauch
e9e2a91cea package: bump socket.io-client 2014-06-19 08:05:38 -07:00
Guillermo Rauch
8a3a111a7f Merge pull request #1635 from rase-/add/test
Test for duplicate events on manual reconnect
2014-06-18 15:54:23 -07:00
Tony Kovanen
bd87e4dc35 Bump socket.io-client to latest commit so that duplicate events test passes 2014-06-19 01:52:34 +03:00
Tony Kovanen
71c253e992 Added test for duplicate events after manual reconnects 2014-06-19 01:49:00 +03:00
Guillermo Rauch
a5cf4f57a0 Release 1.0.5 2014-06-17 18:14:44 -07:00
Guillermo Rauch
a079cbc7f9 client: fixes #1632 2014-06-17 18:07:30 -07:00
Guillermo Rauch
14a9fdb64f package: bump engine.io 2014-06-16 08:36:01 -07:00
Thanasis Polychronakis
55fb100fc0 http.Server is a constructor
...and thus requires the `new` keyword
2014-06-14 13:52:36 +03:00
Guillermo Rauch
6159df3937 fixed client 2014-06-13 13:04:50 -07:00
Guillermo Rauch
6f7bab5dfd Merge pull request #1578 from kevin-roark/add/emit-buffer-test
added the client emit-buffer test
2014-06-13 10:10:40 -07:00
Guillermo Rauch
7d2b44e176 index: fix typo [thanks @yanatan16] 2014-06-11 10:42:48 -07:00
Tony Kovanen
0b5fdf995a Merge pull request #1603 from nkzawa/patch-2
Add removeListener to blacklisted events
2014-06-08 14:40:25 +03:00
Naoyuki Kanezawa
a66bea5b33 add removeListener to blacklisted events 2014-06-08 20:34:50 +09:00
Guillermo Rauch
a1a88aaaaf Merge pull request #1600 from poldridge/master
Update index.js
2014-06-06 22:36:19 -07:00
poldridge
3f817c3a18 Update index.js
Added missing hasOwnProperty check. socket.io breaks without it when Object.prototype has been extended.
2014-06-06 22:08:58 -07:00
Guillermo Rauch
99bbd74d14 Merge pull request #1582 from kevin-roark/add/clearer-example-instructions
Add/clearer example instructions
2014-06-02 20:44:34 -07:00
Kevin Roark
398511ddee Merge branch 'upstream' into add/clearer-example-instructions 2014-06-02 20:28:42 -07:00
Kevin Roark
fdf7937815 clearer instructions to install chat example 2014-06-02 20:28:19 -07:00
Guillermo Rauch
475909e642 Release 1.0.4 2014-06-02 20:08:33 -07:00
Guillermo Rauch
95acec8b94 package: bump socket.io-client 2014-06-02 20:07:07 -07:00
Kevin Roark
5812ddf2b0 added the client emit-buffer test 2014-06-01 23:20:42 -07:00
Guillermo Rauch
1bbc3951bd Release 1.0.3 2014-05-31 18:34:50 -07:00
Guillermo Rauch
039eed2c2a package: bump socket.io-client 2014-05-31 09:53:25 -07:00
Guillermo Rauch
6de022b180 Merge pull request #1565 from kevin-roark/add/binary-ack
Add/binary ack
2014-05-31 09:50:19 -07:00
Guillermo Rauch
a06331d29f travis fix 2014-05-30 21:37:22 -07:00
Guillermo Rauch
e639685370 fix travis 2014-05-30 21:23:55 -07:00
Guillermo Rauch
1f2e681ce2 package: bump socket.io-parser for binary ack fix 2014-05-30 21:11:57 -07:00
Kevin Roark
397944fcbe big file tests 2014-05-30 20:40:44 -07:00
Kevin Roark
27dada65b9 distinction between ACK and BINARY_ACK 2014-05-30 18:42:23 -07:00
Guillermo Rauch
99f1ac9aae Merge pull request #1563 from rase-/fix/no-disconnect-fired-for-nsp
Fix namespace iterator in disconnect
2014-05-30 16:40:59 -07:00
Tony Kovanen
ee8d0fbae0 Fix namespace iterator in disconnect 2014-05-31 02:25:28 +03:00
Guillermo Rauch
8e08a6d419 Merge pull request #1562 from rase-/add/utf8-tests
Add test case for emitting multibyte chars
2014-05-30 15:48:34 -07:00
Tony Kovanen
318ae87f50 Add test case for emitting multibyte chars 2014-05-31 01:45:31 +03:00
Guillermo Rauch
2c1b61148d Merge branch 'master' of github.com:automattic/socket.io 2014-05-30 14:14:12 -07:00
Guillermo Rauch
507054c0a8 package: bump engine.io for utf8 binary fix 2014-05-30 14:09:54 -07:00
Tony Kovanen
dfceb006d7 Merge pull request #1554 from grant/master
Fix xss vulnerability in example chat app
2014-05-30 12:15:12 +03:00
Grant Timmerman
4d83456f74 Fix xss vulnerability in example chat app 2014-05-30 02:03:33 -07:00
Tony Kovanen
201aad83b1 Merge pull request #1540 from grant/master
Make chat example wrap long words (no overflow)
2014-05-30 12:02:15 +03:00
Grant Timmerman
72eb61d01f Make chat example wrap long words (no overflow) 2014-05-30 01:44:27 -07:00
Tony Kovanen
163a2a696e Merge pull request #1543 from mohnish/patch-1
Remove obsolete message from README file
2014-05-29 21:33:36 +03:00
Guillermo Rauch
199a479ebc Merge pull request #1545 from overra/patch-1
Use cleanInput() on incoming messages
2014-05-28 20:47:20 -07:00
Guillermo Rauch
d383ff9662 Merge pull request #1546 from hiddenmin/patch-1
Update Readme.md
2014-05-28 19:42:39 -07:00
Amin Cheloh
416b550189 Update Readme.md
socket.io-adapter link
2014-05-29 09:41:37 +07:00
Adam Snodgrass
536b338a01 Use cleanInput() on incoming messages
This prevents XSS if one were to send messages using socket.io from the console.
2014-05-28 20:35:24 -05:00
Mohnish Thallavajhula
a06ae10895 Remove obsolete message from README file 2014-05-28 17:10:50 -07:00
Guillermo Rauch
35a85084b1 Release 1.0.2 2014-05-28 13:24:59 -07:00
Guillermo Rauch
0c2b44a846 package: bump parser for windows fix 2014-05-28 13:23:51 -07:00
Guillermo Rauch
0f6ee2dbd9 travis 2014-05-28 12:56:10 -07:00
Guillermo Rauch
68ac0d6d24 Release 1.0.1 2014-05-28 10:32:31 -07:00
Guillermo Rauch
00ef9ca652 Release 1.0.0 2014-05-28 10:19:24 -07:00
Guillermo Rauch
2febbce87d Merge pull request #1530 from kevin-roark/update/has-binary-data
bump has-binary-data
2014-05-24 15:19:48 -07:00
Kevin Roark
31c45862cb bump has-binary-data 2014-05-24 14:14:59 -05:00
Guillermo Rauch
809e2bc3f8 Merge pull request #1529 from rase-/add/bc
Added socket.handshake BC object
2014-05-24 11:08:00 -07:00
Tony Kovanen
10adcb089e Added socket.handshake BC object 2014-05-24 17:02:47 +03:00
Guillermo Rauch
5bc75ea944 Release 1.0.0-pre5 2014-05-22 09:35:32 -07:00
Guillermo Rauch
cd4f6ad5e9 package: bump socket.io-client for parser fixes 2014-05-22 09:32:42 -07:00
Guillermo Rauch
54e6c79014 package: bump engine.io 2014-05-22 09:25:58 -07:00
Guillermo Rauch
237b234cab Release 1.0.0-pre4 2014-05-19 16:02:54 -07:00
Guillermo Rauch
547440605d package: bump client 2014-05-19 16:02:31 -07:00
Guillermo Rauch
d763c8b6ea Release 1.0.0-pre3 2014-05-17 15:40:40 -07:00
Guillermo Rauch
5d210ac46c package: bump parser 2014-05-17 14:02:57 -07:00
Guillermo Rauch
ea89e520bc package: bump engine.io 2014-05-16 16:57:41 -07:00
Guillermo Rauch
c8bf064b10 Merge pull request #1513 from hallucynogenyc/patch-1
Update for new npm check
2014-05-06 10:15:33 -04:00
hallucynogenyc
08fe191211 Update for new npm check
Npm will now throw a warning when installing a package:

npm WARN package.json socket.io@1.0.0-pre2 No repository field.

If the repository field is not present.
2014-05-06 16:14:50 +02:00
Guillermo Rauch
0842729c1f test: temporarily removing parser test 2014-04-28 11:16:59 -07:00
Guillermo Rauch
9720c76d10 Release 1.0.0-pre2 2014-04-27 19:40:33 -07:00
Guillermo Rauch
0f127d2b7d package: bump engine.io 2014-04-27 19:23:07 -07:00
Guillermo Rauch
e87e9e18e1 package: bump parser 2014-04-27 18:54:53 -07:00
Guillermo Rauch
46351d38b8 Merge pull request #1489 from kevin-roark/add/protocol-check
added test that server and client using same protocol
2014-04-14 13:11:04 -07:00
Kevin Roark
ce68fb3105 Merge branch 'upstream' into add/protocol-check 2014-04-14 12:43:01 -04:00
Guillermo Rauch
94905500e4 Merge pull request #1467 from rase-/add/set-backwards-compatibility
Added backwards compatible settability of engine.io maxHttpBufferSize
2014-04-13 12:25:36 -07:00
Tony Kovanen
f830899e39 Added backwards compatible settability of engine.io maxHttpBufferSize
Updated readme
2014-04-12 12:02:52 +03:00
Guillermo Rauch
3444f017bc Merge pull request #1492 from kevin-roark/add/query-test
Added a test to check access to client query params
2014-04-11 10:57:04 -07:00
Kevin Roark
0588dc0fc4 Added a test to check access to client query params
It fails with the current upstream client! There is a pending PR to
make this test pass though.
2014-04-11 13:19:19 -04:00
Guillermo Rauch
57425ab1dd Merge pull request #1485 from rase-/add/origins
Added support for setting allowed origins
2014-04-11 09:46:37 -07:00
Tony Kovanen
463d7a16a1 Moved the origins checking callback outside the origins getter/setter function. 2014-04-11 19:39:10 +03:00
Tony Kovanen
5d74847123 Updated README to include origins 2014-04-11 01:29:37 +03:00
Kevin Roark
f8b4d87331 added test that server and client using same protocol 2014-04-10 14:45:32 -04:00
Tony Kovanen
e9928b2b1d Switched to async allowRequest callback in engine.io for setting the allowed origins 2014-04-10 21:02:20 +03:00
Tony Kovanen
d33553a4bd Added support for setting allowed origins 2014-04-09 22:34:53 +03:00
Guillermo Rauch
45a98970d7 added information about logging 2014-03-28 11:51:54 -03:00
Guillermo Rauch
0b4e4f6a67 Merge pull request #1464 from rase-/add/set-backwards-compatibility
Set function for BC
2014-03-25 20:09:16 -03:00
Tony Kovanen
656047536a The set function in server can be used to set some attributes for backwards compatibility 2014-03-26 00:04:22 +02:00
Guillermo Rauch
97b7ab4fe2 Merge pull request #1462 from nicolagreco/patch-1
Mistake in callback call 'done' instead of 'next' in docs
2014-03-24 22:38:02 -03:00
Nicola Greco
6a435ce677 Mistake in callback call 'done' instead of 'next' in docs 2014-03-25 01:02:46 +00:00
Guillermo Rauch
6aa553b211 Merge branch 'master' of github.com:LearnBoost/socket.io 2014-03-24 14:44:00 -03:00
Guillermo Rauch
024af23b2c package: bump client 2014-03-24 14:43:37 -03:00
Guillermo Rauch
b50d9f8f5d Merge pull request #1443 from kevin-roark/add/simple-tests
added some new tests, including binary with acks
2014-03-24 14:21:19 -03:00
Kevin Roark
874c194210 Merge branch 'upstream' into add/simple-tests
Conflicts:
	package.json
2014-03-24 13:03:43 -04:00
Guillermo Rauch
f537560bcc package: bump socket.io-parser 2014-03-18 18:28:49 -03:00
Guillermo Rauch
7197d6a29d rebuild 2014-03-18 17:16:38 -03:00
Guillermo Rauch
8dba96511d package: rollback socket.io-parser to fix acks 2014-03-18 16:45:48 -03:00
Guillermo Rauch
f8d1d33dfa Merge branch 'master' of github.com:LearnBoost/socket.io
Conflicts:
	package.json
2014-03-18 16:34:49 -03:00
Guillermo Rauch
736106a9e7 package: bump engine.io 2014-03-18 16:31:22 -03:00
Guillermo Rauch
f5a8ac293a Merge pull request #1452 from kevin-roark/update/parser-dependency
updated parser dependency
2014-03-15 19:35:35 -02:00
Kevin Roark
afc83ad65a Merge branch 'upstream' into add/simple-tests
Conflicts:
	package.json
2014-03-15 17:32:27 -04:00
Kevin Roark
b5f90923a2 updated parser dependency 2014-03-15 17:30:47 -04:00
Guillermo Rauch
c574f5f959 Merge pull request #1451 from elisee/patch-1
Fix // … to be /* … */ in README.md
2014-03-15 17:57:01 -02:00
elisee
ba339cc460 Fix // … to be /* … */ 2014-03-15 20:25:00 +01:00
Guillermo Rauch
aee4dd9a6d package: bump expect.js 2014-03-15 10:39:21 -03:00
Guillermo Rauch
ad86129437 Release 1.0.0-pre 2014-03-15 10:36:51 -03:00
Guillermo Rauch
c8eda77da3 package: fix versions 2014-03-15 10:33:02 -03:00
Guillermo Rauch
a4fabba781 Readme: tweak 2014-03-15 10:23:25 -03:00
Guillermo Rauch
c19d2692e2 package: bump engine.io 2014-03-14 19:39:10 -03:00
Guillermo Rauch
36ad8e87eb package: bump socket.io-adapter 2014-03-14 15:05:43 -03:00
Kevin Roark
7d4aa670ad bumped parser dependency 2014-03-13 10:49:31 -04:00
Kevin Roark
620f94a007 Merge branch 'upstream' into add/simple-tests
Conflicts:
	package.json
2014-03-12 20:33:01 -04:00
Guillermo Rauch
f808c377b0 package: bump engine.io 2014-03-12 15:47:29 -03:00
Guillermo Rauch
41c5b37ac7 bump engine.io 2014-03-11 11:53:42 -03:00
Guillermo Rauch
c972153669 bump client 2014-03-10 20:09:56 -03:00
Kevin Roark
4823d20cf1 Merge branch 'upstream' into add/simple-tests
Conflicts:
	package.json
2014-03-08 20:58:41 -05:00
Guillermo Rauch
44a79f9cee server: make Server#adapter work after construction 2014-03-07 18:33:36 -03:00
Guillermo Rauch
81e8a0c3a5 added support for volatile packets 2014-03-07 04:09:43 -06:00
Guillermo Rauch
adffabeee3 style 2014-03-07 03:41:22 -06:00
Guillermo Rauch
79dd06a767 socket: fix flags api state 2014-03-07 03:32:27 -06:00
Guillermo Rauch
93df3c47cc Readme; document Socket#id 2014-03-07 00:43:40 -06:00
Guillermo Rauch
2a3a5a01a2 Readme: document Socket#join and Socket#leave 2014-03-07 00:39:39 -06:00
Guillermo Rauch
dd8745ece2 Readme: document to multiple-call situation 2014-03-07 00:33:54 -06:00
Guillermo Rauch
4615e932c1 Readme: document Socket#to and Socket#in 2014-03-07 00:33:05 -06:00
Guillermo Rauch
7e96f0a1ff Readme: document Socket#emit 2014-03-07 00:31:01 -06:00
Guillermo Rauch
8df80ee91c move adapter out 2014-03-06 22:49:38 -06:00
Kevin Roark
612d35194f updated parser dependency 2014-03-06 18:41:43 -05:00
Kevin Roark
a5ff1d854e added some new tests, including binary with acks 2014-03-06 16:58:21 -05:00
Guillermo Rauch
0c8ed9547c package: introduce proper engine.io version 2014-03-06 12:11:46 -08:00
Guillermo Rauch
8104694fdf package: bump parser 2014-03-04 23:29:22 -08:00
Guillermo Rauch
6be582db3d package: bump client 2014-03-04 00:25:24 -08:00
Guillermo Rauch
12733a8759 test: fix global leakage 2014-03-03 14:22:51 -08:00
Guillermo Rauch
5e28161322 Merge pull request #1440 from kevin-roark/add/binary-broadcasting
Added binary support to broadcasting of events
2014-03-02 20:53:37 -08:00
Kevin Roark
c2bf0ea700 Added binary support to broadcasting of events
lib/namespace.js previously was not considering whether an event had
binary data and was giving all events parser.EVENT type -- now it uses
the has-binary-data module to set the event type appropriately.

Then, after this fix there was a problem with lib/adapter.js -- because
socket.io-parser modifies the packet object in its encoding, the sockets
after the 1st in a broadcast were not getting the correct data. To fix
this, the data is encoded once in adapter, and then the encoded data
is passed to each of the sockets.

lib/socket.js and lib/client.js were updated to allow for the above. The
.packet method of each now takes an optional second "preEncoded" parameter
-- if this is true, then client skips the encoding and just writes the
packet argument directly to engine.

test/socket.io.js was updated to add two new tests that test
multi-messaging of events with binary data.
2014-03-02 22:15:16 -05:00
Guillermo Rauch
571f3a663c package: bump socket.io-client for new build 2014-03-01 10:18:33 -08:00
Guillermo Rauch
d293e3be7c version badge 2014-03-01 09:00:34 -08:00
Guillermo Rauch
e2a5e4b1f2 package: adjust socket.io-client 2014-03-01 08:55:50 -08:00
Guillermo Rauch
7b4c8c67c2 package: bump parser 2014-03-01 08:55:05 -08:00
Guillermo Rauch
e280e17094 Merge pull request #1432 from kevin-roark/add/better-binary-events
Updated protocol-facing code for new binary protocol
2014-03-01 08:53:49 -08:00
Guillermo Rauch
947d7b4ea5 Merge pull request #1437 from keyosk/master
Update chat example
2014-03-01 08:21:53 -08:00
Cody Massin
318d62e5ad When displaying leave and join messages show a message with an updated participants count.
Signed-off-by: Cody Massin <keyosk@gmail.com>
2014-03-01 00:20:51 -08:00
Kevin Roark
fc34c7d7a4 Updated protocol-facing code to reflect newest parser
Socket.io-parser now has a class-based Encoder and Decoder scheme,
so client.js was changed appropriately.

The main difference is that most of the logic for interpreting packets
is now isolated to parser, and client receives a 'decoded' event when
parser has a reconstructed packet ready to go.
2014-02-27 17:54:02 -05:00
Kevin Roark
449c28ce1c Updated protocol-facing code for new binary protocol
This is a squash of four boring commits. The gist is that client.js
encoding and decoding stuff was updated to take an array of encoded packets
to write, and to handle sequences of binary packets to decode. There was
also merging done with upstream. All tests are passing.
2014-02-26 13:45:47 -05:00
Guillermo Rauch
3faca287a5 chat: forward 3000 2014-02-24 16:54:48 -08:00
Guillermo Rauch
266278d14c prettify 2014-02-24 16:46:23 -08:00
Guillermo Rauch
d286ba2064 rename app->index 2014-02-24 16:28:04 -08:00
Guillermo Rauch
d4ec1b6ff0 use shorthand io call 2014-02-24 16:27:46 -08:00
Guillermo Rauch
49f11f9cf5 README: move to index 2014-02-24 16:27:37 -08:00
Guillermo Rauch
05fd23ddda Merge pull request #1430 from kevin-roark/fix/has-binary-dependency
fixed the has-binary-data dependency
2014-02-21 14:19:35 -08:00
Kevin Roark
d21b1f36a3 fixed the has-binary-data dependency 2014-02-21 17:10:53 -05:00
Guillermo Rauch
573b32cc7d package: bump client 2014-02-21 13:32:12 -08:00
Guillermo Rauch
16d1afc7fc Merge pull request #1426 from brishin/binary
Binary
2014-02-21 13:02:26 -08:00
Kevin Roark
675830e726 updated socket.io-client dependency 2014-02-20 17:21:39 -05:00
Kevin Roark
b1c971507b updated engine and -parser dependencies 2014-02-19 19:54:31 -05:00
Kevin Roark
8c3ca99e7c merged binary with upstream's new chat app 2014-02-19 18:03:36 -05:00
Kevin Roark
beab053123 anonymous function style correct 2014-02-19 17:57:59 -05:00
Kevin Roark
745ee03102 Added binary support to socket.io
This is a squash of about 25 commits, and here is a summary:

adamreis added initial binary test with the doge image.

kevin-roark updated binary tests and wrote some binary encoding protocol.

kevin-roark replaced the custom binary encoding with msgpack because we
have to handle arbitrary json that contains binary.

adamreis added some 'crazy' tests for emmiting and receiving events with
several types of data.

kevin-roark updated client.js to use socket.io-protocol's async encoding

Did a bunch of upstream merging.
2014-02-19 13:46:39 -05:00
Guillermo Rauch
69de792c03 Merge pull request #1427 from grant/upstream
Example: Chat -- Welcome message is always on top. Click now focuses input.
2014-02-18 21:14:53 -08:00
Grant Timmerman
d037d6cb38 Redefined input-focus click areas 2014-02-18 21:08:43 -08:00
Grant Timmerman
e06ea11c27 Welcome message is always on top. Click now focuses input. 2014-02-18 20:43:59 -08:00
Guillermo Rauch
daf8df8f5c Merge pull request #1425 from Aaron1011/node_11
Test on Node 0.11
2014-02-18 17:00:06 -08:00
Guillermo Rauch
ff2476c7a5 Merge pull request #1415 from grant/upstream
Example: Chat
2014-02-18 15:51:51 -08:00
Aaron Hill
fc77c0faca Test on Node 0.11 2014-02-18 12:31:07 -05:00
Grant Timmerman
e0a85a90aa Changed hash function after testing it on generated lists of random usernames 2014-02-17 13:50:43 -08:00
Grant Timmerman
3aa3213b13 Moved colors to client with hash fn, cleaned up app.js 2014-02-17 13:41:21 -08:00
Grant Timmerman
575ff2ecfc Fixed scrollbar height, fixed "undefined is typing", cleaned up fade effect 2014-02-16 12:12:02 -08:00
Grant Timmerman
852a9d34df Added X is typing functionality 2014-02-16 02:50:33 -08:00
Grant Timmerman
8a3781499d Reorganized event system, added log event, and changed formatting of chat 2014-02-16 01:05:41 -08:00
Grant Timmerman
ab60d166ac Added basic chatroom html 2014-02-15 23:31:00 -08:00
Grant Timmerman
f7838635a7 Added basic login page html for the new design 2014-02-15 23:00:20 -08:00
Grant Timmerman
cfb2a26d4f Updated package.json, added numUsers int on server, and used io shorthand notation 2014-02-14 21:29:08 -08:00
Guillermo Rauch
09cfb17731 *: remove unused client dir and symlink WARN 2014-02-14 10:34:24 -08:00
Guillermo Rauch
4cd4381b80 lib: bc compatibility 2014-02-13 14:12:59 -08:00
Guillermo Rauch
d65ec8d649 package: bump socket.io-client 2014-02-12 16:43:08 -08:00
Guillermo Rauch
e16ac61b82 package: bump socket.io-client 2014-02-12 16:28:35 -08:00
Guillermo Rauch
d17f5ce914 package: use a specific debug 2014-02-12 14:21:04 -08:00
Guillermo Rauch
1982afa481 package: serve a working socket.io-client 2014-02-12 14:16:32 -08:00
Grant Timmerman
1860aa41ee Removed extra lines, removed extra html 2014-02-11 21:46:59 -08:00
Grant Timmerman
598a140ad4 Update styles and formatting 2014-02-11 21:30:07 -08:00
Grant Timmerman
b8f6d4054c Added more friendly username input interface 2014-02-11 21:11:58 -08:00
Grant Timmerman
450d408ed6 Updated code style 2014-02-11 18:18:54 -08:00
Grant Timmerman
0023aed4c3 Changed tabs to spaces, removed screenshot, and updated README 2014-02-11 17:13:44 -08:00
Grant Timmerman
f99cdc9339 Updated package.json and Readme 2014-02-11 16:22:01 -08:00
Grant Timmerman
999b8bc387 Updated screenshot 2014-02-11 16:16:25 -08:00
Grant Timmerman
95d19e285c Removed external npm socket.io and now using local socket.io module 2014-02-11 13:09:46 -08:00
Grant Timmerman
9f8b1a2e1e Removed .gitignore in the chat example 2014-02-11 13:04:14 -08:00
Grant Timmerman
0c5e3eb5cf Merge branch 'master' of https://github.com/LearnBoost/socket.io into upstream 2014-02-11 13:00:20 -08:00
Grant Timmerman
eca3316620 Removed zuul yml 2014-02-11 12:59:17 -08:00
Grant Timmerman
29df46ae07 Added chat example 2014-02-11 12:48:55 -08:00
Guillermo Rauch
980b6a7c40 package: bump engine.io 2014-02-09 11:18:49 -08:00
Guillermo Rauch
c0393fce20 Merge pull request #1399 from lzyzsd/master
fix captcha in comment
2014-02-08 12:13:01 -08:00
Guillermo Rauch
093f5f7186 style 2014-02-08 12:12:47 -08:00
Guillermo Rauch
1f0f209d5e Merge pull request #1411 from get/server-client-file
change index to read build file from client
2014-02-08 12:11:57 -08:00
GK
fc61a37a6d change index to read build file from client 2014-02-08 11:18:07 -08:00
Guillermo Rauch
bf8761fb9b Merge pull request #1410 from brishin/test
Fix `npm test`
2014-02-07 15:24:45 -08:00
Brian Donghee Shin
3dcba2859c Fix npm test 2014-02-07 15:23:22 -08:00
Guillermo Rauch
c73e01485d Merge pull request #1403 from nkzawa/patch-1
middlewares of main namespace should be called first
2014-02-03 14:00:14 -08:00
Naoyuki Kanezawa
a3e1b0658f middlewares of main namespace should be called first 2014-02-04 04:00:24 +09:00
Guillermo Rauch
3cf6a0949b Merge pull request #1402 from gdi2290/patch-1
update copyright year
2014-02-03 06:52:08 -08:00
PatrickJS
a98b8abe97 update copyright year 2014-02-03 02:08:42 -08:00
Bruce Lee
db429864f6 fix captcha 2014-01-24 21:29:55 +08:00
Guillermo Rauch
7d5612eed7 Merge pull request #1395 from nulltask/patch-1
index: remove send dep
2014-01-15 10:22:41 -08:00
Seiya Konno
3efcd52674 index: remove send dep 2014-01-16 03:18:39 +09:00
Guillermo Rauch
8c0b60791c gitignore: added coverage 2014-01-10 11:47:55 -03:00
Guillermo Rauch
32fe383e70 package: remove send dependency 2014-01-10 11:47:24 -03:00
Guillermo Rauch
6305ebe8aa test: extend client serving tests 2014-01-10 11:47:04 -03:00
Guillermo Rauch
2b1a5afe6c index: simplify and speed up client serving 2014-01-10 11:46:45 -03:00
Guillermo Rauch
84bf735e4d add test coverage 2014-01-09 13:09:26 -03:00
Guillermo Rauch
142c73c9a1 index: remove SIO_COV env 2014-01-09 13:01:08 -03:00
Guillermo Rauch
07cf9395a0 package: bump engine.io 2014-01-02 08:00:04 -03:00
Guillermo Rauch
7ed789d381 package: remove ~ 2014-01-02 07:40:44 -03:00
Guillermo Rauch
48936231ea index: add support for string port numbers 2013-12-26 21:30:33 -03:00
Guillermo Rauch
2b5183b369 socket: revert onclose reason 2013-12-25 13:15:18 -03:00
Guillermo Rauch
14c71c2e72 socket: fix onclose reason 2013-12-25 13:13:02 -03:00
Guillermo Rauch
03db6a62e7 Readme: document use 2013-12-24 21:46:23 -03:00
Guillermo Rauch
83208b6e11 socket: add conn, client, request getters 2013-12-24 21:36:48 -03:00
Guillermo Rauch
036faa7d89 Readme: fix 2013-12-24 21:02:15 -03:00
Guillermo Rauch
7b2a71ac4f server: add listen 2013-12-24 20:49:21 -03:00
Guillermo Rauch
da844159d9 namespace: jshint friendly usage of reserved keyword for backwards-compatibility 2013-12-24 20:10:16 -03:00
Guillermo Rauch
baea55009b Readme: document usage with node 2013-12-24 20:08:47 -03:00
Guillermo Rauch
198efb0957 Readme: clarify engine.io options 2013-12-24 20:07:56 -03:00
Guillermo Rauch
f0e88265d6 Readme: added example of using 1.0 and koajs 2013-12-24 20:05:24 -03:00
Guillermo Rauch
760e1b5cda Readme: fix 2013-12-24 20:01:56 -03:00
Guillermo Rauch
ecca4ee738 use serveClient in favor of static for broader jshint compliance 2013-12-24 20:00:46 -03:00
Guillermo Rauch
d31aafa5fd socket: fix style 2013-12-24 19:56:10 -03:00
Guillermo Rauch
c545e3b963 lib: fix style 2013-12-24 19:56:01 -03:00
Guillermo Rauch
af66e5df4e client: fix style 2013-12-24 19:55:52 -03:00
Guillermo Rauch
a86994f693 index: syntax 2013-12-24 19:51:53 -03:00
Guillermo Rauch
430670f136 Merge pull request #1313 from tylermcginnis33/patch-1
Remove unnecessary comma from documentation
2013-12-09 08:27:02 -08:00
Guillermo Rauch
f65966d858 Merge pull request #1220 from balupton/patch-1
Removed 0.6 from travis (no longer supported by socket.io deps), added 0.10
2013-12-09 08:16:38 -08:00
Guillermo Rauch
2f3f54fb38 updated history 2013-12-09 13:03:37 -03:00
Guillermo Rauch
f0cc5aa834 package: bump engine.io 2013-12-09 13:00:02 -03:00
Guillermo Rauch
340281152f LICENSE: update 2013-12-09 00:28:51 -03:00
Guillermo Rauch
5f247ca38e package: remove optionalDependencies 2013-12-09 00:27:45 -03:00
Tyler McGinnis
cbabf0719e Remove unnecessary comma from documentation
A comma is used when there are three or more items in a series or you are separating two or more independent clauses.
2013-09-11 19:10:46 -07:00
Benjamin Arthur Lupton
6a11d09590 Removed 0.6 from travis, added 0.10
Also stringified the versions as they should be, as it is a yaml file so `0.10` becomes `0.1`, so for versions we should use strings - `"0.10"` stays `0.10`
2013-04-19 12:45:47 +10:00
Guillermo Rauch
64f6b244b6 Merge pull request #1189 from kaosdynamics/patch-1
Fix socket.io-client repository name
2013-03-19 16:35:17 -07:00
Kaos Dynamics
9ad1c2f3ac Fix socket.io-client repository name 2013-03-15 00:10:21 +01:00
Guillermo Rauch
242d02dee5 Merge pull request #1188 from MatthewMueller/master
fix install for 1.0
2013-03-13 17:57:50 -07:00
Matthew Mueller
3bd5455b1a Update package.json 2013-03-13 17:14:47 -07:00
Guillermo Rauch
7cc56a51a8 package: bumped engine.io 2013-02-22 10:55:26 -08:00
Guillermo Rauch
0d5200ed69 Readme: fix 2013-01-28 07:53:30 -08:00
Guillermo Rauch
abf798e2bb Readme: note 2013-01-28 07:51:55 -08:00
Guillermo Rauch
2102eb4bb3 Readme: added listen to examples 2013-01-28 07:51:14 -08:00
Guillermo Rauch
cef1583a64 test: middleware tests 2012-12-24 19:50:49 -03:00
Guillermo Rauch
5f843feb90 namespace: make sure not to fire connection if underlying client closed after next is called from a middleware 2012-12-24 19:50:25 -03:00
Guillermo Rauch
01a06b2b62 Makefile: change slow param 2012-12-24 19:50:13 -03:00
Guillermo Rauch
46d069b3cc test: added room tracking test 2012-12-24 15:07:23 -03:00
Guillermo Rauch
708af3f803 README: renamed joined to rooms 2012-12-24 15:07:13 -03:00
Guillermo Rauch
0881dfbdce socket: rename joined to rooms 2012-12-24 15:07:04 -03:00
Guillermo Rauch
c54011b6a1 Readme: document Namespace#connected 2012-12-23 23:25:17 -03:00
Guillermo Rauch
f605b365b4 test: added broadcasting / namespace emit tests 2012-12-23 23:24:35 -03:00
Guillermo Rauch
1ec766799f test: fix helper to take options 2012-12-23 23:24:19 -03:00
Guillermo Rauch
67f7d5749b adapter: initial memory impl 2012-12-23 23:23:05 -03:00
Guillermo Rauch
95d8e7531c socket: keep track of socket in connected hash 2012-12-23 23:21:50 -03:00
Guillermo Rauch
2e71357221 socket: added leaveAll 2012-12-23 23:21:37 -03:00
Guillermo Rauch
ef96e3b07f socket: added leave 2012-12-23 23:21:18 -03:00
Guillermo Rauch
6046c385b9 socket: added join 2012-12-23 23:21:07 -03:00
Guillermo Rauch
e8d11924aa socket: added in 2012-12-23 23:20:58 -03:00
Guillermo Rauch
eb0213882f socket: fix emit 2012-12-23 23:20:46 -03:00
Guillermo Rauch
de8e746959 socket: rooms and flags are now hashes 2012-12-23 23:20:26 -03:00
Guillermo Rauch
dc173330e5 socket: fix flags 2012-12-23 23:20:13 -03:00
Guillermo Rauch
d65635d212 socket: rename rooms to joined 2012-12-23 23:20:03 -03:00
Guillermo Rauch
dd0fd539e6 namespace: fix emit 2012-12-23 23:19:05 -03:00
Guillermo Rauch
5d4f90de47 namespace: make in able to track multiple rooms 2012-12-23 23:18:48 -03:00
Guillermo Rauch
59c8c34ceb namespace: fix flags 2012-12-23 23:18:38 -03:00
Guillermo Rauch
bcfec6df76 namespace: added connected hash 2012-12-23 23:18:26 -03:00
Guillermo Rauch
dbba592dfa namespace: implement own flags 2012-12-23 23:18:14 -03:00
Guillermo Rauch
d411dec5a4 index: rename adaptor to adapter 2012-12-23 23:18:01 -03:00
Guillermo Rauch
ab5a226f3e README: rename Adaptor to Adapter 2012-12-23 23:17:48 -03:00
Guillermo Rauch
fb857bd8b4 index: added Server#adaptor 2012-12-18 18:09:41 -03:00
Guillermo Rauch
2e5fdb65bd README: improved getters/setters docs and added Adaptor section 2012-12-18 18:07:30 -03:00
Guillermo Rauch
b4f12ea2f9 README: document Socket#rooms 2012-12-18 18:02:28 -03:00
Guillermo Rauch
902373196e socket: added broadcast flag 2012-12-18 17:28:14 -03:00
Guillermo Rauch
ae516a3f06 test: added args + callback events tests 2012-12-18 17:27:22 -03:00
Guillermo Rauch
ecf937c775 test: style 2012-12-18 17:27:09 -03:00
Guillermo Rauch
d1def44858 test: added event ack tests 2012-12-18 17:23:53 -03:00
Guillermo Rauch
381bc4260a socket: forgot this js oddity that you can access objects with strings or numbers 2012-12-18 17:20:20 -03:00
Guillermo Rauch
8a5cb03fcb socket: fix Socket#ack 2012-12-18 17:20:01 -03:00
Guillermo Rauch
22c91d8e49 socket: allow for falsy packet.id 2012-12-18 17:19:36 -03:00
Guillermo Rauch
bd37a9a34b socket: protect against __proto__ deletion 2012-12-18 17:00:44 -03:00
Guillermo Rauch
2fa98fb61a package: bumped socket.io-parser 2012-12-18 15:50:14 -03:00
Guillermo Rauch
6b3cdd7c9c test: added test for event emitting with send 2012-12-18 15:25:56 -03:00
Guillermo Rauch
3038ce5526 test: added event emitting test 2012-12-18 15:24:24 -03:00
Guillermo Rauch
a0020bcb2c socket: fix event packet 2012-12-18 15:22:16 -03:00
Guillermo Rauch
c929f8c7fb test: added socket event reception test 2012-12-18 15:18:26 -03:00
Guillermo Rauch
1d8a747773 test: added socket#send test 2012-12-18 15:15:42 -03:00
Guillermo Rauch
56ed3fbe75 socket: fixed packet handling 2012-12-18 15:15:12 -03:00
Guillermo Rauch
169046e026 test: added disconncet(true) test 2012-12-18 14:58:09 -03:00
Guillermo Rauch
56221bc093 socket: attempt to send disconnect packets prior to closing the transport
this will prevent reconnection from triggering
2012-12-18 14:57:37 -03:00
Guillermo Rauch
5da04cd1a9 socket: fixed EventEmitter inheritance 2012-12-18 14:57:23 -03:00
Guillermo Rauch
342845d5c2 socket: added missing acks initialization 2012-12-18 14:56:58 -03:00
Guillermo Rauch
97b63b0860 namespace: blacklist newListener event 2012-12-18 14:56:44 -03:00
Guillermo Rauch
12d1dca7ca socket: added more blacklisted events 2012-12-18 14:56:24 -03:00
Guillermo Rauch
3a259d420c namespace: improve middleware logic 2012-12-18 14:55:58 -03:00
Guillermo Rauch
19837a0f86 client: added disconnect method 2012-12-18 14:55:42 -03:00
Guillermo Rauch
3feb98a346 client: removed extra line 2012-12-17 15:26:04 -03:00
Guillermo Rauch
a8ea0f4fb0 socket: added Emitter mixin 2012-12-17 14:36:24 -03:00
Guillermo Rauch
1609eaa4e5 index: added second parameter to of optional 2012-12-17 14:25:55 -03:00
Guillermo Rauch
e724e7bdf6 test: added test for of second parameter 2012-12-17 14:25:40 -03:00
Guillermo Rauch
06e7df4eb2 test: added multiplexing tests 2012-12-17 12:45:26 -03:00
Guillermo Rauch
28a19bfb43 test: added second parameter to helper to aid w testing namespaces 2012-12-17 12:45:13 -03:00
Guillermo Rauch
deefa7bbb9 client: style 2012-12-17 09:58:34 -03:00
Guillermo Rauch
bfd019c2f3 Readme: described Socket and Client classes 2012-12-17 09:36:11 -03:00
Guillermo Rauch
755cead37c Readme: document namespace events 2012-12-17 09:01:45 -03:00
Guillermo Rauch
01e73669f9 test: added connect namespace event test 2012-12-17 09:00:17 -03:00
Guillermo Rauch
5022b06242 Readme: added build status 2012-12-17 08:52:00 -03:00
Guillermo Rauch
3afe5e3032 test: added basic namespace tests 2012-12-17 08:43:03 -03:00
Guillermo Rauch
4315732220 index: added missing on method 2012-12-17 08:39:12 -03:00
Guillermo Rauch
fcd969b1be index: fix style 2012-12-17 08:39:02 -03:00
Guillermo Rauch
c67d2d5494 namespace: instrument add 2012-12-17 08:29:43 -03:00
Guillermo Rauch
4f0fce34f5 index: fix client url 2012-12-17 08:29:25 -03:00
Guillermo Rauch
31adf5e45e lib: fixed static server binding 2012-12-17 01:10:03 -03:00
Guillermo Rauch
3063241eba test: fixed test for engine.io attachment 2012-12-17 01:09:50 -03:00
Guillermo Rauch
3b65a9f011 index: feel static server attachment order 2012-12-17 00:46:54 -03:00
Guillermo Rauch
f1e2af3d91 test: added client creation helper 2012-12-17 00:18:39 -03:00
Guillermo Rauch
70ce641d85 namespace: fix run call 2012-12-16 23:50:46 -03:00
Guillermo Rauch
c87a530b08 index: remove client event 2012-12-16 23:50:39 -03:00
Guillermo Rauch
fc65ed630a index: override path with /socket.io 2012-12-16 21:36:04 -03:00
Guillermo Rauch
98c4bb6955 test: fixed style 2012-12-16 19:13:02 -03:00
Guillermo Rauch
6d0b1a5117 test: basic namespaces tests 2012-12-16 19:12:03 -03:00
Guillermo Rauch
cb806c0d4e test: attachment and client serving tests 2012-12-16 18:58:17 -03:00
Guillermo Rauch
eb029808f5 Readme: muuuch nice readme <3 2012-12-16 18:58:00 -03:00
Guillermo Rauch
2615aa45e7 index: add warning about passing a function to attach 2012-12-16 18:53:46 -03:00
Guillermo Rauch
f6370c1635 index: removed middleware attachment possibility 2012-12-16 18:50:42 -03:00
Guillermo Rauch
4ecbf2a46e index: fix event listener override 2012-12-16 18:37:57 -03:00
Guillermo Rauch
c3d5024496 index: fix port binding 2012-12-16 18:37:46 -03:00
Guillermo Rauch
9c2224cca0 index: api cleanup 2012-12-14 10:07:07 -03:00
Guillermo Rauch
c695065c7a dox 2012-12-14 10:06:52 -03:00
Guillermo Rauch
44da490467 index: renamed client to static for clarity 2012-12-14 09:27:55 -03:00
Guillermo Rauch
8901efd085 package: added supertest 2012-12-14 09:18:44 -03:00
Guillermo Rauch
1e68a83bd3 index: fix send implementation 2012-12-14 09:18:34 -03:00
Guillermo Rauch
4ea334899f package: added client dep and superagent 2012-12-13 16:39:10 -03:00
Guillermo Rauch
5f397464a9 client: added static files 2012-12-13 16:38:58 -03:00
Guillermo Rauch
373c66f1ee index: added client serving with send 2012-12-13 16:38:23 -03:00
Guillermo Rauch
bec38c2ce1 index: move this to engine.io 2012-12-13 12:20:56 -03:00
Guillermo Rauch
b6a4899689 initial 1.0 commit 2012-12-13 12:14:54 -03:00
Guillermo Rauch
3af1ad982c Merge branch 'master' of github.com:LearnBoost/socket.io 2012-12-13 10:54:19 -03:00
Guillermo Rauch
8daa71302d Merge tag '0.9.12'
Release 0.9.12

Conflicts:
	package.json
2012-12-13 08:48:05 -03:00
Guillermo Rauch
b2a8ed1421 Release 0.9.12 2012-12-13 08:19:16 -03:00
Guillermo Rauch
0d3313f536 manager: fix for latest node which is returning a clone with listeners [viirya] 2012-12-13 08:18:42 -03:00
Guillermo Rauch
fcd4f6acfc Merge pull request #1078 from stouset/master
Fix operator precedence bug
2012-12-11 09:42:23 -08:00
Guillermo Rauch
80036cc50f Merge pull request #1082 from shapeshed/master
Fix leaking message:id, disconnect:id
2012-11-27 20:45:46 -08:00
Guillermo Rauch
373eadf7e1 Merge pull request #1086 from sampsasaarela/master
Fixed bug in symbian anna
2012-11-20 02:06:01 -08:00
Sampsa Saarela
ef54570313 Changed content-type in response header from text/plain to application/javascript because some browsers force file download (eg. symbian anna) 2012-11-20 11:53:01 +02:00
George Ornbo
6256f569b3 fix leaking message:id, disconnect:id #1081 #1064 #862 2012-11-12 13:11:23 +00:00
Stephen Touset
cd4dee7257 Respect operator precedence 2012-11-09 17:49:40 -08:00
Guillermo Rauch
3b7224c7e0 Release 0.9.11 2012-11-02 08:03:15 -07:00
Guillermo Rauch
2030cf1432 package: move redis to optionalDependenices [3rd-Eden] 2012-11-02 08:01:24 -07:00
Guillermo Rauch
7537e2543f transports: removed headers that are set by node from htmlfile [stbuehler] 2012-11-01 17:52:51 -07:00
Guillermo Rauch
e00913aae0 transports: fixed xhr-polling 2012-11-01 17:51:59 -07:00
Guillermo Rauch
dbabf20faa transports: fix for Connection: close [stbuehler] (fixes #406) 2012-11-01 17:14:06 -07:00
Guillermo Rauch
4de65523d9 Merge pull request #1061 from shripadk/master
Fix: Remove socket session from child processes on disconnect
2012-10-27 18:24:33 -07:00
Shripad K
7cca186bb1 fix: remove socket session from child processes in cluster on disconnect 2012-10-28 05:45:21 +05:30
Guillermo Rauch
ec07fa8308 Merge pull request #1031 from secobarbital/master
Fixed global variable leak
2012-09-15 13:46:03 -07:00
Seggy Umboh
f5c32c1490 Fixed global leak 2012-09-14 18:48:49 -07:00
Guillermo Rauch
c3ba8a722b Merge pull request #1008 from faeldt/master
Increase performance of generateId by avoiding sync calls to crypto.randomBytes
2012-09-10 15:06:40 -07:00
Guillermo Rauch
70b328f844 Merge pull request #1026 from jmatthewsr-ms/master
Websocket: Accept a PONG
2012-09-08 21:05:00 -07:00
Justin Matthews
32a44a3b5d Websocket: accept a pong (IE10 sends them) 2012-09-08 20:08:37 -07:00
Guillermo Rauch
c23ddb2bff Merge pull request #1022 from 3rd-Eden/master
Move redis
2012-09-07 13:38:36 -07:00
3rd-Eden
f7f219d6dd Move redis to the devDependencies, don't depend on redis as it's not a core component
to run Socket.IO.
2012-09-07 15:32:09 +02:00
Kristian Faeldt
f7d40d5f7b Moved generateId into an external module 2012-09-07 19:48:21 +09:00
Kristian Faeldt
da91c89147 Only fall back when no bytes available, not when threshold is reached 2012-08-28 19:15:55 +09:00
Kristian Faeldt
a10e963858 Added getRandomBytes to improve generateId performance 2012-08-28 18:56:11 +09:00
Guillermo Rauch
21a3733dec Merge pull request #1001 from crazyrobot/patch-1
Redis Store: removed unneeded module ('assert')
2012-08-22 16:28:28 -07:00
Itai
4a6890898a Redis Store: removed unneeded module ('assert')
It's not used anywhere in the file and the test file (test/stores.redis.test.js) uses the 'should' module.
I'm assuming this is a leftover.
2012-08-23 02:27:03 +03:00
Guillermo Rauch
ab2a0b6a8b test: removed protocolVersion private api from tests 2012-08-13 16:14:28 -07:00
Guillermo Rauch
c797d2a9fb *: added ws dependency 2012-08-13 16:14:15 -07:00
Guillermo Rauch
d558c97089 transport: rewrite websocket transport to use ws client 2012-08-13 16:14:03 -07:00
Guillermo Rauch
b483dfcce9 test: removed old transports tests 2012-08-13 16:13:51 -07:00
Guillermo Rauch
f59e8aceaa manager: implemented ws 2012-08-13 16:13:38 -07:00
Guillermo Rauch
de9e8dffe1 Release 0.9.10 2012-08-10 13:34:50 -07:00
Guillermo Rauch
3a3044ebba Merge pull request #972 from Coreh/express-3.x-readme
Add express 3.0 instructions on Readme.md
2012-08-10 10:17:55 -07:00
Guillermo Rauch
d10b4dd1bd Merge pull request #985 from GICodeWarrior/log-case-fix
Don't lowercase log messages
2012-08-08 18:03:57 -07:00
Rusty Burchfield
12beee2d63 Don't lowercase log messages
Lowercasing log messages is unnecessary.  It makes some messages difficult to
read, and others difficult to search for.
2012-08-08 11:32:57 -07:00
Guillermo Rauch
875f14d16b Revert "Fix infinite recursion in Websocket parsers."
This reverts commit c218468f67.
2012-08-07 13:18:41 -07:00
Guillermo Rauch
8ca8990a0c Merge pull request #983 from GICodeWarrior/parser-recursion
Fix infinite recursion in Websocket parsers.
2012-08-06 13:16:37 -07:00
Rusty Burchfield
c218468f67 Fix infinite recursion in Websocket parsers.
If a client is feeding messages faster than server can handle them, infinite
recursion occurs.  Basically, the "overflow" data gets added to the parser and
it immediately parses a new message.

The fix pushes the processing of the next message (in this edge case) onto the
event queue.  This prevents the stack from recursing indefinitely.  This also
prevents a fast client from starving other clients.
2012-08-06 13:03:51 -07:00
Guillermo Rauch
4164e3bd7e Merge pull request #981 from doozr/honour-flash-settings
Honour flash settings
2012-08-06 08:59:17 -07:00
Guillermo Rauch
46227e7ac9 Merge pull request #980 from doozr/jsonp-error-crash
Always set the HTTP response in case an error should be returned to the client
2012-08-06 08:58:57 -07:00
Craig Andrews
d723d363b2 Always set the HTTP response in case an error should be returned to the client 2012-08-06 14:16:06 +01:00
Craig Andrews
fa1c1b2ada Create or destroy the flash policy server on configuration change 2012-08-06 14:14:15 +01:00
Craig Andrews
d32a848c3f Honour configuration to disable flash policy server 2012-08-06 14:14:14 +01:00
Guillermo Rauch
48ad0d3d1d Release 0.9.9 2012-08-01 15:14:02 -07:00
Guillermo Rauch
281a467960 manager: added response to sync disconnect xhrs 2012-08-01 15:08:06 -07:00
Guillermo Rauch
1fa74a46a3 Revert "Fix disconnectSync getting ignored"
This reverts commit f48b40e134.
2012-08-01 11:58:28 -07:00
Guillermo Rauch
ca4e3f32a3 Merge pull request #975 from huancz/master
fix issue #961 - restore compatibility with earlier node releases (up to 0.4.x)
2012-07-31 08:34:22 -07:00
Guillermo Rauch
9dd8134e6a Merge pull request #970 from renier/master
Codebase needs a license file (#965)
2012-07-31 08:32:07 -07:00
Renier Morales
180f1c91b9 Put license text in its own file (#965) 2012-07-31 11:07:21 -04:00
Marco Aurélio
bddf652c25 Add express 3.0 instructions on Readme.md 2012-07-30 15:53:47 -03:00
Guillermo Rauch
c795e4cf1a Merge pull request #971 from Coreh/express-3.x-warn
Add warning to .listen() to ease the migration to Express 3.x
2012-07-30 11:49:53 -07:00
Marco Aurélio
6afbb34581 Add warning to .listen() to ease the migration to Express 3.x 2012-07-30 15:43:00 -03:00
Guillermo Rauch
ac39dbc721 Merge pull request #964 from crickeys/xhr_polling_disconnectSync
Fix disconnectSync getting ignored
2012-07-27 10:06:03 -07:00
Petr Běhan
a5c5c20438 restore compatibility with node 0.4.x 2012-07-27 15:38:57 +02:00
Brian Gruber
f48b40e134 Fix disconnectSync getting ignored
If using xhr-polling and a browser closes a tab or window, the
disconnectSync in the socket.io-client method is called which sends an
XHR request to the server indicating a disconnect. This line would cause
that to be ignored and so the server would have to wait for a timeout to
mark them as disconnect. This was possibly because it was sent from a
different tcp socket than the current connection.
2012-07-26 21:19:00 -05:00
Guillermo Rauch
1679fd564c Release 0.9.8 2012-07-24 17:36:30 -07:00
Guillermo Rauch
bb900d445a Release 0.9.7 2012-07-24 11:16:20 -07:00
Guillermo Rauch
c6fed55f53 tests: fixed tests for 0.8 2012-07-24 10:39:23 -07:00
Guillermo Rauch
6adebc85fc Merge pull request #958 from xaroth8088/master
Prevent crash when socket leaves a room twice.
2012-07-22 11:26:21 -07:00
xaroth8088
7a087bcc94 Prevent crash when socket leaves a room twice. 2012-07-22 11:09:06 -07:00
Guillermo Rauch
18422183c8 Merge pull request #957 from xaroth8088/master
Corrects unsafe usage of for..in, permitting socket.io to be used in environments that extend Object, etc.
2012-07-21 11:44:28 -07:00
xaroth8088
aeb904f58b Corrects unsafe usage of for..in, permitting socket.io to be used in environments where Object, Function, etc. have been extended.
http://yuiblog.com/blog/2006/09/26/for-in-intrigue/
2012-07-21 11:30:15 -07:00
xaroth8088
9c0b9de7f0 Revert "Corrects unsafe usage of for..in, permitting socket.io to be used in environments that extend Object, etc."
This reverts commit 81552c11ca.
2012-07-21 11:21:11 -07:00
xaroth8088
81552c11ca Corrects unsafe usage of for..in, permitting socket.io to be used in environments that extend Object, etc.
http://yuiblog.com/blog/2006/09/26/for-in-intrigue/
2012-07-21 10:29:20 -07:00
Guillermo Rauch
e1fe76aebe Fix for node 0.8 with gzip compression. Thanks @vadimi 2012-07-09 16:58:02 -07:00
Guillermo Rauch
8197a0c854 Merge pull request #929 from sjonnet19/patch-1
Update redis to support Node 0.8.x
2012-06-26 06:29:08 -07:00
Shawn Jonnet
2b91f1407f Update redis to support Node 0.8.x 2012-06-25 23:30:24 -03:00
Guillermo Rauch
3b9715e8e7 Merge pull request #869 from MrSwitch/master
Small change to demo copy
2012-05-03 06:24:15 -07:00
Andrew Dodson
4e13cfb03e Update copy 2012-05-03 12:16:01 +10:00
Guillermo Rauch
39671e81a5 Merge pull request #868 from bodash/patch-1
I continued to have websocket connection issues in Safari when using SSL...
2012-05-02 12:21:24 -07:00
bodash
ffa8994a23 I continued to have websocket connection issues in Safari when using SSL that terminated at a load balancer. The shorthand logic that was here was nice and compact but didn't seem to work. Took the "intent" of the short hand and made it a bit more verbose and now it works. 2012-05-02 13:18:46 -06:00
Guillermo Rauch
de1afe1317 Merge pull request #857 from martinthomson/bug/856
Fix for ID generation vulnerability #856
2012-04-26 15:49:24 -07:00
Martin Thomson
aaad106b90 Adding node 0.4 backward compat for id gen 2012-04-26 15:08:19 -07:00
Martin Thomson
f850ddccd0 Removing more fixes for other bug 2012-04-26 14:35:17 -07:00
Martin Thomson
8d269aae4c Removing fixes for other bug 2012-04-26 14:33:37 -07:00
Martin Thomson
67b4eb9abd Making ID generation securely random 2012-04-26 14:28:00 -07:00
Guillermo Rauch
fe6dd87443 Merge pull request #848 from mbrevoort/redisStoreRaceCondition
Fix Redis Store race condition in manager onOpen unsubscribe callback
2012-04-23 15:30:30 -07:00
Mike Brevoort
d9aeaa494f Fix Redis Store race condition in manager onOpen unsubscribe callback 2012-04-23 16:06:31 -06:00
Guillermo Rauch
2024d45383 Merge pull request #841 from TooTallNate/master
fix for EventEmitters always reusing the same Array instance for listeners
2012-04-19 13:30:13 -07:00
Nathan Rajlich
e1884859bc fix for EventEmitters always reusing the same Array instance for listeners
This fixes node v0.7.x.

The node commits that broke this old behavior is here:
  78dc13fbf9%5E...928ea564d16da47e615ddac627e0b4d4a40d8196
2012-04-19 13:18:22 -07:00
Guillermo Rauch
0242a2ddf3 Merge branch 'master' of github.com:LearnBoost/socket.io 2012-04-17 19:51:49 -03:00
Guillermo Rauch
dbe6d5f740 Release 0.9.6 2012-04-17 19:51:37 -03:00
Guillermo Rauch
e98fc7bc86 Fixed XSS in jsonp-polling. 2012-04-17 19:48:32 -03:00
Guillermo Rauch
9bbf17f31e Merge pull request #827 from crickeys/patch-4
Fixes when browser doesn't send origin header, defaults to empty string ...
2012-04-11 15:02:50 -07:00
crickeys
1a5a87af13 Fixes when browser doesn't send origin header, defaults to empty string instead of UNDEFINED (which would throw an error on the origin.match(/^https/) below 2012-04-11 14:41:07 -05:00
Guillermo Rauch
a4e53a642b Release 0.9.5 2012-04-05 14:37:18 -03:00
Guillermo Rauch
6f36d8c2ff Added test for polling with connection close. 2012-04-05 14:32:10 -03:00
Guillermo Rauch
09fb16b443 Ensure close upon request close. 2012-04-05 14:31:50 -03:00
Guillermo Rauch
330407cc9d Fix disconnection reason being lost for polling transports. 2012-04-05 14:31:32 -03:00
Guillermo Rauch
2075307f23 Ensure that polling transports work with Connection: close 2012-04-05 14:31:13 -03:00
Guillermo Rauch
d7b06edaca Log disconnection reason 2012-04-05 14:31:01 -03:00
351 changed files with 215188 additions and 18232 deletions

61
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@@ -0,0 +1,61 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: 'to triage'
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Please fill the following code example:
Socket.IO server version: `x.y.z`
*Server*
```js
import { Server } from "socket.io";
const io = new Server(3000, {});
io.on("connection", (socket) => {
console.log(`connect ${socket.id}`);
socket.on("disconnect", () => {
console.log(`disconnect ${socket.id}`);
});
});
```
Socket.IO client version: `x.y.z`
*Client*
```js
import { io } from "socket.io-client";
const socket = io("ws://localhost:3000/", {});
socket.on("connect", () => {
console.log(`connect ${socket.id}`);
});
socket.on("disconnect", () => {
console.log("disconnect");
});
```
**Expected behavior**
A clear and concise description of what you expected to happen.
**Platform:**
- Device: [e.g. Samsung S8]
- OS: [e.g. Android 9.2]
**Additional context**
Add any other context about the problem here.

5
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Ask a Question
url: https://github.com/socketio/socket.io/discussions/new?category=q-a
about: Ask the community for help

View File

@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: 'enhancement'
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

18
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@@ -0,0 +1,18 @@
### The kind of change this PR does introduce
* [x] a bug fix
* [ ] a new feature
* [ ] an update to the documentation
* [ ] a code change that improves performance
* [ ] other
### Current behavior
### New behavior
### Other information (e.g. related issues)

26
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
name: CI
on:
push:
pull_request:
schedule:
- cron: '0 0 * * 0'
jobs:
test-node:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12, 14, 16]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
env:
CI: true

4
.gitignore vendored
View File

@@ -8,3 +8,7 @@ lib-cov
*.pid
benchmarks/*.png
node_modules
coverage
.idea
.nyc_output
dist/

View File

@@ -1,3 +0,0 @@
support
test
examples

2
.replit Normal file
View File

@@ -0,0 +1,2 @@
language = "nodejs"
run = "npm start"

View File

@@ -1,6 +0,0 @@
language: node_js
node_js:
- 0.6
notifications:
irc: "irc.freenode.org#socket.io"

534
CHANGELOG.md Normal file
View File

@@ -0,0 +1,534 @@
## [4.5.1](https://github.com/socketio/socket.io/compare/4.5.0...4.5.1) (2022-05-17)
### Bug Fixes
* forward the local flag to the adapter when using fetchSockets() ([30430f0](https://github.com/socketio/socket.io/commit/30430f0985f8e7c49394543d4c84913b6a15df60))
* **typings:** add HTTPS server to accepted types ([#4351](https://github.com/socketio/socket.io/issues/4351)) ([9b43c91](https://github.com/socketio/socket.io/commit/9b43c9167cff817c60fa29dbda2ef7cd938aff51))
# [4.5.0](https://github.com/socketio/socket.io/compare/4.4.1...4.5.0) (2022-04-23)
### Bug Fixes
* **typings:** ensure compatibility with TypeScript 3.x ([#4259](https://github.com/socketio/socket.io/issues/4259)) ([02c87a8](https://github.com/socketio/socket.io/commit/02c87a85614e217b8e7b93753f315790ae9d99f6))
### Features
* add support for catch-all listeners for outgoing packets ([531104d](https://github.com/socketio/socket.io/commit/531104d332690138b7aab84d5583d6204132c8b4))
This is similar to `onAny()`, but for outgoing packets.
Syntax:
```js
socket.onAnyOutgoing((event, ...args) => {
console.log(event);
});
```
* broadcast and expect multiple acks ([8b20457](https://github.com/socketio/socket.io/commit/8b204570a94979bbec307f23ca078f30f5cf07b0))
Syntax:
```js
io.timeout(1000).emit("some-event", (err, responses) => {
// ...
});
```
* add the "maxPayload" field in the handshake details ([088dcb4](https://github.com/socketio/engine.io/commit/088dcb4dff60df39785df13d0a33d3ceaa1dff38))
So that clients in HTTP long-polling can decide how many packets they have to send to stay under the maxHttpBufferSize
value.
This is a backward compatible change which should not mandate a new major revision of the protocol (we stay in v4), as
we only add a field in the JSON-encoded handshake data:
```
0{"sid":"lv_VI97HAXpY6yYWAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000,"maxPayload":1000000}
```
## [4.4.1](https://github.com/socketio/socket.io/compare/4.4.0...4.4.1) (2022-01-06)
### Bug Fixes
* **types:** make `RemoteSocket.data` type safe ([#4234](https://github.com/socketio/socket.io/issues/4234)) ([770ee59](https://github.com/socketio/socket.io/commit/770ee5949fb47c2556876c622f06c862573657d6))
* **types:** pass `SocketData` type to custom namespaces ([#4233](https://github.com/socketio/socket.io/issues/4233)) ([f2b8de7](https://github.com/socketio/socket.io/commit/f2b8de71919e1b4d3e57f15a459972c1d1064787))
# [4.4.0](https://github.com/socketio/socket.io/compare/4.3.2...4.4.0) (2021-11-18)
### Bug Fixes
* only set 'connected' to true after middleware execution ([02b0f73](https://github.com/socketio/socket.io/commit/02b0f73e2c64b09c72c5fbf7dc5f059557bdbe50))
### Features
* add an implementation based on uWebSockets.js ([c0d8c5a](https://github.com/socketio/socket.io/commit/c0d8c5ab234d0d2bef0d0dec472973cc9662f647))
* add timeout feature ([f0ed42f](https://github.com/socketio/socket.io/commit/f0ed42f18cabef20ad976aeec37077b6bf3837a5))
* add type information to `socket.data` ([#4159](https://github.com/socketio/socket.io/issues/4159)) ([fe8730c](https://github.com/socketio/socket.io/commit/fe8730ca0f15bc92d5de81cf934c89c76d6af329))
## [4.3.2](https://github.com/socketio/socket.io/compare/4.3.1...4.3.2) (2021-11-08)
### Bug Fixes
* fix race condition in dynamic namespaces ([#4137](https://github.com/socketio/socket.io/issues/4137)) ([9d86397](https://github.com/socketio/socket.io/commit/9d86397243bcbb5775a29d96e5ef03e17148a8e7))
## [4.3.1](https://github.com/socketio/socket.io/compare/4.3.0...4.3.1) (2021-10-16)
### Bug Fixes
* fix server attachment ([#4127](https://github.com/socketio/socket.io/issues/4127)) ([0ef2a4d](https://github.com/socketio/socket.io/commit/0ef2a4d02c9350aff163df9cb61aece89c4dac0f))
# [4.3.0](https://github.com/socketio/socket.io/compare/4.2.0...4.3.0) (2021-10-14)
### Bug Fixes
* **typings:** add name field to cookie option ([#4099](https://github.com/socketio/socket.io/issues/4099)) ([033c5d3](https://github.com/socketio/socket.io/commit/033c5d399a2b985afad32c1e4b0c16d764e248cd))
* send volatile packets with binary attachments ([dc81fcf](https://github.com/socketio/socket.io/commit/dc81fcf461cfdbb5b34b1a5a96b84373754047d5))
### Features
* serve ESM bundle ([60edecb](https://github.com/socketio/socket.io/commit/60edecb3bd33801803cdcba0aefbafa381a2abb3))
# [4.2.0](https://github.com/socketio/socket.io/compare/4.1.3...4.2.0) (2021-08-30)
### Bug Fixes
* **typings:** allow async listener in typed events ([ccfd8ca](https://github.com/socketio/socket.io/commit/ccfd8caba6d38b7ba6c5114bd8179346ed07671c))
### Features
* ignore the query string when serving client JavaScript ([#4024](https://github.com/socketio/socket.io/issues/4024)) ([24fee27](https://github.com/socketio/socket.io/commit/24fee27ba36485308f8e995879c10931532c814e))
## [4.1.3](https://github.com/socketio/socket.io/compare/4.1.2...4.1.3) (2021-07-10)
### Bug Fixes
* fix io.except() method ([94e27cd](https://github.com/socketio/socket.io/commit/94e27cd072c8a4eeb9636f6ffbb7a21d382f36b0))
* remove x-sourcemap header ([a4dffc6](https://github.com/socketio/socket.io/commit/a4dffc6527f412d51a786ae5bf2e9080fe1ca63c))
## [4.1.2](https://github.com/socketio/socket.io/compare/4.1.1...4.1.2) (2021-05-17)
### Bug Fixes
* **typings:** ensure compatibility with TypeScript 3.x ([0cb6ac9](https://github.com/socketio/socket.io/commit/0cb6ac95b49a27483b6f1b6402fa54b35f82e36f))
* ensure compatibility with previous versions of the adapter ([a2cf248](https://github.com/socketio/socket.io/commit/a2cf2486c366cb62293101c10520c57f6984a3fc))
## [4.1.1](https://github.com/socketio/socket.io/compare/4.1.0...4.1.1) (2021-05-11)
### Bug Fixes
* **typings:** properly type server-side events ([b84ed1e](https://github.com/socketio/socket.io/commit/b84ed1e41c9053792caf58974c5de9395bfd509f))
* **typings:** properly type the adapter attribute ([891b187](https://github.com/socketio/socket.io/commit/891b1870e92d1ec38910f03bb839817e2d6be65a))
# [4.1.0](https://github.com/socketio/socket.io/compare/4.0.2...4.1.0) (2021-05-11)
### Features
* add support for inter-server communication ([93cce05](https://github.com/socketio/socket.io/commit/93cce05fb3faf91f21fa71212275c776aa161107))
* notify upon namespace creation ([499c892](https://github.com/socketio/socket.io/commit/499c89250d2db1ab7725ab2b74840e188c267c46))
* add a "connection_error" event ([7096e98](https://github.com/socketio/engine.io/commit/7096e98a02295a62c8ea2aa56461d4875887092d), from `engine.io`)
* add the "initial_headers" and "headers" events ([2527543](https://github.com/socketio/engine.io/commit/252754353a0e88eb036ebb3082e9d6a9a5f497db), from `engine.io`)
### Performance Improvements
* add support for the "wsPreEncoded" writing option ([dc381b7](https://github.com/socketio/socket.io/commit/dc381b72c6b2f8172001dedd84116122e4cc95b3))
## [4.0.2](https://github.com/socketio/socket.io/compare/4.0.1...4.0.2) (2021-05-06)
### Bug Fixes
* **typings:** make "engine" attribute public ([b81ce4c](https://github.com/socketio/socket.io/commit/b81ce4c9d0b00666361498e2ba5e0d007d5860b8))
* properly export the Socket class ([d65b6ee](https://github.com/socketio/socket.io/commit/d65b6ee84c8e91deb61c3c1385eb19afa196a909))
## [4.0.1](https://github.com/socketio/socket.io/compare/4.0.0...4.0.1) (2021-03-31)
### Bug Fixes
* **typings:** add fallback to untyped event listener ([#3834](https://github.com/socketio/socket.io/issues/3834)) ([a11152f](https://github.com/socketio/socket.io/commit/a11152f42b281df83409313962f60f230239c79e))
* **typings:** update return type from emit ([#3843](https://github.com/socketio/socket.io/issues/3843)) ([1a72ae4](https://github.com/socketio/socket.io/commit/1a72ae4fe27a14cf60916f991a2c94da91d9e54a))
# [4.0.0](https://github.com/socketio/socket.io/compare/3.1.2...4.0.0) (2021-03-10)
### Bug Fixes
* make io.to(...) immutable ([ac9e8ca](https://github.com/socketio/socket.io/commit/ac9e8ca6c71e00d4af45ee03f590fe56f3951186))
### Features
* add some utility methods ([b25495c](https://github.com/socketio/socket.io/commit/b25495c069031674da08e19aed68922c7c7a0e28))
* add support for typed events ([#3822](https://github.com/socketio/socket.io/issues/3822)) ([0107510](https://github.com/socketio/socket.io/commit/0107510ba8a0f148c78029d8be8919b350feb633))
* allow to exclude specific rooms when broadcasting ([#3789](https://github.com/socketio/socket.io/issues/3789)) ([7de2e87](https://github.com/socketio/socket.io/commit/7de2e87e888d849eb2dfc5e362af4c9e86044701))
* allow to pass an array to io.to(...) ([085d1de](https://github.com/socketio/socket.io/commit/085d1de9df909651de8b313cc6f9f253374b702e))
## [3.1.2](https://github.com/socketio/socket.io/compare/3.1.1...3.1.2) (2021-02-26)
### Bug Fixes
* ignore packets received after disconnection ([494c64e](https://github.com/socketio/socket.io/commit/494c64e44f645cbd24c645f1186d203789e84af0))
## [3.1.1](https://github.com/socketio/socket.io/compare/3.1.0...3.1.1) (2021-02-03)
### Bug Fixes
* properly parse the CONNECT packet in v2 compatibility mode ([6f4bd7f](https://github.com/socketio/socket.io/commit/6f4bd7f8e7c41a075a8014565330a77c38b03a8d))
* **typings:** add return types and general-case overload signatures ([#3776](https://github.com/socketio/socket.io/issues/3776)) ([9e8f288](https://github.com/socketio/socket.io/commit/9e8f288ca9f14f91064b8d3cce5946f7d23d407c))
* **typings:** update the types of "query", "auth" and "headers" ([4f2e9a7](https://github.com/socketio/socket.io/commit/4f2e9a716d9835b550c8fd9a9b429ebf069c2895))
# [3.1.0](https://github.com/socketio/socket.io/compare/3.0.5...3.1.0) (2021-01-15)
### Features
* confirm a weak but matching ETag ([#3485](https://github.com/socketio/socket.io/issues/3485)) ([161091d](https://github.com/socketio/socket.io/commit/161091dd4c9e1b1610ac3d45d964195e63d92b94))
* **esm:** export the Namespace and Socket class ([#3699](https://github.com/socketio/socket.io/issues/3699)) ([233650c](https://github.com/socketio/socket.io/commit/233650c22209708b5fccc4349c38d2fa1b465d8f))
* add support for Socket.IO v2 clients ([9925746](https://github.com/socketio/socket.io/commit/9925746c8ee3a6522bd640b5d586c83f04f2f1ba))
* add room events ([155fa63](https://github.com/socketio/socket.io-adapter/commit/155fa6333a504036e99a33667dc0397f6aede25e))
### Bug Fixes
* allow integers as event names ([1c220dd](https://github.com/socketio/socket.io-parser/commit/1c220ddbf45ea4b44bc8dbf6f9ae245f672ba1b9))
## [3.0.5](https://github.com/socketio/socket.io/compare/3.0.4...3.0.5) (2021-01-05)
### Bug Fixes
* properly clear timeout on connection failure ([170b739](https://github.com/socketio/socket.io/commit/170b739f147cb6c92b423729b877e242e376927d))
### Reverts
* restore the socket middleware functionality ([bf54327](https://github.com/socketio/socket.io/commit/bf5432742158e4d5ba2722cff4a614967dffa5b9))
## [3.0.4](https://github.com/socketio/socket.io/compare/3.0.3...3.0.4) (2020-12-07)
## [3.0.3](https://github.com/socketio/socket.io/compare/3.0.2...3.0.3) (2020-11-19)
## [3.0.2](https://github.com/socketio/socket.io/compare/3.0.1...3.0.2) (2020-11-17)
### Bug Fixes
* merge Engine.IO options ([43705d7](https://github.com/socketio/socket.io/commit/43705d7a9149833afc69edc937ea7f8c9aabfeef))
## [3.0.1](https://github.com/socketio/socket.io/compare/3.0.0...3.0.1) (2020-11-09)
### Bug Fixes
* export ServerOptions and Namespace types ([#3684](https://github.com/socketio/socket.io/issues/3684)) ([f62f180](https://github.com/socketio/socket.io/commit/f62f180edafdd56d8a8a277e092bc66df0c5f07f))
* **typings:** update the signature of the emit method ([50671d9](https://github.com/socketio/socket.io/commit/50671d984a81535a6a15c704546ca7465e2ea295))
# [3.0.0](https://github.com/socketio/socket.io/compare/2.3.0...3.0.0) (2020-11-05)
### Bug Fixes
* close clients with no namespace ([91cd255](https://github.com/socketio/socket.io/commit/91cd255ba76ff6a780c62740f9f5cd3a76f5d7c7))
### Features
* emit an Error object upon middleware error ([54bf4a4](https://github.com/socketio/socket.io/commit/54bf4a44e9e896dfb64764ee7bd4e8823eb7dc7b))
* serve msgpack bundle ([aa7574f](https://github.com/socketio/socket.io/commit/aa7574f88471aa30ae472a5cddf1000a8baa70fd))
* add support for catch-all listeners ([5c73733](https://github.com/socketio/socket.io/commit/5c737339858d59eab4b5ee2dd6feff0e82c4fe5a))
* make Socket#join() and Socket#leave() synchronous ([129c641](https://github.com/socketio/socket.io/commit/129c6417bd818bc8b4e1b831644323876e627c13))
* remove prod dependency to socket.io-client ([7603da7](https://github.com/socketio/socket.io/commit/7603da71a535481e3fc60e38b013abf78516d322))
* move binary detection back to the parser ([669592d](https://github.com/socketio/socket.io/commit/669592d120409a5cf00f128070dee6d22259ba4f))
* add ES6 module export ([8b6b100](https://github.com/socketio/socket.io/commit/8b6b100c284ccce7d85e55659e3397f533916847))
* do not reuse the Engine.IO id ([2875d2c](https://github.com/socketio/socket.io/commit/2875d2cfdfa463e64cb520099749f543bbc4eb15))
* remove Server#set() method ([029f478](https://github.com/socketio/socket.io/commit/029f478992f59b1eb5226453db46363a570eea46))
* remove Socket#rooms object ([1507b41](https://github.com/socketio/socket.io/commit/1507b416d584381554d1ed23c9aaf3b650540071))
* remove the 'origins' option ([a8c0600](https://github.com/socketio/socket.io/commit/a8c06006098b512ba1b8b8df82777349db486f41))
* remove the implicit connection to the default namespace ([3289f7e](https://github.com/socketio/socket.io/commit/3289f7ec376e9ec88c2f90e2735c8ca8d01c0e97))
* throw upon reserved event names ([4bd5b23](https://github.com/socketio/socket.io/commit/4bd5b2339a66a5a675e20f689fff2e70ff12d236))
### BREAKING CHANGES
* the Socket#use() method is removed (see [5c73733](https://github.com/socketio/socket.io/commit/5c737339858d59eab4b5ee2dd6feff0e82c4fe5a))
* Socket#join() and Socket#leave() do not accept a callback argument anymore.
Before:
```js
socket.join("room1", () => {
io.to("room1").emit("hello");
});
```
After:
```js
socket.join("room1");
io.to("room1").emit("hello");
// or await socket.join("room1"); for custom adapters
```
* the "connected" map is renamed to "sockets"
* the Socket#binary() method is removed, as this use case is now covered by the ability to provide your own parser.
* the 'origins' option is removed
Before:
```js
new Server(3000, {
origins: ["https://example.com"]
});
```
The 'origins' option was used in the allowRequest method, in order to
determine whether the request should pass or not. And the Engine.IO
server would implicitly add the necessary Access-Control-Allow-xxx
headers.
After:
```js
new Server(3000, {
cors: {
origin: "https://example.com",
methods: ["GET", "POST"],
allowedHeaders: ["content-type"]
}
});
```
The already existing 'allowRequest' option can be used for validation:
```js
new Server(3000, {
allowRequest: (req, callback) => {
callback(null, req.headers.referer.startsWith("https://example.com"));
}
});
```
* Socket#rooms is now a Set instead of an object
* Namespace#connected is now a Map instead of an object
* there is no more implicit connection to the default namespace:
```js
// client-side
const socket = io("/admin");
// server-side
io.on("connect", socket => {
// not triggered anymore
})
io.use((socket, next) => {
// not triggered anymore
});
io.of("/admin").use((socket, next) => {
// triggered
});
```
* the Server#set() method was removed
This method was kept for backward-compatibility with pre-1.0 versions.
# [3.0.0-rc4](https://github.com/socketio/socket.io/compare/3.0.0-rc3...3.0.0-rc4) (2020-10-30)
### Features
* emit an Error object upon middleware error ([54bf4a4](https://github.com/socketio/socket.io/commit/54bf4a44e9e896dfb64764ee7bd4e8823eb7dc7b))
* serve msgpack bundle ([aa7574f](https://github.com/socketio/socket.io/commit/aa7574f88471aa30ae472a5cddf1000a8baa70fd))
# [3.0.0-rc3](https://github.com/socketio/socket.io/compare/3.0.0-rc2...3.0.0-rc3) (2020-10-26)
### Features
* add support for catch-all listeners ([5c73733](https://github.com/socketio/socket.io/commit/5c737339858d59eab4b5ee2dd6feff0e82c4fe5a))
* make Socket#join() and Socket#leave() synchronous ([129c641](https://github.com/socketio/socket.io/commit/129c6417bd818bc8b4e1b831644323876e627c13))
* remove prod dependency to socket.io-client ([7603da7](https://github.com/socketio/socket.io/commit/7603da71a535481e3fc60e38b013abf78516d322))
### BREAKING CHANGES
* the Socket#use() method is removed (see [5c73733](https://github.com/socketio/socket.io/commit/5c737339858d59eab4b5ee2dd6feff0e82c4fe5a))
* Socket#join() and Socket#leave() do not accept a callback argument anymore.
Before:
```js
socket.join("room1", () => {
io.to("room1").emit("hello");
});
```
After:
```js
socket.join("room1");
io.to("room1").emit("hello");
// or await socket.join("room1"); for custom adapters
```
# [3.0.0-rc2](https://github.com/socketio/socket.io/compare/3.0.0-rc1...3.0.0-rc2) (2020-10-15)
### Bug Fixes
* close clients with no namespace ([91cd255](https://github.com/socketio/socket.io/commit/91cd255ba76ff6a780c62740f9f5cd3a76f5d7c7))
### Code Refactoring
* remove duplicate _sockets map ([8a5db7f](https://github.com/socketio/socket.io/commit/8a5db7fa36a075da75cde43cd4fb6382b7659953))
### Features
* move binary detection back to the parser ([669592d](https://github.com/socketio/socket.io/commit/669592d120409a5cf00f128070dee6d22259ba4f))
### BREAKING CHANGES
* the "connected" map is renamed to "sockets"
* the Socket#binary() method is removed, as this use case is now covered by the ability to provide your own parser.
# [3.0.0-rc1](https://github.com/socketio/socket.io/compare/2.3.0...3.0.0-rc1) (2020-10-13)
### Features
* add ES6 module export ([8b6b100](https://github.com/socketio/socket.io/commit/8b6b100c284ccce7d85e55659e3397f533916847))
* do not reuse the Engine.IO id ([2875d2c](https://github.com/socketio/socket.io/commit/2875d2cfdfa463e64cb520099749f543bbc4eb15))
* remove Server#set() method ([029f478](https://github.com/socketio/socket.io/commit/029f478992f59b1eb5226453db46363a570eea46))
* remove Socket#rooms object ([1507b41](https://github.com/socketio/socket.io/commit/1507b416d584381554d1ed23c9aaf3b650540071))
* remove the 'origins' option ([a8c0600](https://github.com/socketio/socket.io/commit/a8c06006098b512ba1b8b8df82777349db486f41))
* remove the implicit connection to the default namespace ([3289f7e](https://github.com/socketio/socket.io/commit/3289f7ec376e9ec88c2f90e2735c8ca8d01c0e97))
* throw upon reserved event names ([4bd5b23](https://github.com/socketio/socket.io/commit/4bd5b2339a66a5a675e20f689fff2e70ff12d236))
### BREAKING CHANGES
* the 'origins' option is removed
Before:
```js
new Server(3000, {
origins: ["https://example.com"]
});
```
The 'origins' option was used in the allowRequest method, in order to
determine whether the request should pass or not. And the Engine.IO
server would implicitly add the necessary Access-Control-Allow-xxx
headers.
After:
```js
new Server(3000, {
cors: {
origin: "https://example.com",
methods: ["GET", "POST"],
allowedHeaders: ["content-type"]
}
});
```
The already existing 'allowRequest' option can be used for validation:
```js
new Server(3000, {
allowRequest: (req, callback) => {
callback(null, req.headers.referer.startsWith("https://example.com"));
}
});
```
* Socket#rooms is now a Set instead of an object
* Namespace#connected is now a Map instead of an object
* there is no more implicit connection to the default namespace:
```js
// client-side
const socket = io("/admin");
// server-side
io.on("connect", socket => {
// not triggered anymore
})
io.use((socket, next) => {
// not triggered anymore
});
io.of("/admin").use((socket, next) => {
// triggered
});
```
* the Server#set() method was removed
This method was kept for backward-compatibility with pre-1.0 versions.

View File

@@ -1,246 +0,0 @@
0.9.4 / 2012-04-01
==================
* Disconnecting from namespace improvement (#795) [DanielBaulig]
* Bumped client with polling reconnection loop (#438)
0.9.3 / 2012-03-28
==================
* Fix "Syntax error" on FF Web Console with XHR Polling [mikito]
0.9.2 / 2012-03-13
==================
* More sensible close `timeout default` (fixes disconnect issue)
0.9.1-1 / 2012-03-02
====================
* Bumped client with NPM dependency fix.
0.9.1 / 2012-03-02
==================
* Changed heartbeat timeout and interval defaults (60 and 25 seconds)
* Make tests work both on 0.4 and 0.6
* Updated client (improvements + bug fixes).
0.9.0 / 2012-02-26
==================
* Make it possible to use a regexp to match the socket.io resource URL.
We need this because we have to prefix the socket.io URL with a variable ID.
* Supplemental fix to gavinuhma/authfix, it looks like the same Access-Control-Origin logic is needed in the http and xhr-polling transports
* Updated express dep for windows compatibility.
* Combine two substr calls into one in decodePayload to improve performance
* Minor documentation fix
* Minor. Conform to style of other files.
* Switching setting to 'match origin protocol'
* Revert "Fixes leaking Redis subscriptions for #663. The local flag was not getting passed through onClientDisconnect()."
* Revert "Handle leaked dispatch:[id] subscription."
* Merge pull request #667 from dshaw/patch/redis-disconnect
* Handle leaked dispatch:[id] subscription.
* Fixes leaking Redis subscriptions for #663. The local flag was not getting passed through onClientDisconnect().
* Prevent memory leaking on uncompleted requests & add max post size limitation
* Fix for testcase
* Set Access-Control-Allow-Credentials true, regardless of cookie
* Remove assertvarnish from package as it breaks on 0.6
* Correct irc channel
* Added proper return after reserved field error
* Fixes manager.js failure to close connection after transport error has happened
* Added implicit port 80 for origin checks. fixes #638
* Fixed bug #432 in 0.8.7
* Set Access-Control-Allow-Origin header to origin to enable withCredentials
* Adding configuration variable matchOriginProtocol
* Fixes location mismatch error in Safari.
* Use tty to detect if we should add colors or not by default.
* Updated the package location.
0.8.7 / 2011-11-05
==================
* Fixed memory leaks in closed clients.
* Fixed memory leaks in namespaces.
* Fixed websocket handling for malformed requests from proxies. [einaros]
* Node 0.6 compatibility. [einaros] [3rd-Eden]
* Adapted tests and examples.
0.8.6 / 2011-10-27
==================
* Added JSON decoding on jsonp-polling transport.
* Fixed README example.
* Major speed optimizations [3rd-Eden] [einaros] [visionmedia]
* Added decode/encode benchmarks [visionmedia]
* Added support for black-listing client sent events.
* Fixed logging options, closes #540 [3rd-Eden]
* Added vary header for gzip [3rd-Eden]
* Properly cleaned up async websocket / flashsocket tests, after patching node-websocket-client
* Patched to properly shut down when a finishClose call is made during connection establishment
* Added support for socket.io version on url and far-future Expires [3rd-Eden] [getify]
* Began IE10 compatibility [einaros] [tbranyen]
* Misc WebSocket fixes [einaros]
* Added UTF8 to respone headers for htmlfile [3rd-Eden]
0.8.5 / 2011-10-07
==================
* Added websocket draft HyBi-16 support. [einaros]
* Fixed websocket continuation bugs. [einaros]
* Fixed flashsocket transport name.
* Fixed websocket tests.
* Ensured `parser#decodePayload` doesn't choke.
* Added http referrer verification to manager verifyOrigin.
* Added access control for cross domain xhr handshakes [3rd-Eden]
* Added support for automatic generation of socket.io files [3rd-Eden]
* Added websocket binary support [einaros]
* Added gzip support for socket.io.js [3rd-Eden]
* Expose socket.transport [3rd-Eden]
* Updated client.
0.8.4 / 2011-09-06
==================
* Client build
0.8.3 / 2011-09-03
==================
* Fixed `\n` parsing for non-JSON packets (fixes #479).
* Fixed parsing of certain unicode characters (fixes #451).
* Fixed transport message packet logging.
* Fixed emission of `error` event resulting in an uncaught exception if unhandled (fixes #476).
* Fixed; allow for falsy values as the configuration value of `log level` (fixes #491).
* Fixed repository URI in `package.json`. Fixes #504.
* Added text/plain content-type to handshake responses [einaros]
* Improved single byte writes [einaros]
* Updated socket.io-flashsocket default port from 843 to 10843 [3rd-Eden]
* Updated client.
0.8.2 / 2011-08-29
==================
* Updated client.
0.8.1 / 2011-08-29
==================
* Fixed utf8 bug in send framing in websocket [einaros]
* Fixed typo in docs [Znarkus]
* Fixed bug in send framing for over 64kB of data in websocket [einaros]
* Corrected ping handling in websocket transport [einaros]
0.8.0 / 2011-08-28
==================
* Updated to work with two-level websocket versioning. [einaros]
* Added hybi07 support. [einaros]
* Added hybi10 support. [einaros]
* Added http referrer verification to manager.js verifyOrigin. [einaors]
0.7.11 / 2011-08-27
===================
* Updated socket.io-client.
0.7.10 / 2011-08-27
===================
* Updated socket.io-client.
0.7.9 / 2011-08-12
==================
* Updated socket.io-client.
* Make sure we only do garbage collection when the server we receive is actually run.
0.7.8 / 2011-08-08
==================
* Changed; make sure sio#listen passes options to both HTTP server and socket.io manager.
* Added docs for sio#listen.
* Added options parameter support for Manager constructor.
* Added memory leaks tests and test-leaks Makefile task.
* Removed auto npm-linking from make test.
* Make sure that you can disable heartbeats. [3rd-Eden]
* Fixed rooms memory leak [3rd-Eden]
* Send response once we got all POST data, not immediately [Pita]
* Fixed onLeave behavior with missing clientsk [3rd-Eden]
* Prevent duplicate references in rooms.
* Added alias for `to` to `in` and `in` to `to`.
* Fixed roomClients definition.
* Removed dependency on redis for installation without npm [3rd-Eden]
* Expose path and querystring in handshakeData [3rd-Eden]
0.7.7 / 2011-07-12
==================
* Fixed double dispatch handling with emit to closed clients.
* Added test for emitting to closed clients to prevent regression.
* Fixed race condition in redis test.
* Changed Transport#end instrumentation.
* Leveraged $emit instead of emit internally.
* Made tests faster.
* Fixed double disconnect events.
* Fixed disconnect logic
* Simplified remote events handling in Socket.
* Increased testcase timeout.
* Fixed unknown room emitting (GH-291). [3rd-Eden]
* Fixed `address` in handshakeData. [3rd-Eden]
* Removed transports definition in chat example.
* Fixed room cleanup
* Fixed; make sure the client is cleaned up after booting.
* Make sure to mark the client as non-open if the connection is closed.
* Removed unneeded `buffer` declarations.
* Fixed; make sure to clear socket handlers and subscriptions upon transport close.
0.7.6 / 2011-06-30
==================
* Fixed general dispatching when a client has closed.
0.7.5 / 2011-06-30
==================
* Fixed dispatching to clients that are disconnected.
0.7.4 / 2011-06-30
==================
* Fixed; only clear handlers if they were set. [level09]
0.7.3 / 2011-06-30
==================
* Exposed handshake data to clients.
* Refactored dispatcher interface.
* Changed; Moved id generation method into the manager.
* Added sub-namespace authorization. [3rd-Eden]
* Changed; normalized SocketNamespace local eventing [dvv]
* Changed; Use packet.reason or default to 'packet' [3rd-Eden]
* Changed console.error to console.log.
* Fixed; bind both servers at the same time do that the test never times out.
* Added 304 support.
* Removed `Transport#name` for abstract interface.
* Changed; lazily require http and https module only when needed. [3rd-Eden]
0.7.2 / 2011-06-22
==================
* Make sure to write a packet (of type `noop`) when closing a poll.
This solves a problem with cross-domain requests being flagged as aborted and
reconnection being triggered.
* Added `noop` message type.
0.7.1 / 2011-06-21
==================
* Fixed cross-domain XHR.
* Added CORS test to xhr-polling suite.
0.7.0 / 2010-06-21
==================
* http://socket.io/announcement.html

22
LICENSE Normal file
View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2014-2018 Automattic <dev@cloudup.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,31 +0,0 @@
ALL_TESTS = $(shell find test/ -name '*.test.js')
ALL_BENCH = $(shell find benchmarks -name '*.bench.js')
run-tests:
@./node_modules/.bin/expresso \
-t 3000 \
-I support \
--serial \
$(TESTFLAGS) \
$(TESTS)
test:
@$(MAKE) NODE_PATH=lib TESTS="$(ALL_TESTS)" run-tests
test-cov:
@TESTFLAGS=--cov $(MAKE) test
test-leaks:
@ls test/leaks/* | xargs node --expose_debug_as=debug --expose_gc
run-bench:
@node $(PROFILEFLAGS) benchmarks/runner.js
bench:
@$(MAKE) BENCHMARKS="$(ALL_BENCH)" run-bench
profile:
@PROFILEFLAGS='--prof --trace-opt --trace-bailout --trace-deopt' $(MAKE) bench
.PHONY: test bench profile

502
Readme.md
View File

@@ -1,345 +1,269 @@
# Socket.IO
# socket.io
[![Run on Repl.it](https://repl.it/badge/github/socketio/socket.io)](https://replit.com/@socketio/socketio-minimal-example)
[![Backers on Open Collective](https://opencollective.com/socketio/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/socketio/sponsors/badge.svg)](#sponsors)
[![Build Status](https://github.com/socketio/socket.io/workflows/CI/badge.svg)](https://github.com/socketio/socket.io/actions)
[![NPM version](https://badge.fury.io/js/socket.io.svg)](https://www.npmjs.com/package/socket.io)
![Downloads](https://img.shields.io/npm/dm/socket.io.svg?style=flat)
[![](https://slackin-socketio.now.sh/badge.svg)](https://slackin-socketio.now.sh)
Socket.IO is a Node.JS project that makes WebSockets and realtime possible in
all browsers. It also enhances WebSockets by providing built-in multiplexing,
horizontal scalability, automatic JSON encoding/decoding, and more.
## Features
## How to Install
Socket.IO enables real-time bidirectional event-based communication. It consists of:
- a Node.js server (this repository)
- a [Javascript client library](https://github.com/socketio/socket.io-client) for the browser (or a Node.js client)
Some implementations in other languages are also available:
- [Java](https://github.com/socketio/socket.io-client-java)
- [C++](https://github.com/socketio/socket.io-client-cpp)
- [Swift](https://github.com/socketio/socket.io-client-swift)
- [Dart](https://github.com/rikulo/socket.io-client-dart)
- [Python](https://github.com/miguelgrinberg/python-socketio)
- [.NET](https://github.com/doghappy/socket.io-client-csharp)
Its main features are:
#### Reliability
Connections are established even in the presence of:
- proxies and load balancers.
- personal firewall and antivirus software.
For this purpose, it relies on [Engine.IO](https://github.com/socketio/engine.io), which first establishes a long-polling connection, then tries to upgrade to better transports that are "tested" on the side, like WebSocket. Please see the [Goals](https://github.com/socketio/engine.io#goals) section for more information.
#### Auto-reconnection support
Unless instructed otherwise a disconnected client will try to reconnect forever, until the server is available again. Please see the available reconnection options [here](https://socket.io/docs/v3/client-api/#new-Manager-url-options).
#### Disconnection detection
A heartbeat mechanism is implemented at the Engine.IO level, allowing both the server and the client to know when the other one is not responding anymore.
That functionality is achieved with timers set on both the server and the client, with timeout values (the `pingInterval` and `pingTimeout` parameters) shared during the connection handshake. Those timers require any subsequent client calls to be directed to the same server, hence the `sticky-session` requirement when using multiples nodes.
#### Binary support
Any serializable data structures can be emitted, including:
- [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) and [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) in the browser
- [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) and [Buffer](https://nodejs.org/api/buffer.html) in Node.js
#### Simple and convenient API
Sample code:
```js
io.on('connection', socket => {
socket.emit('request', /* … */); // emit an event to the socket
io.emit('broadcast', /* … */); // emit an event to all connected sockets
socket.on('reply', () => { /* … */ }); // listen to the event
});
```
#### Cross-browser
Browser support is tested in Sauce Labs:
[![Sauce Test Status](https://saucelabs.com/browser-matrix/socket.svg)](https://saucelabs.com/u/socket)
#### Multiplexing support
In order to create separation of concerns within your application (for example per module, or based on permissions), Socket.IO allows you to create several `Namespaces`, which will act as separate communication channels but will share the same underlying connection.
#### Room support
Within each `Namespace`, you can define arbitrary channels, called `Rooms`, that sockets can join and leave. You can then broadcast to any given room, reaching every socket that has joined it.
This is a useful feature to send notifications to a group of users, or to a given user connected on several devices for example.
**Note:** Socket.IO is not a WebSocket implementation. Although Socket.IO indeed uses WebSocket as a transport when possible, it adds some metadata to each packet: the packet type, the namespace and the ack id when a message acknowledgement is needed. That is why a WebSocket client will not be able to successfully connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a WebSocket server (like `ws://echo.websocket.org`) either. Please see the protocol specification [here](https://github.com/socketio/socket.io-protocol).
## Installation
```bash
// with npm
npm install socket.io
// with yarn
yarn add socket.io
```
## How to use
First, require `socket.io`:
The following example attaches socket.io to a plain Node.JS
HTTP server listening on port `3000`.
```js
var io = require('socket.io');
```
Next, attach it to a HTTP/HTTPS server. If you're using the fantastic `express`
web framework:
```js
var app = express.createServer()
, io = io.listen(app);
app.listen(80);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
const server = require('http').createServer();
const io = require('socket.io')(server);
io.on('connection', client => {
client.on('event', data => { /* … */ });
client.on('disconnect', () => { /* … */ });
});
server.listen(3000);
```
Finally, load it from the client side code:
```html
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
```
For more thorough examples, look at the `examples/` directory.
## Short recipes
### Sending and receiving events.
Socket.IO allows you to emit and receive custom events.
Besides `connect`, `message` and `disconnect`, you can emit custom events:
### Standalone
```js
// note, io.listen(<port>) will create a http server for you
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
io.sockets.emit('this', { will: 'be received by everyone' });
socket.on('private message', function (from, msg) {
console.log('I received a private message by ', from, ' saying ', msg);
});
socket.on('disconnect', function () {
io.sockets.emit('user disconnected');
});
});
const io = require('socket.io')();
io.on('connection', client => { ... });
io.listen(3000);
```
### Storing data associated to a client
Sometimes it's necessary to store data associated with a client that's
necessary for the duration of the session.
#### Server side
### Module syntax
```js
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.on('set nickname', function (name) {
socket.set('nickname', name, function () { socket.emit('ready'); });
});
socket.on('msg', function () {
socket.get('nickname', function (err, name) {
console.log('Chat message by ', name);
});
});
});
import { Server } from "socket.io";
const io = new Server(server);
io.listen(3000);
```
#### Client side
### In conjunction with Express
```html
<script>
var socket = io.connect('http://localhost');
socket.on('connect', function () {
socket.emit('set nickname', confirm('What is your nickname?'));
socket.on('ready', function () {
console.log('Connected !');
socket.emit('msg', confirm('What is your message?'));
});
});
</script>
```
### Restricting yourself to a namespace
If you have control over all the messages and events emitted for a particular
application, using the default `/` namespace works.
If you want to leverage 3rd-party code, or produce code to share with others,
socket.io provides a way of namespacing a `socket`.
This has the benefit of `multiplexing` a single connection. Instead of
socket.io using two `WebSocket` connections, it'll use one.
The following example defines a socket that listens on '/chat' and one for
'/news':
#### Server side
Starting with **3.0**, express applications have become request handler
functions that you pass to `http` or `http` `Server` instances. You need
to pass the `Server` to `socket.io`, and not the express application
function. Also make sure to call `.listen` on the `server`, not the `app`.
```js
var io = require('socket.io').listen(80);
var chat = io
.of('/chat')
.on('connection', function (socket) {
socket.emit('a message', { that: 'only', '/chat': 'will get' });
chat.emit('a message', { everyone: 'in', '/chat': 'will get' });
});
var news = io
.of('/news');
.on('connection', function (socket) {
socket.emit('item', { news: 'item' });
});
const app = require('express')();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
io.on('connection', () => { /* … */ });
server.listen(3000);
```
#### Client side:
### In conjunction with Koa
```html
<script>
var chat = io.connect('http://localhost/chat')
, news = io.connect('http://localhost/news');
chat.on('connect', function () {
chat.emit('hi!');
});
news.on('news', function () {
news.emit('woot');
});
</script>
```
### Sending volatile messages.
Sometimes certain messages can be dropped. Let's say you have an app that
shows realtime tweets for the keyword `bieber`.
If a certain client is not ready to receive messages (because of network slowness
or other issues, or because he's connected through long polling and is in the
middle of a request-response cycle), if he doesn't receive ALL the tweets related
to bieber your application won't suffer.
In that case, you might want to send those messages as volatile messages.
#### Server side
Like Express.JS, Koa works by exposing an application as a request
handler function, but only by calling the `callback` method.
```js
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
var tweets = setInterval(function () {
getBieberTweet(function (tweet) {
socket.volatile.emit('bieber tweet', tweet);
});
}, 100);
socket.on('disconnect', function () {
clearInterval(tweets);
});
});
const app = require('koa')();
const server = require('http').createServer(app.callback());
const io = require('socket.io')(server);
io.on('connection', () => { /* … */ });
server.listen(3000);
```
#### Client side
### In conjunction with Fastify
In the client side, messages are received the same way whether they're volatile
or not.
### Getting acknowledgements
Sometimes, you might want to get a callback when the client confirmed the message
reception.
To do this, simply pass a function as the last parameter of `.send` or `.emit`.
What's more, when you use `.emit`, the acknowledgement is done by you, which
means you can also pass data along:
#### Server side
To integrate Socket.io in your Fastify application you just need to
register `fastify-socket.io` plugin. It will create a `decorator`
called `io`.
```js
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.on('ferret', function (name, fn) {
fn('woot');
});
});
const app = require('fastify')();
app.register(require('fastify-socket.io'));
app.io.on('connection', () => { /* … */ });
app.listen(3000);
```
#### Client side
## Documentation
```html
<script>
var socket = io.connect(); // TIP: .connect with no args does auto-discovery
socket.on('connect', function () { // TIP: you can avoid listening on `connect` and listen on events directly too!
socket.emit('ferret', 'tobi', function (data) {
console.log(data); // data will be 'woot'
});
});
</script>
Please see the documentation [here](https://socket.io/docs/).
The source code of the website can be found [here](https://github.com/socketio/socket.io-website). Contributions are welcome!
## Debug / logging
Socket.IO is powered by [debug](https://github.com/visionmedia/debug).
In order to see all the debug output, run your app with the environment variable
`DEBUG` including the desired scope.
To see the output from all of Socket.IO's debugging scopes you can use:
```
DEBUG=socket.io* node myapp
```
### Broadcasting messages
## Testing
To broadcast, simply add a `broadcast` flag to `emit` and `send` method calls.
Broadcasting means sending a message to everyone else except for the socket
that starts it.
#### Server side
```js
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.broadcast.emit('user connected');
socket.broadcast.json.send({ a: 'message' });
});
```
### Rooms
Sometimes you want to put certain sockets in the same room, so that it's easy
to broadcast to all of them together.
Think of this as built-in channels for sockets. Sockets `join` and `leave`
rooms in each socket.
#### Server side
```js
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.join('justin bieber fans');
socket.broadcast.to('justin bieber fans').emit('new fan');
io.sockets.in('rammstein fans').emit('new non-fan');
});
npm test
```
This runs the `gulp` task `test`. By default the test will be run with the source code in `lib` directory.
### Using it just as a cross-browser WebSocket
Set the environmental variable `TEST_VERSION` to `compat` to test the transpiled es5-compat version of the code.
If you just want the WebSocket semantics, you can do that too.
Simply leverage `send` and listen on the `message` event:
The `gulp` task `test` will always transpile the source code into es5 and export to `dist` first before running the test.
#### Server side
```js
var io = require('socket.io').listen(80);
## Backers
io.sockets.on('connection', function (socket) {
socket.on('message', function () { });
socket.on('disconnect', function () { });
});
```
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/socketio#backer)]
#### Client side
<a href="https://opencollective.com/socketio/backer/0/website" target="_blank"><img src="https://opencollective.com/socketio/backer/0/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/1/website" target="_blank"><img src="https://opencollective.com/socketio/backer/1/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/2/website" target="_blank"><img src="https://opencollective.com/socketio/backer/2/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/3/website" target="_blank"><img src="https://opencollective.com/socketio/backer/3/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/4/website" target="_blank"><img src="https://opencollective.com/socketio/backer/4/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/5/website" target="_blank"><img src="https://opencollective.com/socketio/backer/5/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/6/website" target="_blank"><img src="https://opencollective.com/socketio/backer/6/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/7/website" target="_blank"><img src="https://opencollective.com/socketio/backer/7/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/8/website" target="_blank"><img src="https://opencollective.com/socketio/backer/8/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/9/website" target="_blank"><img src="https://opencollective.com/socketio/backer/9/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/10/website" target="_blank"><img src="https://opencollective.com/socketio/backer/10/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/11/website" target="_blank"><img src="https://opencollective.com/socketio/backer/11/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/12/website" target="_blank"><img src="https://opencollective.com/socketio/backer/12/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/13/website" target="_blank"><img src="https://opencollective.com/socketio/backer/13/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/14/website" target="_blank"><img src="https://opencollective.com/socketio/backer/14/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/15/website" target="_blank"><img src="https://opencollective.com/socketio/backer/15/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/16/website" target="_blank"><img src="https://opencollective.com/socketio/backer/16/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/17/website" target="_blank"><img src="https://opencollective.com/socketio/backer/17/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/18/website" target="_blank"><img src="https://opencollective.com/socketio/backer/18/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/19/website" target="_blank"><img src="https://opencollective.com/socketio/backer/19/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/20/website" target="_blank"><img src="https://opencollective.com/socketio/backer/20/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/21/website" target="_blank"><img src="https://opencollective.com/socketio/backer/21/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/22/website" target="_blank"><img src="https://opencollective.com/socketio/backer/22/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/23/website" target="_blank"><img src="https://opencollective.com/socketio/backer/23/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/24/website" target="_blank"><img src="https://opencollective.com/socketio/backer/24/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/25/website" target="_blank"><img src="https://opencollective.com/socketio/backer/25/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/26/website" target="_blank"><img src="https://opencollective.com/socketio/backer/26/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/27/website" target="_blank"><img src="https://opencollective.com/socketio/backer/27/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/28/website" target="_blank"><img src="https://opencollective.com/socketio/backer/28/avatar.svg"></a>
<a href="https://opencollective.com/socketio/backer/29/website" target="_blank"><img src="https://opencollective.com/socketio/backer/29/avatar.svg"></a>
```html
<script>
var socket = io.connect('http://localhost/');
socket.on('connect', function () {
socket.send('hi');
socket.on('message', function (msg) {
// my msg
});
});
</script>
```
## Sponsors
### Changing configuration
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/socketio#sponsor)]
Configuration in socket.io is TJ-style:
<a href="https://opencollective.com/socketio/sponsor/0/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/1/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/2/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/3/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/4/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/4/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/5/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/5/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/6/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/6/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/7/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/8/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/9/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/9/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/10/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/10/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/11/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/11/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/12/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/12/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/13/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/13/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/14/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/14/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/15/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/15/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/16/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/16/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/17/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/17/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/18/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/18/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/19/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/19/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/20/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/20/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/21/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/21/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/22/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/22/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/23/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/23/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/24/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/24/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/25/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/25/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/26/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/26/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/27/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/27/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/28/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/28/avatar.svg"></a>
<a href="https://opencollective.com/socketio/sponsor/29/website" target="_blank"><img src="https://opencollective.com/socketio/sponsor/29/avatar.svg"></a>
#### Server side
```js
var io = require('socket.io').listen(80);
## License
io.configure(function () {
io.set('transports', ['websocket', 'flashsocket', 'xhr-polling']);
});
io.configure('development', function () {
io.set('transports', ['websocket', 'xhr-polling']);
io.enable('log');
});
```
## License
(The MIT License)
Copyright (c) 2011 Guillermo Rauch &lt;guillermo@learnboost.com&gt;
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[MIT](LICENSE)

View File

@@ -1,64 +0,0 @@
/**
* Module dependencies.
*/
var benchmark = require('benchmark')
, colors = require('colors')
, io = require('../')
, parser = io.parser
, suite = new benchmark.Suite('Decode packet');
suite.add('string', function () {
parser.decodePacket('4:::"2"');
});
suite.add('event', function () {
parser.decodePacket('5:::{"name":"woot"}');
});
suite.add('event+ack', function () {
parser.decodePacket('5:1+::{"name":"tobi"}');
});
suite.add('event+data', function () {
parser.decodePacket('5:::{"name":"edwald","args":[{"a": "b"},2,"3"]}');
});
suite.add('heartbeat', function () {
parser.decodePacket('2:::');
});
suite.add('error', function () {
parser.decodePacket('7:::2+0');
});
var payload = parser.encodePayload([
parser.encodePacket({ type: 'message', data: '5', endpoint: '' })
, parser.encodePacket({ type: 'message', data: '53d', endpoint: '' })
, parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
, parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
, parser.encodePacket({ type: 'message', data: 'foobarbazfoobarbaz', endpoint: '' })
, parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
, parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
]);
suite.add('payload', function () {
parser.decodePayload(payload);
});
suite.on('cycle', function (bench, details) {
console.log('\n' + suite.name.grey, details.name.white.bold);
console.log([
details.hz.toFixed(2).cyan + ' ops/sec'.grey
, details.count.toString().white + ' times executed'.grey
, 'benchmark took '.grey + details.times.elapsed.toString().white + ' sec.'.grey
,
].join(', '.grey));
});
if (!module.parent) {
suite.run();
} else {
module.exports = suite;
}

View File

@@ -1,90 +0,0 @@
/**
* Module dependencies.
*/
var benchmark = require('benchmark')
, colors = require('colors')
, io = require('../')
, parser = io.parser
, suite = new benchmark.Suite('Encode packet');
suite.add('string', function () {
parser.encodePacket({
type: 'json'
, endpoint: ''
, data: '2'
});
});
suite.add('event', function () {
parser.encodePacket({
type: 'event'
, name: 'woot'
, endpoint: ''
, args: []
});
});
suite.add('event+ack', function () {
parser.encodePacket({
type: 'json'
, id: 1
, ack: 'data'
, endpoint: ''
, data: { a: 'b' }
});
});
suite.add('event+data', function () {
parser.encodePacket({
type: 'event'
, name: 'edwald'
, endpoint: ''
, args: [{a: 'b'}, 2, '3']
});
});
suite.add('heartbeat', function () {
parser.encodePacket({
type: 'heartbeat'
, endpoint: ''
})
});
suite.add('error', function () {
parser.encodePacket({
type: 'error'
, reason: 'unauthorized'
, advice: 'reconnect'
, endpoint: ''
})
})
suite.add('payload', function () {
parser.encodePayload([
parser.encodePacket({ type: 'message', data: '5', endpoint: '' })
, parser.encodePacket({ type: 'message', data: '53d', endpoint: '' })
, parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
, parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
, parser.encodePacket({ type: 'message', data: 'foobarbazfoobarbaz', endpoint: '' })
, parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
, parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
]);
});
suite.on('cycle', function (bench, details) {
console.log('\n' + suite.name.grey, details.name.white.bold);
console.log([
details.hz.toFixed(2).cyan + ' ops/sec'.grey
, details.count.toString().white + ' times executed'.grey
, 'benchmark took '.grey + details.times.elapsed.toString().white + ' sec.'.grey
,
].join(', '.grey));
});
if (!module.parent) {
suite.run();
} else {
module.exports = suite;
}

View File

@@ -1,55 +0,0 @@
/**
* Benchmark runner dependencies
*/
var colors = require('colors')
, path = require('path');
/**
* Find all the benchmarks
*/
var benchmarks_files = process.env.BENCHMARKS.split(' ')
, all = [].concat(benchmarks_files)
, first = all.shift()
, benchmarks = {};
// find the benchmarks and load them all in our obj
benchmarks_files.forEach(function (file) {
benchmarks[file] = require(path.join(__dirname, '..', file));
});
// setup the complete listeners
benchmarks_files.forEach(function (file) {
var benchmark = benchmarks[file]
, next_file = all.shift()
, next = benchmarks[next_file];
/**
* Generate a oncomplete function for the tests, either we are done or we
* have more benchmarks to process.
*/
function complete () {
if (!next) {
console.log(
'\n\nBenchmark completed in'.grey
, (Date.now() - start).toString().green + ' ms'.grey
);
} else {
console.log('\nStarting benchmark '.grey + next_file.yellow);
next.run();
}
}
// attach the listener
benchmark.on('complete', complete);
});
/**
* Start the benchmark
*/
var start = Date.now();
console.log('Starting benchmark '.grey + first.yellow);
benchmarks[first].run();

7
client-dist/socket.io.esm.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4440
client-dist/socket.io.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

7
client-dist/socket.io.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

7
client-dist/socket.io.msgpack.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
docs/README.md Normal file
View File

@@ -0,0 +1,2 @@
The documentation has been moved to the website [here](https://socket.io/docs/).

1
examples/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
package-lock.json

View File

@@ -0,0 +1,17 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support
# You can see what browsers were selected by your queries by running:
# npx browserslist
last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.

View File

@@ -0,0 +1,16 @@
# Editor configuration, see https://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.ts]
quote_type = single
[*.md]
max_line_length = off
trim_trailing_whitespace = false

46
examples/angular-todomvc/.gitignore vendored Normal file
View File

@@ -0,0 +1,46 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# Only exists if Bazel was run
/bazel-out
# dependencies
/node_modules
# profiling files
chrome-profiler-events*.json
speed-measure-plugin*.json
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings
# System Files
.DS_Store
Thumbs.db

View File

@@ -0,0 +1,35 @@
# Angular TodoMVC + Socket.IO
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.0.4.
Inspired from the [TodoMVC](http://todomvc.com/) [angular example](https://github.com/tastejs/todomvc/tree/master/examples/angular2).
![demo](assets/demo.gif)
## Development server
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
## Socket.IO server
Run `npm run start:server` to start the Socket.IO server.
## Code scaffolding
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
## Build
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
## Running unit tests
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Running end-to-end tests
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.

View File

@@ -0,0 +1,128 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular-todomvc": {
"projectType": "application",
"schematics": {
"@schematics/angular:application": {
"strict": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/angular-todomvc",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "angular-todomvc:build"
},
"configurations": {
"production": {
"browserTarget": "angular-todomvc:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "angular-todomvc:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "angular-todomvc:serve"
},
"configurations": {
"production": {
"devServerTarget": "angular-todomvc:serve:production"
}
}
}
}
}
},
"defaultProject": "angular-todomvc"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

View File

@@ -0,0 +1,37 @@
// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter');
/**
* @type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
browserName: 'chrome'
},
directConnect: true,
SELENIUM_PROMISE_MANAGER: false,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json')
});
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: StacktraceOption.PRETTY
}
}));
}
};

View File

@@ -0,0 +1,23 @@
import { AppPage } from './app.po';
import { browser, logging } from 'protractor';
describe('workspace-project App', () => {
let page: AppPage;
beforeEach(() => {
page = new AppPage();
});
it('should display welcome message', async () => {
await page.navigateTo();
expect(await page.getTitleText()).toEqual('angular-todomvc app is running!');
});
afterEach(async () => {
// Assert that there are no errors emitted from the browser
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
expect(logs).not.toContain(jasmine.objectContaining({
level: logging.Level.SEVERE,
} as logging.Entry));
});
});

View File

@@ -0,0 +1,11 @@
import { browser, by, element } from 'protractor';
export class AppPage {
async navigateTo(): Promise<unknown> {
return browser.get(browser.baseUrl);
}
async getTitleText(): Promise<string> {
return element(by.css('app-root .content span')).getText();
}
}

View File

@@ -0,0 +1,13 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"target": "es2018",
"types": [
"jasmine",
"node"
]
}
}

View File

@@ -0,0 +1,44 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage/angular-todomvc'),
subdir: '.',
reporters: [
{ type: 'html' },
{ type: 'text-summary' }
]
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};

View File

@@ -0,0 +1,48 @@
{
"name": "angular-todomvc",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"start:server": "ts-node -O '{\"module\":\"commonjs\"}' server.ts"
},
"private": true,
"dependencies": {
"@angular/animations": "~11.0.4",
"@angular/common": "~11.0.4",
"@angular/compiler": "~11.0.4",
"@angular/core": "~11.0.4",
"@angular/forms": "~11.0.4",
"@angular/platform-browser": "~11.0.4",
"@angular/platform-browser-dynamic": "~11.0.4",
"@angular/router": "~11.0.4",
"rxjs": "~6.6.0",
"socket.io": "^4.0.0",
"socket.io-client": "^4.0.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1100.4",
"@angular/cli": "~11.0.4",
"@angular/compiler-cli": "~11.0.4",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.0.2"
}
}

View File

@@ -0,0 +1,28 @@
import { Server } from "socket.io";
const io = new Server(8080, {
cors: {
origin: "http://localhost:4200",
methods: ["GET", "POST"]
}
});
interface Todo {
completed: boolean;
editing: boolean;
title: string;
}
let todos: Array<Todo> = [];
io.on("connect", (socket) => {
socket.emit("todos", todos);
// note: we could also create a CRUD (create/read/update/delete) service for the todo list
socket.on("update-store", (updatedTodos) => {
// store it locally
todos = updatedTodos;
// broadcast to everyone but the sender
socket.broadcast.emit("todos", todos);
});
});

View File

@@ -0,0 +1,23 @@
<section class="todoapp">
<header class="header">
<h1>todos</h1>
<input class="new-todo" placeholder="What needs to be done?" autofocus="" [(ngModel)]="newTodoText" (keyup.enter)="addTodo()">
</header>
<section class="main" *ngIf="todoStore.todos.length > 0">
<input id="toggle-all" class="toggle-all" type="checkbox" *ngIf="todoStore.todos.length" #toggleall [checked]="todoStore.allCompleted()" (click)="todoStore.setAllTo(toggleall.checked)">
<ul class="todo-list">
<li *ngFor="let todo of todoStore.todos" [class.completed]="todo.completed" [class.editing]="todo.editing">
<div class="view">
<input class="toggle" type="checkbox" (click)="toggleCompletion(todo)" [checked]="todo.completed">
<label (dblclick)="editTodo(todo)">{{todo.title}}</label>
<button class="destroy" (click)="remove(todo)"></button>
</div>
<input class="edit" *ngIf="todo.editing" [value]="todo.title" #editedtodo (blur)="stopEditing(todo, editedtodo.value)" (keyup.enter)="updateEditingTodo(todo, editedtodo.value)" (keyup.escape)="cancelEditingTodo(todo)">
</li>
</ul>
</section>
<footer class="footer" *ngIf="todoStore.todos.length > 0">
<span class="todo-count"><strong>{{todoStore.getRemaining().length}}</strong> {{todoStore.getRemaining().length == 1 ? 'item' : 'items'}} left</span>
<button class="clear-completed" *ngIf="todoStore.getCompleted().length > 0" (click)="removeCompleted()">Clear completed</button>
</footer>
</section>

View File

@@ -0,0 +1,31 @@
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(`should have as title 'angular-todomvc'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('angular-todomvc');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('.content span').textContent).toContain('angular-todomvc app is running!');
});
});

View File

@@ -0,0 +1,59 @@
import { Component } from '@angular/core';
import { RemoteTodoStore, Todo } from './store';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
todoStore: RemoteTodoStore;
newTodoText = '';
constructor(todoStore: RemoteTodoStore) {
this.todoStore = todoStore;
}
stopEditing(todo: Todo, editedTitle: string) {
todo.title = editedTitle;
todo.editing = false;
}
cancelEditingTodo(todo: Todo) {
todo.editing = false;
}
updateEditingTodo(todo: Todo, editedTitle: string) {
editedTitle = editedTitle.trim();
todo.editing = false;
if (editedTitle.length === 0) {
return this.todoStore.remove(todo);
}
todo.title = editedTitle;
}
editTodo(todo: Todo) {
todo.editing = true;
}
removeCompleted() {
this.todoStore.removeCompleted();
}
toggleCompletion(todo: Todo) {
this.todoStore.toggleCompletion(todo);
}
remove(todo: Todo){
this.todoStore.remove(todo);
}
addTodo() {
if (this.newTodoText.trim().length) {
this.todoStore.add(this.newTodoText);
this.newTodoText = '';
}
}
}

View File

@@ -0,0 +1,19 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { RemoteTodoStore } from './store';
import { FormsModule } from "@angular/forms";
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [RemoteTodoStore],
bootstrap: [AppComponent]
})
export class AppModule { }

View File

@@ -0,0 +1,95 @@
import { io, Socket } from "socket.io-client";
export class Todo {
completed: boolean;
editing: boolean;
private _title: String = "";
get title() {
return this._title;
}
set title(value: String) {
this._title = value.trim();
}
constructor(title: String) {
this.completed = false;
this.editing = false;
this.title = title.trim();
}
}
export class TodoStore {
todos: Array<Todo>;
constructor() {
let persistedTodos = JSON.parse(localStorage.getItem('angular2-todos') || '[]');
// Normalize back into classes
this.todos = persistedTodos.map( (todo: {_title: String, completed: boolean}) => {
let ret = new Todo(todo._title);
ret.completed = todo.completed;
return ret;
});
}
protected updateStore() {
localStorage.setItem('angular2-todos', JSON.stringify(this.todos));
}
private getWithCompleted(completed: boolean) {
return this.todos.filter((todo: Todo) => todo.completed === completed);
}
allCompleted() {
return this.todos.length === this.getCompleted().length;
}
setAllTo(completed: boolean) {
this.todos.forEach((t: Todo) => t.completed = completed);
this.updateStore();
}
removeCompleted() {
this.todos = this.getWithCompleted(false);
this.updateStore();
}
getRemaining() {
return this.getWithCompleted(false);
}
getCompleted() {
return this.getWithCompleted(true);
}
toggleCompletion(todo: Todo) {
todo.completed = !todo.completed;
this.updateStore();
}
remove(todo: Todo) {
this.todos.splice(this.todos.indexOf(todo), 1);
this.updateStore();
}
add(title: String) {
this.todos.push(new Todo(title));
this.updateStore();
}
}
export class RemoteTodoStore extends TodoStore {
private socket: Socket;
constructor() {
super();
this.socket = io("http://localhost:8080");
this.socket.on("todos", (updatedTodos: Array<Todo>) => {
this.todos = updatedTodos;
});
}
protected updateStore() {
this.socket.emit("update-store", this.todos.map(({ title, editing, completed }) => ({ title, editing, completed })));
}
}

View File

@@ -0,0 +1,3 @@
export const environment = {
production: true
};

View File

@@ -0,0 +1,16 @@
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false
};
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Angular Todo MVC</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>

View File

@@ -0,0 +1,12 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));

View File

@@ -0,0 +1,63 @@
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
*/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
* because those flags need to be set before `zone.js` being loaded, and webpack
* will put import in the top of bundle, so user need to create a separate file
* in this directory (for example: zone-flags.ts), and put the following flags
* into that file, and then add the following code before importing zone.js.
* import './zone-flags';
*
* The flags allowed in zone-flags.ts are listed here.
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*
* (window as any).__Zone_enable_cross_context_check = true;
*
*/
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/

View File

@@ -0,0 +1,381 @@
/* imported from node_modules/todomvc-app-css/index.css */
html,
body {
margin: 0;
padding: 0;
}
button {
margin: 0;
padding: 0;
border: 0;
background: none;
font-size: 100%;
vertical-align: baseline;
font-family: inherit;
font-weight: inherit;
color: inherit;
-webkit-appearance: none;
appearance: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
line-height: 1.4em;
background: #f5f5f5;
color: #111111;
min-width: 230px;
max-width: 550px;
margin: 0 auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-weight: 300;
}
:focus {
outline: 0;
}
.hidden {
display: none;
}
.todoapp {
background: #fff;
margin: 130px 0 40px 0;
position: relative;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2),
0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
.todoapp input::-webkit-input-placeholder {
font-style: italic;
font-weight: 300;
color: rgba(0, 0, 0, 0.4);
}
.todoapp input::-moz-placeholder {
font-style: italic;
font-weight: 300;
color: rgba(0, 0, 0, 0.4);
}
.todoapp input::input-placeholder {
font-style: italic;
font-weight: 300;
color: rgba(0, 0, 0, 0.4);
}
.todoapp h1 {
position: absolute;
top: -140px;
width: 100%;
font-size: 80px;
font-weight: 200;
text-align: center;
color: #b83f45;
-webkit-text-rendering: optimizeLegibility;
-moz-text-rendering: optimizeLegibility;
text-rendering: optimizeLegibility;
}
.new-todo,
.edit {
position: relative;
margin: 0;
width: 100%;
font-size: 24px;
font-family: inherit;
font-weight: inherit;
line-height: 1.4em;
color: inherit;
padding: 6px;
border: 1px solid #999;
box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.new-todo {
padding: 16px 16px 16px 60px;
border: none;
background: rgba(0, 0, 0, 0.003);
box-shadow: inset 0 -2px 1px rgba(0,0,0,0.03);
}
.main {
position: relative;
z-index: 2;
border-top: 1px solid #e6e6e6;
}
.toggle-all {
width: 1px;
height: 1px;
border: none; /* Mobile Safari */
opacity: 0;
position: absolute;
right: 100%;
bottom: 100%;
}
.toggle-all + label {
width: 60px;
height: 34px;
font-size: 0;
position: absolute;
top: -52px;
left: -13px;
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
.toggle-all + label:before {
content: '';
font-size: 22px;
color: #e6e6e6;
padding: 10px 27px 10px 27px;
}
.toggle-all:checked + label:before {
color: #737373;
}
.todo-list {
margin: 0;
padding: 0;
list-style: none;
}
.todo-list li {
position: relative;
font-size: 24px;
border-bottom: 1px solid #ededed;
}
.todo-list li:last-child {
border-bottom: none;
}
.todo-list li.editing {
border-bottom: none;
padding: 0;
}
.todo-list li.editing .edit {
display: block;
width: calc(100% - 43px);
padding: 12px 16px;
margin: 0 0 0 43px;
}
.todo-list li.editing .view {
display: none;
}
.todo-list li .toggle {
text-align: center;
width: 40px;
/* auto, since non-WebKit browsers doesn't support input styling */
height: auto;
position: absolute;
top: 0;
bottom: 0;
margin: auto 0;
border: none; /* Mobile Safari */
-webkit-appearance: none;
appearance: none;
}
.todo-list li .toggle {
opacity: 0;
}
.todo-list li .toggle + label {
/*
Firefox requires `#` to be escaped - https://bugzilla.mozilla.org/show_bug.cgi?id=922433
IE and Edge requires *everything* to be escaped to render, so we do that instead of just the `#` - https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7157459/
*/
background-image: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23ededed%22%20stroke-width%3D%223%22/%3E%3C/svg%3E');
background-repeat: no-repeat;
background-position: center left;
}
.todo-list li .toggle:checked + label {
background-image: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23bddad5%22%20stroke-width%3D%223%22/%3E%3Cpath%20fill%3D%22%235dc2af%22%20d%3D%22M72%2025L42%2071%2027%2056l-4%204%2020%2020%2034-52z%22/%3E%3C/svg%3E');
}
.todo-list li label {
word-break: break-all;
padding: 15px 15px 15px 60px;
display: block;
line-height: 1.2;
transition: color 0.4s;
font-weight: 400;
color: #4d4d4d;
}
.todo-list li.completed label {
color: #cdcdcd;
text-decoration: line-through;
}
.todo-list li .destroy {
display: none;
position: absolute;
top: 0;
right: 10px;
bottom: 0;
width: 40px;
height: 40px;
margin: auto 0;
font-size: 30px;
color: #cc9a9a;
margin-bottom: 11px;
transition: color 0.2s ease-out;
}
.todo-list li .destroy:hover {
color: #af5b5e;
}
.todo-list li .destroy:after {
content: '×';
}
.todo-list li:hover .destroy {
display: block;
}
.todo-list li .edit {
display: none;
}
.todo-list li.editing:last-child {
margin-bottom: -1px;
}
.footer {
padding: 10px 15px;
height: 20px;
text-align: center;
font-size: 15px;
border-top: 1px solid #e6e6e6;
}
.footer:before {
content: '';
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 50px;
overflow: hidden;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2),
0 8px 0 -3px #f6f6f6,
0 9px 1px -3px rgba(0, 0, 0, 0.2),
0 16px 0 -6px #f6f6f6,
0 17px 2px -6px rgba(0, 0, 0, 0.2);
}
.todo-count {
float: left;
text-align: left;
}
.todo-count strong {
font-weight: 300;
}
.filters {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
right: 0;
left: 0;
}
.filters li {
display: inline;
}
.filters li a {
color: inherit;
margin: 3px;
padding: 3px 7px;
text-decoration: none;
border: 1px solid transparent;
border-radius: 3px;
}
.filters li a:hover {
border-color: rgba(175, 47, 47, 0.1);
}
.filters li a.selected {
border-color: rgba(175, 47, 47, 0.2);
}
.clear-completed,
html .clear-completed:active {
float: right;
position: relative;
line-height: 20px;
text-decoration: none;
cursor: pointer;
}
.clear-completed:hover {
text-decoration: underline;
}
.info {
margin: 65px auto 0;
color: #4d4d4d;
font-size: 11px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
text-align: center;
}
.info p {
line-height: 1;
}
.info a {
color: inherit;
text-decoration: none;
font-weight: 400;
}
.info a:hover {
text-decoration: underline;
}
/*
Hack to remove background from Mobile Safari.
Can't use it globally since it destroys checkboxes in Firefox
*/
@media screen and (-webkit-min-device-pixel-ratio:0) {
.toggle-all,
.todo-list li .toggle {
background: none;
}
.todo-list li .toggle {
height: 40px;
}
}
@media (max-width: 430px) {
.footer {
height: 50px;
}
.filters {
bottom: 10px;
}
}

View File

@@ -0,0 +1,25 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
keys(): string[];
<T>(id: string): T;
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

View File

@@ -0,0 +1,15 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": []
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}

View File

@@ -0,0 +1,29 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}

View File

@@ -0,0 +1,18 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"jasmine"
]
},
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}

View File

@@ -0,0 +1,152 @@
{
"extends": "tslint:recommended",
"rulesDirectory": [
"codelyzer"
],
"rules": {
"align": {
"options": [
"parameters",
"statements"
]
},
"array-type": false,
"arrow-return-shorthand": true,
"curly": true,
"deprecation": {
"severity": "warning"
},
"eofline": true,
"import-blacklist": [
true,
"rxjs/Rx"
],
"import-spacing": true,
"indent": {
"options": [
"spaces"
]
},
"max-classes-per-file": false,
"max-line-length": [
true,
140
],
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-empty": false,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-non-null-assertion": true,
"no-redundant-jsdoc": true,
"no-switch-case-fall-through": true,
"no-var-requires": false,
"object-literal-key-quotes": [
true,
"as-needed"
],
"quotemark": [
true,
"single"
],
"semicolon": {
"options": [
"always"
]
},
"space-before-function-paren": {
"options": {
"anonymous": "never",
"asyncArrow": "always",
"constructor": "never",
"method": "never",
"named": "never"
}
},
"typedef": [
true,
"call-signature"
],
"typedef-whitespace": {
"options": [
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
},
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
]
},
"variable-name": {
"options": [
"ban-keywords",
"check-format",
"allow-pascal-case"
]
},
"whitespace": {
"options": [
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type",
"check-typecast"
]
},
"component-class-suffix": true,
"contextual-lifecycle": true,
"directive-class-suffix": true,
"no-conflicting-lifecycle": true,
"no-host-metadata-property": true,
"no-input-rename": true,
"no-inputs-metadata-property": true,
"no-output-native": true,
"no-output-on-prefix": true,
"no-output-rename": true,
"no-outputs-metadata-property": true,
"template-banana-in-box": true,
"template-no-negated-async": true,
"use-lifecycle-interface": true,
"use-pipe-transform-interface": true,
"directive-selector": [
true,
"attribute",
"app",
"camelCase"
],
"component-selector": [
true,
"element",
"app",
"kebab-case"
]
}
}

View File

@@ -0,0 +1,26 @@
# Basic CRUD application with Socket.IO
Please read the related [guide](https://socket.io/get-started/basic-crud-application/).
This repository contains several implementations of the server:
| Directory | Language | Database | Cluster? |
|----------------------------|------------|------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
| `server/` | TypeScript | in-memory | No |
| `server-postgres-cluster/` | JavaScript | Postgres, with the [Postgres adapter](https://socket.io/docs/v4/postgres-adapter/) | Yes, with the [`@socket.io/sticky`](https://github.com/socketio/socket.io-sticky) module) |
## Running the frontend
```
cd angular-client
npm install
npm start
```
### Running the server
```
cd server
npm install
npm start
```

View File

@@ -0,0 +1,17 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support
# You can see what browsers were selected by your queries by running:
# npx browserslist
last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.

View File

@@ -0,0 +1,16 @@
# Editor configuration, see https://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.ts]
quote_type = single
[*.md]
max_line_length = off
trim_trailing_whitespace = false

View File

@@ -0,0 +1,46 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# Only exists if Bazel was run
/bazel-out
# dependencies
/node_modules
# profiling files
chrome-profiler-events*.json
speed-measure-plugin*.json
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings
# System Files
.DS_Store
Thumbs.db

View File

@@ -0,0 +1,31 @@
# Angular TodoMVC + Socket.IO
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.0.4.
Inspired from the [TodoMVC](http://todomvc.com/) [angular example](https://github.com/tastejs/todomvc/tree/master/examples/angular2).
![demo](assets/demo.gif)
## Development server
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
## Code scaffolding
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
## Build
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
## Running unit tests
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Running end-to-end tests
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.

View File

@@ -0,0 +1,128 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular-todomvc": {
"projectType": "application",
"schematics": {
"@schematics/angular:application": {
"strict": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/angular-todomvc",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "angular-todomvc:build"
},
"configurations": {
"production": {
"browserTarget": "angular-todomvc:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "angular-todomvc:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "angular-todomvc:serve"
},
"configurations": {
"production": {
"devServerTarget": "angular-todomvc:serve:production"
}
}
}
}
}
},
"defaultProject": "angular-todomvc"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

View File

@@ -0,0 +1,37 @@
// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter');
/**
* @type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
browserName: 'chrome'
},
directConnect: true,
SELENIUM_PROMISE_MANAGER: false,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json')
});
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: StacktraceOption.PRETTY
}
}));
}
};

View File

@@ -0,0 +1,23 @@
import { AppPage } from './app.po';
import { browser, logging } from 'protractor';
describe('workspace-project App', () => {
let page: AppPage;
beforeEach(() => {
page = new AppPage();
});
it('should display welcome message', async () => {
await page.navigateTo();
expect(await page.getTitleText()).toEqual('angular-todomvc app is running!');
});
afterEach(async () => {
// Assert that there are no errors emitted from the browser
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
expect(logs).not.toContain(jasmine.objectContaining({
level: logging.Level.SEVERE,
} as logging.Entry));
});
});

View File

@@ -0,0 +1,11 @@
import { browser, by, element } from 'protractor';
export class AppPage {
async navigateTo(): Promise<unknown> {
return browser.get(browser.baseUrl);
}
async getTitleText(): Promise<string> {
return element(by.css('app-root .content span')).getText();
}
}

View File

@@ -0,0 +1,13 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"target": "es2018",
"types": [
"jasmine",
"node"
]
}
}

View File

@@ -0,0 +1,44 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage/angular-todomvc'),
subdir: '.',
reporters: [
{ type: 'html' },
{ type: 'text-summary' }
]
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};

View File

@@ -0,0 +1,46 @@
{
"name": "angular-todomvc",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~11.0.4",
"@angular/common": "~11.0.4",
"@angular/compiler": "~11.0.4",
"@angular/core": "~11.0.4",
"@angular/forms": "~11.0.4",
"@angular/platform-browser": "~11.0.4",
"@angular/platform-browser-dynamic": "~11.0.4",
"@angular/router": "~11.0.4",
"rxjs": "~6.6.0",
"socket.io-client": "^4.0.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1100.4",
"@angular/cli": "~11.0.4",
"@angular/compiler-cli": "~11.0.4",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.0.2"
}
}

View File

@@ -0,0 +1,23 @@
<section class="todoapp">
<header class="header">
<h1>todos</h1>
<input class="new-todo" placeholder="What needs to be done?" autofocus="" [(ngModel)]="newTodoText" (keyup.enter)="addTodo()">
</header>
<section class="main" *ngIf="todoStore.todos.length > 0">
<input id="toggle-all" class="toggle-all" type="checkbox" *ngIf="todoStore.todos.length" #toggleall [checked]="todoStore.allCompleted()" (click)="todoStore.setAllTo(toggleall.checked)">
<ul class="todo-list">
<li *ngFor="let todo of todoStore.todos" [class.completed]="todo.completed" [class.editing]="todo.editing">
<div class="view">
<input class="toggle" type="checkbox" (click)="toggleCompletion(todo)" [checked]="todo.completed">
<label (dblclick)="editTodo(todo)">{{todo.title}}</label>
<button class="destroy" (click)="remove(todo)"></button>
</div>
<input class="edit" *ngIf="todo.editing" [value]="todo.title" #editedtodo (blur)="stopEditing(todo, editedtodo.value)" (keyup.enter)="updateEditingTodo(todo, editedtodo.value)" (keyup.escape)="cancelEditingTodo(todo)">
</li>
</ul>
</section>
<footer class="footer" *ngIf="todoStore.todos.length > 0">
<span class="todo-count"><strong>{{todoStore.getRemaining().length}}</strong> {{todoStore.getRemaining().length == 1 ? 'item' : 'items'}} left</span>
<button class="clear-completed" *ngIf="todoStore.getCompleted().length > 0" (click)="removeCompleted()">Clear completed</button>
</footer>
</section>

View File

@@ -0,0 +1,31 @@
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(`should have as title 'angular-todomvc'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('angular-todomvc');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('.content span').textContent).toContain('angular-todomvc app is running!');
});
});

View File

@@ -0,0 +1,59 @@
import { Component } from '@angular/core';
import { TodoStore, Todo } from './store';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
todoStore: TodoStore;
newTodoText = '';
constructor(todoStore: TodoStore) {
this.todoStore = todoStore;
}
stopEditing(todo: Todo, editedTitle: string) {
todo.title = editedTitle;
todo.editing = false;
}
cancelEditingTodo(todo: Todo) {
todo.editing = false;
}
updateEditingTodo(todo: Todo, editedTitle: string) {
editedTitle = editedTitle.trim();
todo.editing = false;
if (editedTitle.length === 0) {
return this.todoStore.remove(todo);
}
todo.title = editedTitle;
}
editTodo(todo: Todo) {
todo.editing = true;
}
removeCompleted() {
this.todoStore.removeCompleted();
}
toggleCompletion(todo: Todo) {
this.todoStore.toggleCompletion(todo);
}
remove(todo: Todo){
this.todoStore.remove(todo);
}
addTodo() {
if (this.newTodoText.trim().length) {
this.todoStore.add(this.newTodoText);
this.newTodoText = '';
}
}
}

View File

@@ -0,0 +1,19 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { TodoStore } from './store';
import { FormsModule } from "@angular/forms";
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [TodoStore],
bootstrap: [AppComponent]
})
export class AppModule { }

View File

@@ -0,0 +1,140 @@
import { io, Socket } from "socket.io-client";
import { ClientEvents, ServerEvents } from "../../../server/lib/events";
import { environment } from '../environments/environment';
export interface Todo {
id: string,
title: string,
completed: boolean,
editing: boolean,
synced: boolean
}
const mapTodo = (todo: any) => {
return {
...todo,
editing: false,
synced: true
}
}
export class TodoStore {
public todos: Array<Todo> = [];
private socket: Socket<ServerEvents, ClientEvents>;
constructor() {
this.socket = io(environment.serverUrl);
this.socket.on("connect", () => {
this.socket.emit("todo:list", (res) => {
if ("error" in res) {
// handle the error
return;
}
this.todos = res.data.map(mapTodo);
});
});
this.socket.on("todo:created", (todo) => {
this.todos.push(mapTodo(todo));
});
this.socket.on("todo:updated", (todo) => {
const existingTodo = this.todos.find(t => {
return t.id === todo.id
});
if (existingTodo) {
existingTodo.title = todo.title;
existingTodo.completed = todo.completed;
}
});
this.socket.on("todo:deleted", (id) => {
const index = this.todos.findIndex(t => {
return t.id === id
});
if (index !== -1) {
this.todos.splice(index, 1);
}
})
}
private getWithCompleted(completed: boolean) {
return this.todos.filter((todo: Todo) => todo.completed === completed);
}
allCompleted() {
return this.todos.length === this.getCompleted().length;
}
setAllTo(completed: boolean) {
this.todos.forEach(todo => {
todo.completed = completed;
todo.synced = false;
this.socket.emit("todo:update", todo, (res) => {
if (res && "error" in res) {
// handle the error
return;
}
todo.synced = true;
});
});
}
removeCompleted() {
this.getCompleted().forEach((todo) => {
this.socket.emit("todo:delete", todo.id, (res) => {
if (res && "error" in res) {
// handle the error
}
});
})
this.todos = this.getRemaining();
}
getRemaining() {
return this.getWithCompleted(false);
}
getCompleted() {
return this.getWithCompleted(true);
}
toggleCompletion(todo: Todo) {
todo.completed = !todo.completed;
todo.synced = false;
this.socket.emit("todo:update", todo, (res) => {
if (res && "error" in res) {
// handle the error
return;
}
todo.synced = true;
})
}
remove(todo: Todo) {
this.todos.splice(this.todos.indexOf(todo), 1);
this.socket.emit("todo:delete", todo.id, (res) => {
if (res && "error" in res) {
// handle the error
}
});
}
add(title: string) {
this.socket.emit("todo:create", { title, completed: false }, (res) => {
if ("error" in res) {
// handle the error
return;
}
this.todos.push({
id: res.data,
title,
completed: false,
editing: false,
synced: true
});
});
}
}

View File

@@ -0,0 +1,4 @@
export const environment = {
production: true,
serverUrl: "https://my-custom-domain.com"
};

View File

@@ -0,0 +1,17 @@
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false,
serverUrl: "http://localhost:3000"
};
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Angular Todo MVC</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>

View File

@@ -0,0 +1,12 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));

View File

@@ -0,0 +1,63 @@
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
*/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
* because those flags need to be set before `zone.js` being loaded, and webpack
* will put import in the top of bundle, so user need to create a separate file
* in this directory (for example: zone-flags.ts), and put the following flags
* into that file, and then add the following code before importing zone.js.
* import './zone-flags';
*
* The flags allowed in zone-flags.ts are listed here.
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*
* (window as any).__Zone_enable_cross_context_check = true;
*
*/
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/

View File

@@ -0,0 +1,381 @@
/* imported from node_modules/todomvc-app-css/index.css */
html,
body {
margin: 0;
padding: 0;
}
button {
margin: 0;
padding: 0;
border: 0;
background: none;
font-size: 100%;
vertical-align: baseline;
font-family: inherit;
font-weight: inherit;
color: inherit;
-webkit-appearance: none;
appearance: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
line-height: 1.4em;
background: #f5f5f5;
color: #111111;
min-width: 230px;
max-width: 550px;
margin: 0 auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-weight: 300;
}
:focus {
outline: 0;
}
.hidden {
display: none;
}
.todoapp {
background: #fff;
margin: 130px 0 40px 0;
position: relative;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2),
0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
.todoapp input::-webkit-input-placeholder {
font-style: italic;
font-weight: 300;
color: rgba(0, 0, 0, 0.4);
}
.todoapp input::-moz-placeholder {
font-style: italic;
font-weight: 300;
color: rgba(0, 0, 0, 0.4);
}
.todoapp input::input-placeholder {
font-style: italic;
font-weight: 300;
color: rgba(0, 0, 0, 0.4);
}
.todoapp h1 {
position: absolute;
top: -140px;
width: 100%;
font-size: 80px;
font-weight: 200;
text-align: center;
color: #b83f45;
-webkit-text-rendering: optimizeLegibility;
-moz-text-rendering: optimizeLegibility;
text-rendering: optimizeLegibility;
}
.new-todo,
.edit {
position: relative;
margin: 0;
width: 100%;
font-size: 24px;
font-family: inherit;
font-weight: inherit;
line-height: 1.4em;
color: inherit;
padding: 6px;
border: 1px solid #999;
box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.new-todo {
padding: 16px 16px 16px 60px;
border: none;
background: rgba(0, 0, 0, 0.003);
box-shadow: inset 0 -2px 1px rgba(0,0,0,0.03);
}
.main {
position: relative;
z-index: 2;
border-top: 1px solid #e6e6e6;
}
.toggle-all {
width: 1px;
height: 1px;
border: none; /* Mobile Safari */
opacity: 0;
position: absolute;
right: 100%;
bottom: 100%;
}
.toggle-all + label {
width: 60px;
height: 34px;
font-size: 0;
position: absolute;
top: -52px;
left: -13px;
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
.toggle-all + label:before {
content: '';
font-size: 22px;
color: #e6e6e6;
padding: 10px 27px 10px 27px;
}
.toggle-all:checked + label:before {
color: #737373;
}
.todo-list {
margin: 0;
padding: 0;
list-style: none;
}
.todo-list li {
position: relative;
font-size: 24px;
border-bottom: 1px solid #ededed;
}
.todo-list li:last-child {
border-bottom: none;
}
.todo-list li.editing {
border-bottom: none;
padding: 0;
}
.todo-list li.editing .edit {
display: block;
width: calc(100% - 43px);
padding: 12px 16px;
margin: 0 0 0 43px;
}
.todo-list li.editing .view {
display: none;
}
.todo-list li .toggle {
text-align: center;
width: 40px;
/* auto, since non-WebKit browsers doesn't support input styling */
height: auto;
position: absolute;
top: 0;
bottom: 0;
margin: auto 0;
border: none; /* Mobile Safari */
-webkit-appearance: none;
appearance: none;
}
.todo-list li .toggle {
opacity: 0;
}
.todo-list li .toggle + label {
/*
Firefox requires `#` to be escaped - https://bugzilla.mozilla.org/show_bug.cgi?id=922433
IE and Edge requires *everything* to be escaped to render, so we do that instead of just the `#` - https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7157459/
*/
background-image: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23ededed%22%20stroke-width%3D%223%22/%3E%3C/svg%3E');
background-repeat: no-repeat;
background-position: center left;
}
.todo-list li .toggle:checked + label {
background-image: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23bddad5%22%20stroke-width%3D%223%22/%3E%3Cpath%20fill%3D%22%235dc2af%22%20d%3D%22M72%2025L42%2071%2027%2056l-4%204%2020%2020%2034-52z%22/%3E%3C/svg%3E');
}
.todo-list li label {
word-break: break-all;
padding: 15px 15px 15px 60px;
display: block;
line-height: 1.2;
transition: color 0.4s;
font-weight: 400;
color: #4d4d4d;
}
.todo-list li.completed label {
color: #cdcdcd;
text-decoration: line-through;
}
.todo-list li .destroy {
display: none;
position: absolute;
top: 0;
right: 10px;
bottom: 0;
width: 40px;
height: 40px;
margin: auto 0;
font-size: 30px;
color: #cc9a9a;
margin-bottom: 11px;
transition: color 0.2s ease-out;
}
.todo-list li .destroy:hover {
color: #af5b5e;
}
.todo-list li .destroy:after {
content: '×';
}
.todo-list li:hover .destroy {
display: block;
}
.todo-list li .edit {
display: none;
}
.todo-list li.editing:last-child {
margin-bottom: -1px;
}
.footer {
padding: 10px 15px;
height: 20px;
text-align: center;
font-size: 15px;
border-top: 1px solid #e6e6e6;
}
.footer:before {
content: '';
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 50px;
overflow: hidden;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2),
0 8px 0 -3px #f6f6f6,
0 9px 1px -3px rgba(0, 0, 0, 0.2),
0 16px 0 -6px #f6f6f6,
0 17px 2px -6px rgba(0, 0, 0, 0.2);
}
.todo-count {
float: left;
text-align: left;
}
.todo-count strong {
font-weight: 300;
}
.filters {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
right: 0;
left: 0;
}
.filters li {
display: inline;
}
.filters li a {
color: inherit;
margin: 3px;
padding: 3px 7px;
text-decoration: none;
border: 1px solid transparent;
border-radius: 3px;
}
.filters li a:hover {
border-color: rgba(175, 47, 47, 0.1);
}
.filters li a.selected {
border-color: rgba(175, 47, 47, 0.2);
}
.clear-completed,
html .clear-completed:active {
float: right;
position: relative;
line-height: 20px;
text-decoration: none;
cursor: pointer;
}
.clear-completed:hover {
text-decoration: underline;
}
.info {
margin: 65px auto 0;
color: #4d4d4d;
font-size: 11px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
text-align: center;
}
.info p {
line-height: 1;
}
.info a {
color: inherit;
text-decoration: none;
font-weight: 400;
}
.info a:hover {
text-decoration: underline;
}
/*
Hack to remove background from Mobile Safari.
Can't use it globally since it destroys checkboxes in Firefox
*/
@media screen and (-webkit-min-device-pixel-ratio:0) {
.toggle-all,
.todo-list li .toggle {
background: none;
}
.todo-list li .toggle {
height: 40px;
}
}
@media (max-width: 430px) {
.footer {
height: 50px;
}
.filters {
bottom: 10px;
}
}

View File

@@ -0,0 +1,25 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
keys(): string[];
<T>(id: string): T;
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

View File

@@ -0,0 +1,15 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": []
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}

View File

@@ -0,0 +1,29 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}

View File

@@ -0,0 +1,18 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"jasmine"
]
},
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}

View File

@@ -0,0 +1,152 @@
{
"extends": "tslint:recommended",
"rulesDirectory": [
"codelyzer"
],
"rules": {
"align": {
"options": [
"parameters",
"statements"
]
},
"array-type": false,
"arrow-return-shorthand": true,
"curly": true,
"deprecation": {
"severity": "warning"
},
"eofline": true,
"import-blacklist": [
true,
"rxjs/Rx"
],
"import-spacing": true,
"indent": {
"options": [
"spaces"
]
},
"max-classes-per-file": false,
"max-line-length": [
true,
140
],
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-empty": false,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-non-null-assertion": true,
"no-redundant-jsdoc": true,
"no-switch-case-fall-through": true,
"no-var-requires": false,
"object-literal-key-quotes": [
true,
"as-needed"
],
"quotemark": [
true,
"single"
],
"semicolon": {
"options": [
"always"
]
},
"space-before-function-paren": {
"options": {
"anonymous": "never",
"asyncArrow": "always",
"constructor": "never",
"method": "never",
"named": "never"
}
},
"typedef": [
true,
"call-signature"
],
"typedef-whitespace": {
"options": [
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
},
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
]
},
"variable-name": {
"options": [
"ban-keywords",
"check-format",
"allow-pascal-case"
]
},
"whitespace": {
"options": [
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type",
"check-typecast"
]
},
"component-class-suffix": true,
"contextual-lifecycle": true,
"directive-class-suffix": true,
"no-conflicting-lifecycle": true,
"no-host-metadata-property": true,
"no-input-rename": true,
"no-inputs-metadata-property": true,
"no-output-native": true,
"no-output-on-prefix": true,
"no-output-rename": true,
"no-outputs-metadata-property": true,
"template-banana-in-box": true,
"template-no-negated-async": true,
"use-lifecycle-interface": true,
"use-pipe-transform-interface": true,
"directive-selector": [
true,
"attribute",
"app",
"camelCase"
],
"component-selector": [
true,
"element",
"app",
"kebab-case"
]
}
}

View File

@@ -0,0 +1,16 @@
A basic TODO project.
| Characteristic | |
|----------------|-------------------------------------------------------------------------------------------|
| Language | plain JavaScript |
| Database | Postgres, with the [Postgres adapter](https://socket.io/docs/v4/postgres-adapter/) |
| Cluster? | Yes, with the [`@socket.io/sticky`](https://github.com/socketio/socket.io-sticky) module) |
## Usage
```
$ docker-compose up -d
$ npm install
$ npm start
```

View File

@@ -0,0 +1,9 @@
version: "3"
services:
postgres:
image: postgres:12
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: "changeit"

View File

@@ -0,0 +1,26 @@
import { Server } from "socket.io";
import createTodoHandlers from "./todo-management/todo.handlers.js";
import { setupWorker } from "@socket.io/sticky";
import { createAdapter } from "@socket.io/postgres-adapter";
export function createApplication(httpServer, components, serverOptions = {}) {
const io = new Server(httpServer, serverOptions);
const { createTodo, readTodo, updateTodo, deleteTodo, listTodo } =
createTodoHandlers(components);
io.on("connection", (socket) => {
socket.on("todo:create", createTodo);
socket.on("todo:read", readTodo);
socket.on("todo:update", updateTodo);
socket.on("todo:delete", deleteTodo);
socket.on("todo:list", listTodo);
});
// enable sticky session in the cluster (to remove in standalone mode)
setupWorker(io);
io.adapter(createAdapter(components.connectionPool));
return io;
}

View File

@@ -0,0 +1,28 @@
import cluster from "cluster";
import { createServer } from "http";
import { setupMaster } from "@socket.io/sticky";
import { cpus } from "os";
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
const httpServer = createServer();
setupMaster(httpServer, {
loadBalancingMethod: "least-connection",
});
httpServer.listen(3000);
for (let i = 0; i < cpus().length; i++) {
cluster.fork();
}
cluster.on("exit", (worker) => {
console.log(`Worker ${worker.process.pid} died`);
cluster.fork();
});
} else {
console.log(`Worker ${process.pid} started`);
import("./index.js");
}

View File

@@ -0,0 +1,51 @@
import { createServer } from "http";
import { createApplication } from "./app.js";
import { Sequelize } from "sequelize";
import pg from "pg";
import { PostgresTodoRepository } from "./todo-management/todo.repository.js";
const httpServer = createServer();
const sequelize = new Sequelize("postgres", "postgres", "changeit", {
dialect: "postgres",
});
const connectionPool = new pg.Pool({
user: "postgres",
host: "localhost",
database: "postgres",
password: "changeit",
port: 5432,
});
createApplication(
httpServer,
{
connectionPool,
todoRepository: new PostgresTodoRepository(sequelize),
},
{
cors: {
origin: ["http://localhost:4200"],
},
}
);
const main = async () => {
// create the tables if they do not exist already
await sequelize.sync();
// create the table needed by the postgres adapter
await connectionPool.query(`
CREATE TABLE IF NOT EXISTS socket_io_attachments (
id bigserial UNIQUE,
created_at timestamptz DEFAULT NOW(),
payload bytea
);
`);
// uncomment when running in standalone mode
// httpServer.listen(3000);
};
main();

View File

@@ -0,0 +1,140 @@
import { Errors, mapErrorDetails, sanitizeErrorMessage } from "../util.js";
import { v4 as uuid } from "uuid";
import Joi from "joi";
const idSchema = Joi.string().guid({
version: "uuidv4",
});
const todoSchema = Joi.object({
id: idSchema.alter({
create: (schema) => schema.forbidden(),
update: (schema) => schema.required(),
}),
title: Joi.string().max(256).required(),
completed: Joi.boolean().required(),
});
export default function (components) {
const { todoRepository } = components;
return {
createTodo: async function (payload, callback) {
const socket = this;
// validate the payload
const { error, value } = todoSchema.tailor("create").validate(payload, {
abortEarly: false,
stripUnknown: true,
});
if (error) {
return callback({
error: Errors.INVALID_PAYLOAD,
errorDetails: mapErrorDetails(error.details),
});
}
value.id = uuid();
// persist the entity
try {
await todoRepository.save(value);
} catch (e) {
return callback({
error: sanitizeErrorMessage(e),
});
}
// acknowledge the creation
callback({
data: value.id,
});
// notify the other users
socket.broadcast.emit("todo:created", value);
},
readTodo: async function (id, callback) {
const { error } = idSchema.validate(id);
if (error) {
return callback({
error: Errors.ENTITY_NOT_FOUND,
});
}
try {
const todo = await todoRepository.findById(id);
callback({
data: todo,
});
} catch (e) {
callback({
error: sanitizeErrorMessage(e),
});
}
},
updateTodo: async function (payload, callback) {
const socket = this;
const { error, value } = todoSchema.tailor("update").validate(payload, {
abortEarly: false,
stripUnknown: true,
});
if (error) {
return callback({
error: Errors.INVALID_PAYLOAD,
errorDetails: mapErrorDetails(error.details),
});
}
try {
await todoRepository.save(value);
} catch (e) {
return callback({
error: sanitizeErrorMessage(e),
});
}
callback();
socket.broadcast.emit("todo:updated", value);
},
deleteTodo: async function (id, callback) {
const socket = this;
const { error } = idSchema.validate(id);
if (error) {
return callback({
error: Errors.ENTITY_NOT_FOUND,
});
}
try {
await todoRepository.deleteById(id);
} catch (e) {
return callback({
error: sanitizeErrorMessage(e),
});
}
callback();
socket.broadcast.emit("todo:deleted", id);
},
listTodo: async function (callback) {
try {
callback({
data: await todoRepository.findAll(),
});
} catch (e) {
callback({
error: sanitizeErrorMessage(e),
});
}
},
};
}

View File

@@ -0,0 +1,74 @@
import { Errors } from "../util.js";
import { Model, DataTypes } from "sequelize";
class CrudRepository {
findAll() {}
findById(id) {}
save(entity) {}
deleteById(id) {}
}
export class TodoRepository extends CrudRepository {}
class Todo extends Model {}
export class PostgresTodoRepository extends TodoRepository {
constructor(sequelize) {
super();
this.sequelize = sequelize;
Todo.init(
{
id: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
},
title: {
type: DataTypes.STRING,
},
completed: {
type: DataTypes.BOOLEAN,
},
},
{
sequelize,
tableName: "todos",
}
);
}
findAll() {
return this.sequelize.transaction((transaction) => {
return Todo.findAll({ transaction });
});
}
async findById(id) {
return this.sequelize.transaction(async (transaction) => {
const todo = await Todo.findByPk(id, { transaction });
if (!todo) {
throw Errors.ENTITY_NOT_FOUND;
}
return todo;
});
}
save(entity) {
return this.sequelize.transaction((transaction) => {
return Todo.upsert(entity, { transaction });
});
}
async deleteById(id) {
return this.sequelize.transaction(async (transaction) => {
const count = await Todo.destroy({ where: { id }, transaction });
if (count === 0) {
throw Errors.ENTITY_NOT_FOUND;
}
});
}
}

View File

@@ -0,0 +1,22 @@
export const Errors = {
ENTITY_NOT_FOUND: "entity not found",
INVALID_PAYLOAD: "invalid payload",
};
const errorValues = Object.values(Errors);
export function sanitizeErrorMessage(message) {
if (typeof message === "string" && errorValues.includes(message)) {
return message;
} else {
return "an unknown error has occurred";
}
}
export function mapErrorDetails(details) {
return details.map((item) => ({
message: item.message,
path: item.path,
type: item.type,
}));
}

View File

@@ -0,0 +1,30 @@
{
"name": "basic-crud-server",
"version": "0.0.1",
"description": "Server for the Basic CRUD Socket.IO example (with Postgres and multiple Socket.IO servers)",
"main": "lib/cluster.js",
"type": "module",
"scripts": {
"start": "node lib/cluster.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/socketio/socket.io.git"
},
"author": "Damien Arrachequesne <damien.arrachequesne@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/socketio/socket.io/issues"
},
"homepage": "https://github.com/socketio/socket.io#readme",
"dependencies": {
"@socket.io/postgres-adapter": "^0.2.0",
"@socket.io/sticky": "^1.0.1",
"joi": "^17.4.0",
"pg": "^8.7.3",
"pg-hstore": "^2.3.4",
"sequelize": "^6.18.0",
"socket.io": "^4.0.1",
"uuid": "^8.3.2"
}
}

Some files were not shown because too many files have changed in this diff Show More