From 864f56b0071c26cc522f008da6fec1ff8d0324ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Sat, 5 Nov 2022 23:32:54 +0100 Subject: [PATCH 1/2] TS: fix socket/transport types Fixes #743. * Create Socket type definitions. * Fix ondisconnect definition for Socket (previously defined in WebsocketInterface). * Create missing definitions for UA connection events. --- lib/Socket.d.ts | 29 +++++++++++++++++++++++++++++ lib/Transport.d.ts | 2 +- lib/UA.d.ts | 15 +++++++++++---- lib/WebSocketInterface.d.ts | 37 +------------------------------------ 4 files changed, 42 insertions(+), 41 deletions(-) create mode 100644 lib/Socket.d.ts diff --git a/lib/Socket.d.ts b/lib/Socket.d.ts new file mode 100644 index 0000000..6f63543 --- /dev/null +++ b/lib/Socket.d.ts @@ -0,0 +1,29 @@ +export interface WeightedSocket { + socket: Socket; + weight: number +} + +export class Socket { + get via_transport(): string; + set via_transport(value: string); + + get url(): string; + + get sip_uri(): string; + + connect(): void; + + disconnect(): void; + + send(message: string | ArrayBufferLike | Blob | ArrayBufferView): boolean; + + isConnected(): boolean; + + isConnecting(): boolean; + + onconnect(): void; + + ondisconnect(error: boolean, code?: number, reason?: string): void; + + ondata(event: T): void; +} diff --git a/lib/Transport.d.ts b/lib/Transport.d.ts index 68d2322..5d9e79a 100644 --- a/lib/Transport.d.ts +++ b/lib/Transport.d.ts @@ -1,4 +1,4 @@ -import {Socket} from './WebSocketInterface' +import {Socket} from './Socket' export interface RecoveryOptions { min_interval: number; diff --git a/lib/UA.d.ts b/lib/UA.d.ts index 13798d3..b7db28e 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -1,6 +1,6 @@ import {EventEmitter, Listener} from 'events' -import {DisconnectEvent, Socket, WeightedSocket} from './WebSocketInterface' +import {Socket, WeightedSocket} from './Socket' import {AnswerOptions, Originator, RTCSession, RTCSessionEventMap, TerminateOptions} from './RTCSession' import {IncomingRequest, IncomingResponse, OutgoingRequest} from './SIPMessage' import {Message, SendMessageOptions} from './Message' @@ -60,7 +60,7 @@ export interface OutgoingRTCSessionEvent { export type RTCSessionEvent = IncomingRTCSessionEvent | OutgoingRTCSessionEvent; -export interface UAConnectingEvent { +export interface ConnectingEvent { socket: Socket; attempts: number } @@ -69,6 +69,13 @@ export interface ConnectedEvent { socket: Socket; } +export interface DisconnectEvent { + socket: Socket; + error: boolean; + code?: number; + reason?: string; +} + export interface RegisteredEvent { response: IncomingResponse; } @@ -100,7 +107,7 @@ export interface OutgoingOptionsEvent { request: OutgoingRequest; } -export type UAConnectingListener = (event: UAConnectingEvent) => void; +export type ConnectingListener = (event: ConnectingEvent) => void; export type ConnectedListener = (event: ConnectedEvent) => void; export type DisconnectedListener = (event: DisconnectEvent) => void; export type RegisteredListener = (event: RegisteredEvent) => void; @@ -118,7 +125,7 @@ export type OptionsListener = IncomingOptionsListener | OutgoingOptionsListener; export type SipEventListener = (event: { event: T; request: IncomingRequest; }) => void export interface UAEventMap { - connecting: UAConnectingListener; + connecting: ConnectingListener; connected: ConnectedListener; disconnected: DisconnectedListener; registered: RegisteredListener; diff --git a/lib/WebSocketInterface.d.ts b/lib/WebSocketInterface.d.ts index 2c6c4d9..581b712 100644 --- a/lib/WebSocketInterface.d.ts +++ b/lib/WebSocketInterface.d.ts @@ -1,39 +1,4 @@ -export interface DisconnectEvent { - socket: Socket; - error: boolean; - code?: number; - reason?: string; -} - -export interface WeightedSocket { - socket: Socket; - weight: number -} - -export class Socket { - get via_transport(): string; - set via_transport(value: string); - - get url(): string; - - get sip_uri(): string; - - connect(): void; - - disconnect(): void; - - send(message: string | ArrayBufferLike | Blob | ArrayBufferView): boolean; - - isConnected(): boolean; - - isConnecting(): boolean; - - onconnect(): void; - - ondisconnect(event: DisconnectEvent): void; - - ondata(event: T): void; -} +import { Socket } from './Socket'; export class WebSocketInterface extends Socket { constructor(url: string) From 7dcf79ff4e1823509be68ff5b5f853b121a7d478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Sat, 5 Nov 2022 23:38:25 +0100 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9818cc7..5a89cbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +### NEXT RELEASE + +* TS: fix socket/transport types (#790). + + ### 3.10.0 * Fix typescript typings (#648).