diff --git a/peerjs/Peer-tests.ts b/peerjs/Peer-tests.ts index 5299c84bc5..02a63cd8fa 100644 --- a/peerjs/Peer-tests.ts +++ b/peerjs/Peer-tests.ts @@ -1,16 +1,22 @@ -/// +/// /// -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"); diff --git a/peerjs/Peer.d.ts b/peerjs/Peer.d.ts index 2d57877993..90a103fd97 100644 --- a/peerjs/Peer.d.ts +++ b/peerjs/Peer.d.ts @@ -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)=>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; };