mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-06 09:19:08 +00:00
Merge pull request #3371 from nakakura/peerjs-update
update peerjs/Peer.d.ts
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
/// <reference path="Peer.d.ts" />
|
||||
/// <reference path="./Peer.d.ts" />
|
||||
/// <reference path="../webrtc/RTCPeerConnection.d.ts" />
|
||||
|
||||
var peerByOption: Peer = new Peer({
|
||||
var peerByOption: PeerJs.Peer = new Peer({
|
||||
key: 'peerKey',
|
||||
debug: 3,
|
||||
logFunction: ()=>{
|
||||
}
|
||||
});
|
||||
|
||||
var peerById: Peer = new Peer("peerid");
|
||||
peerByOption.listAllPeers(function(items){
|
||||
for(var i in items){
|
||||
console.log(decodeURI(items[i]));
|
||||
}
|
||||
});
|
||||
|
||||
var peerByIdAndOption: Peer = new Peer(
|
||||
var peerById: PeerJs.Peer = new Peer("peerid");
|
||||
|
||||
var peerByIdAndOption: PeerJs.Peer = new Peer(
|
||||
"peerId",
|
||||
{
|
||||
key: 'peerKey',
|
||||
@@ -42,3 +48,5 @@ peerById.on("call", (media)=> console.log("call"));
|
||||
peerById.on("close", ()=> console.log("close"));
|
||||
peerById.on("disconnected", ()=> console.log("disconnected"));
|
||||
peerById.on("error", (err)=> console.log(err));
|
||||
|
||||
var connection2 = peerById.getConnection(peerByOption, "callto-id");
|
||||
|
||||
187
peerjs/Peer.d.ts
vendored
187
peerjs/Peer.d.ts
vendored
@@ -69,92 +69,105 @@ declare module PeerJs{
|
||||
browser: string;
|
||||
supports: utilSupportsObj;
|
||||
}
|
||||
}
|
||||
|
||||
interface Peer{
|
||||
/**
|
||||
*
|
||||
* @param id The brokering ID of the remote peer (their peer.id).
|
||||
* @param options for specifying details about Peer Connection
|
||||
*/
|
||||
connect(id: string, options?: PeerJs.PeerJSOption): PeerJs.DataConnection;
|
||||
/**
|
||||
* Connects to the remote peer specified by id and returns a data connection.
|
||||
* @param id The brokering ID of the remote peer (their peer.id).
|
||||
* @param stream The caller's media stream
|
||||
* @param options Metadata associated with the connection, passed in by whoever initiated the connection.
|
||||
*/
|
||||
call(id: string, stream: any, options?: any): PeerJs.MediaConnection;
|
||||
/**
|
||||
* Calls the remote peer specified by id and returns a media connection.
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: string, cb: ()=>void): void;
|
||||
/**
|
||||
* Emitted when a connection to the PeerServer is established.
|
||||
* @param event Event name
|
||||
* @param cb id is the brokering ID of the peer
|
||||
*/
|
||||
on(event: 'open', cb: (id: string)=>void): void;
|
||||
/**
|
||||
* Emitted when a new data connection is established from a remote peer.
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: 'connection', cb: (dataConnection: PeerJs.DataConnection)=>void): void;
|
||||
/**
|
||||
* Emitted when a remote peer attempts to call you.
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: 'call', cb: (mediaConnection: PeerJs.MediaConnection)=>void): void;
|
||||
/**
|
||||
* Emitted when the peer is destroyed and can no longer accept or create any new connections.
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: 'close', cb: ()=>void): void;
|
||||
/**
|
||||
* Emitted when the peer is disconnected from the signalling server
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: 'disconnected', cb: ()=>void): void;
|
||||
/**
|
||||
* Errors on the peer are almost always fatal and will destroy the peer.
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: 'error', cb: (err: any)=>void): void;
|
||||
/**
|
||||
* Close the connection to the server, leaving all existing data and media connections intact.
|
||||
*/
|
||||
disconnect(): void;
|
||||
/**
|
||||
* Attempt to reconnect to the server with the peer's old ID
|
||||
*/
|
||||
reconnect(): void;
|
||||
/**
|
||||
* Close the connection to the server and terminate all existing connections.
|
||||
*/
|
||||
destroy(): void;
|
||||
/**
|
||||
* The brokering ID of this peer
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* A hash of all connections associated with this peer, keyed by the remote peer's ID.
|
||||
*/
|
||||
connections: any;
|
||||
/**
|
||||
* false if there is an active connection to the PeerServer.
|
||||
*/
|
||||
disconnected: boolean;
|
||||
/**
|
||||
* true if this peer and all of its connections can no longer be used.
|
||||
*/
|
||||
destroyed: boolean;
|
||||
export interface Peer{
|
||||
/**
|
||||
*
|
||||
* @param id The brokering ID of the remote peer (their peer.id).
|
||||
* @param options for specifying details about Peer Connection
|
||||
*/
|
||||
connect(id: string, options?: PeerJs.PeerJSOption): PeerJs.DataConnection;
|
||||
/**
|
||||
* Connects to the remote peer specified by id and returns a data connection.
|
||||
* @param id The brokering ID of the remote peer (their peer.id).
|
||||
* @param stream The caller's media stream
|
||||
* @param options Metadata associated with the connection, passed in by whoever initiated the connection.
|
||||
*/
|
||||
call(id: string, stream: any, options?: any): PeerJs.MediaConnection;
|
||||
/**
|
||||
* Calls the remote peer specified by id and returns a media connection.
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: string, cb: ()=>void): void;
|
||||
/**
|
||||
* Emitted when a connection to the PeerServer is established.
|
||||
* @param event Event name
|
||||
* @param cb id is the brokering ID of the peer
|
||||
*/
|
||||
on(event: 'open', cb: (id: string)=>void): void;
|
||||
/**
|
||||
* Emitted when a new data connection is established from a remote peer.
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: 'connection', cb: (dataConnection: PeerJs.DataConnection)=>void): void;
|
||||
/**
|
||||
* Emitted when a remote peer attempts to call you.
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: 'call', cb: (mediaConnection: PeerJs.MediaConnection)=>void): void;
|
||||
/**
|
||||
* Emitted when the peer is destroyed and can no longer accept or create any new connections.
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: 'close', cb: ()=>void): void;
|
||||
/**
|
||||
* Emitted when the peer is disconnected from the signalling server
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: 'disconnected', cb: ()=>void): void;
|
||||
/**
|
||||
* Errors on the peer are almost always fatal and will destroy the peer.
|
||||
* @param event Event name
|
||||
* @param cb Callback Function
|
||||
*/
|
||||
on(event: 'error', cb: (err: any)=>void): void;
|
||||
/**
|
||||
* Close the connection to the server, leaving all existing data and media connections intact.
|
||||
*/
|
||||
disconnect(): void;
|
||||
/**
|
||||
* Attempt to reconnect to the server with the peer's old ID
|
||||
*/
|
||||
reconnect(): void;
|
||||
/**
|
||||
* Close the connection to the server and terminate all existing connections.
|
||||
*/
|
||||
destroy(): void;
|
||||
|
||||
/**
|
||||
* Retrieve a data/media connection for this peer.
|
||||
* @param peer
|
||||
* @param id
|
||||
*/
|
||||
getConnection(peer: Peer, id: string): any;
|
||||
|
||||
/**
|
||||
* Get a list of available peer IDs
|
||||
* @param callback
|
||||
*/
|
||||
listAllPeers(callback: (peerIds: Array<string>)=>void): void;
|
||||
/**
|
||||
* The brokering ID of this peer
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* A hash of all connections associated with this peer, keyed by the remote peer's ID.
|
||||
*/
|
||||
connections: any;
|
||||
/**
|
||||
* false if there is an active connection to the PeerServer.
|
||||
*/
|
||||
disconnected: boolean;
|
||||
/**
|
||||
* true if this peer and all of its connections can no longer be used.
|
||||
*/
|
||||
destroyed: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
declare var Peer: {
|
||||
@@ -165,11 +178,11 @@ declare var Peer: {
|
||||
* If no ID is given, one will be generated by the brokering server.
|
||||
* @param options for specifying details about PeerServer
|
||||
*/
|
||||
new (id: string, options?: PeerJs.PeerJSOption): Peer;
|
||||
new (id: string, options?: PeerJs.PeerJSOption): PeerJs.Peer;
|
||||
|
||||
/**
|
||||
* A peer can connect to other peers and listen for connections.
|
||||
* @param options for specifying details about PeerServer
|
||||
*/
|
||||
new (options: PeerJs.PeerJSOption): Peer;
|
||||
new (options: PeerJs.PeerJSOption): PeerJs.Peer;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user