Permalink
Browse files

Add type information for Chrome's Socket API

  • Loading branch information...
ahf committed Jan 19, 2013
1 parent 55832cc commit 7e2aa940a4afcab5d3607a3459043d3f41be8634
Showing with 61 additions and 1 deletion.
  1. +61 −1 chrome/chrome.d.ts
View
@@ -1556,6 +1556,66 @@ declare module chrome.storage {
declare var onChanged: StorageChangedEvent;
}
+////////////////////
+// Socket
+////////////////////
+declare module chrome.socket {
+ interface CreateInfo {
+ socketId: number;
+ }
+
+ interface AcceptInfo {
+ resultCode: number;
+ socketId?: number;
+ }
+
+ interface ReadInfo {
+ resultCode: number;
+ data: ArrayBuffer;
+ }
+
+ interface WriteInfo {
+ bytesWritten: number;
+ }
+
+ interface RecvFromInfo {
+ resultCode: number;
+ data: ArrayBuffer;
+ port: number;
+ address: string;
+ }
+
+ interface SocketInfo {
+ socketType: string;
+ localPort?: number;
+ peerAddress?: string;
+ peerPort?: number;
+ localAddress?: string;
+ connected: bool;
+ }
+
+ interface NetworkInterface {
+ name: string;
+ address: string;
+ }
+
+ export function create(type: string, options?: Object, callback?: (createInfo: CreateInfo) => void): void;
+ export function destroy(socketId: number): void;
+ export function connect(socketId: number, hostname: string, port: number, callback: (result: number) => void): void;
+ export function bind(socketId: number, address: string, port: number, callback: (result: number) => void): void;
+ export function disconnect(socketId: number): void;
+ export function read(socketId: number, bufferSize?: number, callback?: (readInfo: ReadInfo) => void): void;
+ export function write(socketId: number, data: ArrayBuffer, callback?: (writeInfo: WriteInfo) => void): void;
+ export function recvFrom(socketId: number, bufferSize?: number, callback?: (recvFromInfo: RecvFromInfo) => void): void;
+ export function sendTo(socketId: number, data: ArrayBuffer, address: string, port: number, callback?: (writeInfo: WriteInfo) => void): void;
+ export function listen(socketId: number, address: string, port: number, backlog?: number, callback?: (result: number) => void): void;
+ export function accept(socketId: number, callback?: (acceptInfo: AcceptInfo) => void): void;
+ export function setKeepAlive(socketId: number, enable: bool, delay?: number, callback?: (result: bool) => void): void;
+ export function setNoDelay(socketId: number, noDelay: bool, callback?: (result: bool) => void): void;
+ export function getInfo(socketId: number, callback: (result: SocketInfo) => void): void;
+ export function getNetworkList(callback: (result: NetworkInterface[]) => void): void;
+}
+
////////////////////
// Tabs
////////////////////
@@ -2292,4 +2352,4 @@ declare module chrome.windows {
declare var onRemoved: WindowRemovedEvent;
declare var onCreated: WindowCreatedEvent;
declare var onFocusChanged: WindowFocusChangedEvent;
-}
+}

0 comments on commit 7e2aa94

Please sign in to comment.