Skip to content

📢 Send Text to Android TV #46

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

Open
wants to merge 1 commit into
base: main
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ androidRemote.on('ready', async () => {

androidRemote.sendKey(RemoteKeyCode.MUTE, RemoteDirection.SHORT)

androidRemote.sendText("Hello World!")

androidRemote.sendAppLink("https://www.disneyplus.com");
});

Expand Down Expand Up @@ -82,6 +84,11 @@ Emitted when androidtv has a problem : by example when you send a wrong app_link
### `Command: sendCode(code)`
- `code` : You need to pass the shown code on the TV when asked

### `Command: sendText(text)`
- `text` : You need to pass the text to send
* This may not work when virtual keyboard is open on TV
* To hide virtual keyboard, send `sendKey(RemoteKeyCode.KEYCODE_BACK, RemoteDirection.SHORT)`

### `Command: sendKey(KeyCode, Direction)`
- `KeyCode` : Any key of https://developer.android.com/reference/android/view/KeyEvent?hl=fr
- `Direction` :
Expand Down
6 changes: 6 additions & 0 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ androidRemote.on('ready', async () => {
await new Promise(resolve => setTimeout(resolve, 100));
androidRemote.sendKey(RemoteKeyCode.KEYCODE_0, RemoteDirection.END_LONG)

await new Promise(resolve => setTimeout(resolve, 1000));
androidRemote.sendText("Hello");

await new Promise(resolve => setTimeout(resolve, 1000));
androidRemote.sendText(" World!");

androidRemote.sendKey(RemoteKeyCode.KEYCODE_MUTE, RemoteDirection.SHORT)
await new Promise(resolve => setTimeout(resolve, 10000));
androidRemote.sendAppLink("https://www.disneyplus.com");
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"license": "ISC",
"type": "module",
"dependencies": {
"androidtv-remote": "^1.0.10"
"androidtv-remote": "file:../"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "androidtv-remote",
"version": "1.0.10",
"version": "1.1.0",
"description": "AndroidTV Remote",
"main": "dist/index.js",
"engines": {
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export class AndroidRemote extends EventEmitter {
return this.remoteManager.sendKey(key, direction);
}

sendText(text){
return this.remoteManager.sendText(text);
}

getCertificate(){
return {
key:this.cert.key,
Expand Down
18 changes: 18 additions & 0 deletions src/remote/RemoteManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class RemoteManager extends EventEmitter {
}
else if(message.remoteImeBatchEdit){
console.debug("Receive IME BATCH EDIT" + message.remoteImeBatchEdit);
this.remoteImeBatchEditResponse = JSON.parse(JSON.stringify(message.remoteImeBatchEdit));
}
else if(message.remoteImeShowRequest){
console.debug("Receive IME SHOW REQUEST" + message.remoteImeShowRequest);
Expand Down Expand Up @@ -167,6 +168,23 @@ class RemoteManager extends EventEmitter {
key));
}

sendText(text){
let _imeCounter = 0;
let _fieldCounter = 0;
if (this.remoteImeBatchEditResponse) {
if (this.remoteImeBatchEditResponse.imeCounter) {
_imeCounter = this.remoteImeBatchEditResponse.imeCounter;
}
if (this.remoteImeBatchEditResponse.fieldCounter) {
_fieldCounter = this.remoteImeBatchEditResponse.fieldCounter;
}
}
this.client.write(remoteMessageManager.createRemoteImeBatchEdit(
text,
_imeCounter,
_fieldCounter));
}

sendAppLink(app_link){
this.client.write(remoteMessageManager.createRemoteRemoteAppLinkLaunchRequest(app_link));
}
Expand Down
17 changes: 17 additions & 0 deletions src/remote/RemoteMessageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ class RemoteMessageManager {
});
}

createRemoteImeBatchEdit(text, imeCounter, fieldCounter) {
return this.create({
remoteImeBatchEdit: {
imeCounter,
fieldCounter,
editInfo: [{
insert: 0,
textFieldStatus: {
start: text.length - 1,
end: text.length - 1,
value: text
}
}]
}
});
}

parse(buffer){
return this.RemoteMessage.decodeDelimited(buffer);
}
Expand Down
11 changes: 9 additions & 2 deletions src/remote/remotemessage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,20 @@ message RemoteImeShowRequest {
}

message RemoteEditInfo {
int32 insert = 2;
int32 insert = 1;
RemoteImeObject text_field_status = 2;
}

message RemoteImeObject {
int32 start = 1;
int32 end = 2;
string value = 3;
}

message RemoteImeBatchEdit {
int32 ime_counter = 1;
int32 field_counter = 2;
RemoteEditInfo edit_info = 3;
repeated RemoteEditInfo edit_info = 3;
}

message RemoteAppInfo {
Expand Down