mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Reworked definition and added tests
This commit is contained in:
parent
a5e411fdad
commit
da60d0c6bb
213
types/socket.io-p2p/index.d.ts
vendored
213
types/socket.io-p2p/index.d.ts
vendored
@ -14,109 +14,122 @@ export = SocketioP2PStatic;
|
||||
* @param opts Object of viable options
|
||||
* @param cb Optional callback
|
||||
*/
|
||||
declare function SocketioP2PStatic(
|
||||
declare class SocketioP2PStatic {
|
||||
useSockets: boolean;
|
||||
usePeerConnection: boolean;
|
||||
decoder: any;
|
||||
socket: any;
|
||||
cb: () => void;
|
||||
defaultOps: SocketioP2PStatic.DefaultOps;
|
||||
opts: SocketioP2PStatic.P2POptions;
|
||||
peerOpts: SocketioP2PStatic.PeerOpts;
|
||||
numConnectedClients: number;
|
||||
|
||||
constructor(
|
||||
socket: any,
|
||||
opts: SocketioP2PStatic.P2POptions,
|
||||
opts?: SocketioP2PStatic.P2POptions,
|
||||
cb?: () => void
|
||||
): SocketioP2PStatic.Socketiop2p;
|
||||
);
|
||||
|
||||
on(event: string, callback: (data: any) => void): void;
|
||||
emit(eventName: any, data: any): void;
|
||||
|
||||
/**
|
||||
* Upgrade the connection to p2p
|
||||
*/
|
||||
upgrade(): void;
|
||||
disconnect(): void;
|
||||
binarySlice(arr: any[], interval: number, cb: () => void): void;
|
||||
setupPeerEvents(peer: any): void;
|
||||
}
|
||||
|
||||
declare namespace SocketioP2PStatic {
|
||||
interface PeerOpts {
|
||||
/**
|
||||
* Set to true if this is the initiating peer
|
||||
* @default false
|
||||
*/
|
||||
initiator?: boolean;
|
||||
/**
|
||||
* Custom WebRTC channel configuration (used by createDataChannel)
|
||||
* @default {}
|
||||
*/
|
||||
channelConfig?: object;
|
||||
/**
|
||||
* Custom WebRTC data channel name
|
||||
* @default <randomString>
|
||||
*/
|
||||
channelName?: string;
|
||||
/**
|
||||
* Custom WebRTC configuration (used by RTCPeerConnection constructor)
|
||||
* @default {iceServers:[{urls:'stun:stun.l.google.com:19302'},{urls:'stun:global.stun.twilio.com:3478?transport=udp'}]}
|
||||
*/
|
||||
config?: object;
|
||||
/**
|
||||
* Custom WebRTC video/voice constrainst (used by RTCPeerConnection constructor)
|
||||
* @default {}
|
||||
*/
|
||||
constraints?: object;
|
||||
/**
|
||||
* Custom offer contstraints (used by createOffer methode)
|
||||
* @default {}
|
||||
*/
|
||||
offerConstraints?: object;
|
||||
/**
|
||||
* Custom answer constraints (used by createAnswer method)
|
||||
*/
|
||||
answerConstraints?: object;
|
||||
/**
|
||||
* Function to transform generated SDP signaling data (for advanced users)
|
||||
* @default (sdp)=>sdp
|
||||
*/
|
||||
sdpTransfrom?: (sdp: any) => any;
|
||||
/**
|
||||
* If video/voice is desired, pass stream from getUserMedia
|
||||
* @default false
|
||||
*/
|
||||
stream?: boolean;
|
||||
/**
|
||||
* An array of MediaStreams returned from getUserMedia
|
||||
* @default []
|
||||
*/
|
||||
streams?: MediaStream[];
|
||||
/**
|
||||
* Set to false to disable trickle ICE and get single 'signal' event (slower)
|
||||
* @default true
|
||||
*/
|
||||
trickle?: boolean;
|
||||
/**
|
||||
* Custom WebRTC implementation, mainly useful in node to specify the wrtc package
|
||||
* @default {}
|
||||
*/
|
||||
wrtc?: RTCPeerConnection | RTCSessionDescription | RTCIceCandidate;
|
||||
/**
|
||||
* Set to true to create the stream in Object Mode. In this mode, incoming string data is not automatically converted to Buffer objects
|
||||
* @default false
|
||||
*/
|
||||
objectMode?: boolean;
|
||||
}
|
||||
interface DefaultOps {
|
||||
autoUpgrade: boolean;
|
||||
numClients: number;
|
||||
}
|
||||
interface PeerOpts {
|
||||
/**
|
||||
* Set to true if this is the initiating peer
|
||||
* @default false
|
||||
*/
|
||||
initiator?: boolean;
|
||||
/**
|
||||
* Custom WebRTC channel configuration (used by createDataChannel)
|
||||
* @default {}
|
||||
*/
|
||||
channelConfig?: object;
|
||||
/**
|
||||
* Custom WebRTC data channel name
|
||||
* @default <randomString>
|
||||
*/
|
||||
channelName?: string;
|
||||
/**
|
||||
* Custom WebRTC configuration (used by RTCPeerConnection constructor)
|
||||
* @default {iceServers:[{urls:'stun:stun.l.google.com:19302'},{urls:'stun:global.stun.twilio.com:3478?transport=udp'}]}
|
||||
*/
|
||||
config?: object;
|
||||
/**
|
||||
* Custom WebRTC video/voice constrainst (used by RTCPeerConnection constructor)
|
||||
* @default {}
|
||||
*/
|
||||
constraints?: object;
|
||||
/**
|
||||
* Custom offer contstraints (used by createOffer methode)
|
||||
* @default {}
|
||||
*/
|
||||
offerConstraints?: object;
|
||||
/**
|
||||
* Custom answer constraints (used by createAnswer method)
|
||||
*/
|
||||
answerConstraints?: object;
|
||||
/**
|
||||
* Function to transform generated SDP signaling data (for advanced users)
|
||||
* @default (sdp)=>sdp
|
||||
*/
|
||||
sdpTransfrom?: (sdp: any) => any;
|
||||
/**
|
||||
* If video/voice is desired, pass stream from getUserMedia
|
||||
* @default false
|
||||
*/
|
||||
stream?: boolean;
|
||||
/**
|
||||
* An array of MediaStreams returned from getUserMedia
|
||||
* @default []
|
||||
*/
|
||||
streams?: MediaStream[];
|
||||
/**
|
||||
* Set to false to disable trickle ICE and get single 'signal' event (slower)
|
||||
* @default true
|
||||
*/
|
||||
trickle?: boolean;
|
||||
/**
|
||||
* Custom WebRTC implementation, mainly useful in node to specify the wrtc package
|
||||
* @default {}
|
||||
*/
|
||||
wrtc?: RTCPeerConnection | RTCSessionDescription | RTCIceCandidate;
|
||||
/**
|
||||
* Set to true to create the stream in Object Mode. In this mode, incoming string data is not automatically converted to Buffer objects
|
||||
* @default false
|
||||
*/
|
||||
objectMode?: boolean;
|
||||
}
|
||||
|
||||
interface P2POptions {
|
||||
/**
|
||||
* Max number of peers each client can connect to
|
||||
* @default 5
|
||||
*/
|
||||
numClients?: number;
|
||||
/**
|
||||
* Upgrade to p2p connection (from s.io one) when peers are ready
|
||||
* @default true
|
||||
*/
|
||||
autoUpgrade?: boolean;
|
||||
/**
|
||||
* Object of options passed to underlying peers
|
||||
* @default {}
|
||||
*/
|
||||
peerOpts?: PeerOpts;
|
||||
}
|
||||
|
||||
interface Socketiop2p {
|
||||
(socket: any, opts: P2POptions, cb?: () => void): Socketiop2p;
|
||||
on(event: string, callback: (data: any) => void): void;
|
||||
emit(data: any, cb?: () => void): void;
|
||||
|
||||
/**
|
||||
* Upgrade the connection to p2p
|
||||
*/
|
||||
upgrade(): void;
|
||||
disconnect(): void;
|
||||
binarySlice(arr: any[], interval: number, cb: () => void): void;
|
||||
setupPeerEvents(peer: any): void;
|
||||
}
|
||||
interface P2POptions {
|
||||
/**
|
||||
* Max number of peers each client can connect to
|
||||
* @default 5
|
||||
*/
|
||||
numClients?: number;
|
||||
/**
|
||||
* Upgrade to p2p connection (from s.io one) when peers are ready
|
||||
* @default true
|
||||
*/
|
||||
autoUpgrade?: boolean;
|
||||
/**
|
||||
* Object of options passed to underlying peers
|
||||
* @default {}
|
||||
*/
|
||||
peerOpts?: PeerOpts;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,15 @@
|
||||
function testStub() {
|
||||
console.log("this is a stub");
|
||||
}
|
||||
import * as P2P from "socket.io-p2p";
|
||||
import * as io from "socket.io-client";
|
||||
|
||||
const socket = io();
|
||||
const p2p = new P2P(socket);
|
||||
|
||||
p2p.on("ready", (...args) => {
|
||||
console.log(args);
|
||||
p2p.usePeerConnection = true;
|
||||
p2p.emit("peer-obj", { peerId: 1 });
|
||||
});
|
||||
|
||||
p2p.on("peer-msg", data => {
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user