Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix socket types #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

### NEXT RELEASE

* TS: fix socket/transport types (#790).


### 3.10.0

* Fix typescript typings (#648).
Expand Down
29 changes: 29 additions & 0 deletions lib/Socket.d.ts
Original file line number Diff line number Diff line change
@@ -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<T>(event: T): void;
}
2 changes: 1 addition & 1 deletion lib/Transport.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Socket} from './WebSocketInterface'
import {Socket} from './Socket'

export interface RecoveryOptions {
min_interval: number;
Expand Down
15 changes: 11 additions & 4 deletions lib/UA.d.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -60,7 +60,7 @@ export interface OutgoingRTCSessionEvent {

export type RTCSessionEvent = IncomingRTCSessionEvent | OutgoingRTCSessionEvent;

export interface UAConnectingEvent {
export interface ConnectingEvent {
socket: Socket;
attempts: number
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -118,7 +125,7 @@ export type OptionsListener = IncomingOptionsListener | OutgoingOptionsListener;
export type SipEventListener = <T = any>(event: { event: T; request: IncomingRequest; }) => void

export interface UAEventMap {
connecting: UAConnectingListener;
connecting: ConnectingListener;
connected: ConnectedListener;
disconnected: DisconnectedListener;
registered: RegisteredListener;
Expand Down
37 changes: 1 addition & 36 deletions lib/WebSocketInterface.d.ts
Original file line number Diff line number Diff line change
@@ -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<T>(event: T): void;
}
import { Socket } from './Socket';

export class WebSocketInterface extends Socket {
constructor(url: string)
Expand Down