Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rodgc/ngx-socket-io
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.8.1
Choose a base ref
...
head repository: rodgc/ngx-socket-io
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 9 commits
  • 7 files changed
  • 3 contributors

Commits on Dec 27, 2024

  1. Export SOCKET_CONFIG_TOKEN (#188)

    This is needed if one needs to extend a basic configuration with
    namespaces, for example.
    barbieri authored Dec 27, 2024
    Copy the full SHA
    64774f4 View commit details
  2. Fix and sync api wrapper (#190)

    * Fix socket.of() method
    
    Socket-io's of() only exists in the server API and it returns a new
    instance.
    
    For client we must create a new `io()` with the URL containing the
    namespace. Let's do this and share instances whenever the namespace is
    reused.
    
    * Fix chaining methods
    
    Since we're wrapping the socket, we must return ourselves and not the
    internal socket.
    
    * Fix volatile usage
    
    It's a getter that toggles a flag, but then we must return the actual
    instance
    
    * Add return types to help users
    
    Since we're not importing socket.io-client typings, these are
    particularly important to avoid `any`
    
    * Add emitWithAck()
    
    * Add offAny() and offAnyOutgoing()
    
    These match onAny() and onAnyOutgoing()
    
    * Add send()
    
    Basically emit('message', ...args)
    
    * Add compress()
    
    * Add attributes
    
    * Fix connect() and disconnect() arguments
    
    According to
    https://github.com/socketio/socket.io/blob/main/packages/socket.io-client/lib/socket.ts
    and https://socket.io/docs/v4/client-api/
    these functions do not receive any arguments.
    barbieri authored Dec 27, 2024
    Copy the full SHA
    0cda11e View commit details
  3. Release v4.8.2

    rodgc committed Dec 27, 2024
    Copy the full SHA
    d5f9d72 View commit details

Commits on Feb 8, 2025

  1. Fix typing (#191)

    * Fix: off() takes a single function, not array
    
    * Fix and lock typescript typings
    
    The previous attempt to manually sync missed some details, then remove
    the outdated @types/socket-io and use the built-in types instead.
    
    Then do a mapping of the original IoSocket type to the wrapped,
    forcing the wrapper to be returned for chained, properties should
    alway match.
    
    This will force the wrapper to be in sync without much effort.
    
    * Breaking: mark internal fields as private, all as readonly
    
    None of these fields should be reassigned once they are created, so
    they are all readonly.
    
    Except by ioSocket, all are of internal use, so keep them private.
    
    * Breaking: fix off() behavior, sync with socket-io-client
    
    off() without an event name just unregisters all event handlers via
    EventEmitter.
    
    The comment implied offAny() would do this, but it's not the case:
    that just removes the onAny() handlers.
    
    If we really wanted to remove all event handlers for everything we
    should be calling:
     - offAny()
     - offAnyOutgoing()
     - off()
    
    But that would not match the wrapped behavior, so let's just keep it
    simple.
    barbieri authored Feb 8, 2025
    Copy the full SHA
    04f35ac View commit details
  2. Update CHANGELOG

    rodgc committed Feb 8, 2025
    Copy the full SHA
    1d07da8 View commit details
  3. Release v4.8.3

    rodgc committed Feb 8, 2025
    Copy the full SHA
    77d16a2 View commit details

Commits on Feb 9, 2025

  1. The options property in the SocketIoConfig interface has been updated…

    … to use Partial<ManagerOptions> instead of a custom-defined object:
    rodgc committed Feb 9, 2025
    Copy the full SHA
    88a0dc5 View commit details
  2. Update Changelog

    rodgc committed Feb 9, 2025
    Copy the full SHA
    0fff31a View commit details
  3. Release v4.8.4

    rodgc committed Feb 9, 2025
    Copy the full SHA
    c07677b View commit details
Showing with 275 additions and 211 deletions.
  1. +36 −0 CHANGELOG.md
  2. +4 −2 README.md
  3. +1 −1 index.ts
  4. +2 −21 package-lock.json
  5. +1 −3 package.json
  6. +4 −132 src/config/socket-io.config.ts
  7. +227 −52 src/socket-io.service.ts
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,42 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [4.8.4] - 2025-02-09

### Changed

- Updated the `options` property in the `SocketIoConfig` interface to use `Partial<ManagerOptions>` instead of a `custom-defined` object.

## [4.8.3] - 2025-02-06

### Fixed

- `off()` behavior, sync with socket-io-client and takes a single function, not array
- Mark internal fields as private in `WrappedSocket`.

### Removed

- Outdated `@types/socket-io` & `@types/socket.io-client` dependencies and use the built-in types instead.

## [4.8.2] - 2024-12-27

### Added

- Return types to help users.
- emitWithAck().
- offAny().
- offAnyOutgoing().
- send().
- compress().
- export SOCKET_CONFIG_TOKEN.

### Fixed

- socket.of() method.
- Chaining methods.
- Volatile usage.
- connect() and disconnect() arguments.

## [4.8.1] - 2024-11-25

### Update
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -135,8 +135,10 @@ The only addition is the `fromEvent` method, which returns an `Observable` that

### `socket.of(namespace: string)`

Takes an namespace.
Works the same as in Socket.IO.
Takes a namespace and returns an instance based on the current config and the given namespace,
that is added to the end of the current url.
See [Namespaces - Client Initialization](https://socket.io/docs/v4/namespaces/#client-initialization).
Instances are reused based on the namespace.

### `socket.on(eventName: string, callback: Function)`

2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { SocketIoModule } from './src/socket-io.module';
export { SocketIoModule, SOCKET_CONFIG_TOKEN } from './src/socket-io.module';
export { SocketIoConfig } from './src/config/socket-io.config';
export { WrappedSocket as Socket } from './src/socket-io.service';
23 changes: 2 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-socket-io",
"version": "4.8.1",
"version": "4.8.4",
"description": "Socket.IO module for Angular",
"main": "index.ts",
"scripts": {
@@ -40,8 +40,6 @@
"@angular/compiler-cli": "^19.0.0",
"@angular/core": "^19.0.0",
"@types/node": "^22.9.1",
"@types/socket.io": "^3.0.1",
"@types/socket.io-client": "^1.4.36",
"husky": "^9.1.7",
"ng-packagr": "^19.0.0",
"prettier": "^3.3.3",
136 changes: 4 additions & 132 deletions src/config/socket-io.config.ts
Original file line number Diff line number Diff line change
@@ -1,140 +1,12 @@
import type { ManagerOptions } from 'socket.io-client';

/** Config interface */
export interface SocketIoConfig {
url: string;
/**
* Options
* References:
* https://github.com/socketio/socket.io-client/blob/master/docs/API.md#new-managerurl-options
* https://socket.io/docs/v4/client-options
*/
options?: {
/**
* Name of the path that is captured on the server side. Default: /socket.io
*/
path?: string;
/**
* Whether to reconnect automatically. Default: true
*/
reconnection?: boolean;
/**
* Number of reconnection attempts before giving up. Default: infinity
*/
reconnectionAttempts?: number;

/**
* How long to initially wait before attempting a new reconnection. Default: 1000 +- randomizationFactor
*/
reconnectionDelay?: number;

/**
* Maximum amount of time to wait between reconnections. Default: 5000
*/
reconnectionDelayMax?: number;
/**
* Randomization factor for the reconnection delay. Default: 0.5
*/
randomizationFactor?: number;
/**
* Connection timeout before a connect_error and connect_timeout events are emitted. Default: 20000
*/
timeout?: number;
/**
* By setting this false, you have to call manager.open whenever you decide it's appropriate. Default: true
*/
autoConnect?: boolean;
/**
* Additional query parameters that are sent when connecting a namespace (then found in socket.handshake.query object on the server-side)
*/
query?: {
[key: string]: string | null;
};
/**
* The parser to use. Defaults to an instance of the Parser that ships with Socket.IO
* Reference: https://github.com/socketio/socket.io-parser
*/
parser?: any;

// Options for the underlying Engine.IO client:
/**
* Whether the client should try to upgrade the transport from long-polling to something better. Default: true
*/
upgrade?: boolean;
/**
* Forces JSONP for polling transport. Default: false
*/
forceJSONP?: boolean;
/**
* Determines whether to use JSONP when necessary for polling. If disabled (by settings to false) an error will be emitted (saying “No transports available”) if no other transports are available. If another transport is available for opening a connection (e.g. WebSocket) that transport will be used instead. Default: false
*/
jsonp?: boolean;
/**
* Forces base 64 encoding for polling transport even when XHR2 responseType is available and WebSocket even if the used standard supports binary. Default: false
*/
forceBase64?: boolean;
/**
* Enables XDomainRequest for IE8 to avoid loading bar flashing with click sound. default to false because XDomainRequest has a flaw of not sending cookie. Default: false
*/
enablesXDR?: boolean;
/**
* Whether to add the timestamp with each transport request. Note: polling requests are always stamped unless this option is explicitly set to false.
*/
timestampRequests?: boolean;
/**
* The timestamp parameter
*/
timestampParam?: string;
/**
* Port the policy server listens on. Default: 843
*/
policyPort?: number;
/**
* A list of transports to try (in order). Engine always attempts to connect directly with the first one, provided the feature detection test for it passes. Default: ["polling", "websocket"]
*/
transports?: string[];
/**
* Hash of options, indexed by transport name, overriding the common options for the given transport. Default: {}
*/
transportOptions?: any;
/**
* If true and if the previous websocket connection to the server succeeded, the connection attempt will bypass the normal upgrade process and will initially try websocket. A connection attempt following a transport error will use the normal upgrade process. It is recommended you turn this on only when using SSL/TLS connections, or if you know that your network does not block websockets. Default: false.
*/
rememberUpgrade?: boolean;
/**
* Whether transport upgrades should be restricted to transports supporting binary data. Default: false
*/
onlyBinaryUpgrades?: boolean;
/**
* Timeout for xhr-polling requests in milliseconds (0) (only for polling transport). Default: 0
*/
requestTimeout?: number;
/**
* A list of subprotocols. See https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#Subprotocols
*/
protocols?: any;
/**
* Credentials that are sent when accessing a namespace. Default: not present
*/
auth?: { [key: string]: any } | ((cb: (data: object) => void) => void);
/**
* Whether cross-site requests should be made using credentials such as cookies, authorization headers or TLS client certificates. Setting withCredentials has no effect on same-site requests. Default value: false
*/
withCredentials?: boolean;
/**
* Additional headers (then found in socket.handshake.headers object on the server-side). Default value: -
*/
extraHeaders?: {
[header: string]: string;
};

/**
* decide whether to trigger disconnect event when reloading the page or not
* */
closeOnBeforeunload?: boolean;

/**
* Whether to create a new Manager instance. Default value: false
*/
forceNew?: boolean;

// Additional options for NodeJS Engine.IO clients omitted: https://socket.io/docs/client-api/
};
options?: Partial<ManagerOptions>;
}
Loading