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

add kill-forward command. #60

Open
wants to merge 1 commit 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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ Forwards socket connections from the ADB server host (local) to the device (remo
* Returns: `Promise`
* Resolves with: `true`

#### client.removeForward(serial, local[, callback])

Remove the port forward at ADB server host (local). This is analogous to `adb forward --remove <local>`. It's important to note that if you are connected to a remote ADB server, the forward on that host will be removed.

* **serial** The serial number of the device. Corresponds to the device ID in `client.listDevices()`.
* **local** A string representing the local endpoint on the ADB host. At time of writing, can be one of:
- `tcp:<port>`
- `localabstract:<unix domain socket name>`
- `localreserved:<unix domain socket name>`
- `localfilesystem:<unix domain socket name>`
- `dev:<character device name>`
* **callback(err)** Optional. Use this or the returned `Promise`.
- **err** `null` when successful, `Error` otherwise.
* Returns: `Promise`
* Resolves with: `true`

#### client.framebuffer(serial[, format]&#91;, callback])

Fetches the current **raw** framebuffer (i.e. what is visible on the screen) from the device, and optionally converts it into something more usable by using [GraphicsMagick][graphicsmagick]'s `gm` command, which must be available in `$PATH` if conversion is desired. Note that we don't bother supporting really old framebuffer formats such as RGB_565. If for some mysterious reason you happen to run into a `>=2.3` device that uses RGB_565, let us know.
Expand Down
9 changes: 9 additions & 0 deletions lib/adb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import GetPropertiesCommand from './command/host-transport/getproperties';
import InstallCommand from './command/host-transport/install';
import IsInstalledCommand from './command/host-transport/isinstalled';
import ListReversesCommand from './command/host-transport/listreverses';
import KillForwardCommand from './command/host-serial/killforward';
koral-- marked this conversation as resolved.
Show resolved Hide resolved
import LocalCommand from './command/host-transport/local';
import LogcatCommand from './command/host-transport/logcat';
import LogCommand from './command/host-transport/log';
Expand Down Expand Up @@ -277,6 +278,14 @@ class Client extends EventEmitter {
.nodeify(callback);
}

public removeForward(serial: string, local: string, callback?: Callback<boolean>): Bluebird<boolean> {
return this.connection()
.then(function (conn) {
return new KillForwardCommand(conn).execute(serial, local);
})
.nodeify(callback);
}

public listForwards(serial: string, callback?: Callback<Forward[]>): Bluebird<Forward[]> {
return this.connection()
.then(function (conn) {
Expand Down
30 changes: 30 additions & 0 deletions lib/adb/command/host-serial/killforward.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Command from '../../command';
import Protocol from '../../protocol';
import Bluebird from 'bluebird';

class KillForwardCommand extends Command<boolean> {
execute(serial: string, local: string): Bluebird<boolean> {
this._send(`host-serial:${serial}:killforward:${local}`);
return this.parser.readAscii(4).then((reply) => {
switch (reply) {
case Protocol.OKAY:
return this.parser.readAscii(4).then((reply) => {
switch (reply) {
case Protocol.OKAY:
return true;
case Protocol.FAIL:
return this.parser.readError();
default:
return this.parser.unexpected(reply, 'OKAY or FAIL');
}
});
case Protocol.FAIL:
return this.parser.readError();
default:
return this.parser.unexpected(reply, 'OKAY or FAIL');
}
});
}
}

export = KillForwardCommand;