forked from NetrisTV/ws-scrcpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
586 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/node_modules | ||
/dist | ||
/build | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import Position from "./Position"; | ||
import {Buffer} from "buffer"; | ||
|
||
export class ControlEvent { | ||
public static TYPE_KEYCODE = 0; | ||
public static TYPE_TEXT = 1; | ||
public static TYPE_MOUSE = 2; | ||
public static TYPE_SCROLL = 3; | ||
public static TYPE_COMMAND = 4; | ||
|
||
public static KEYCODE_PAYLOAD_LENGTH = 9; | ||
public static MOUSE_PAYLOAD_LENGTH = 17; | ||
public static SCROLL_PAYLOAD_LENGTH = 20; | ||
public static COMMAND_PAYLOAD_LENGTH = 1; | ||
|
||
constructor(readonly type: number) { | ||
this.type = type; | ||
} | ||
|
||
public toBuffer(): Buffer { | ||
throw Error('Not implemented'); | ||
} | ||
|
||
static createKeycodeControlEvent(action: number, keycode: number, metaState: number) { | ||
return new KeyCodeControlEvent(action, keycode, metaState); | ||
} | ||
|
||
static createTextControlEvent(text: string) { | ||
return new TextControlEvent(text); | ||
} | ||
|
||
static createMotionControlEvent(action: number, buttons: number, position: Position) { | ||
return new MotionControlEvent(action, buttons, position); | ||
} | ||
|
||
static createScrollControlEvent(position: Position, hScroll: number, vScroll: number) { | ||
return new ScrollControlEvent(position, hScroll, vScroll); | ||
} | ||
|
||
static createCommandControlEvent(action: number) { | ||
return new CommandControlEvent(action); | ||
} | ||
} | ||
|
||
export class CommandControlEvent extends ControlEvent{ | ||
public static COMMAND_BACK_OR_SCREEN_ON = 0; | ||
public static COMMAND_EXPAND_NOTIFICATION_PANEL = 1; | ||
public static COMMAND_COLLAPSE_NOTIFICATION_PANEL = 2; | ||
|
||
constructor(readonly action: number) { | ||
super(ControlEvent.TYPE_COMMAND); | ||
this.action = action; | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
public toBuffer(): Buffer { | ||
const buffer = new Buffer(ControlEvent.COMMAND_PAYLOAD_LENGTH + 1); | ||
buffer.writeUInt8(this.type, 0); | ||
buffer.writeUInt8(this.action, 1); | ||
return buffer; | ||
} | ||
|
||
public toString(): string { | ||
return `KeyCodeControlEvent{action=${this.action}}`; | ||
} | ||
} | ||
|
||
export class KeyCodeControlEvent extends ControlEvent{ | ||
constructor(readonly action: number, readonly keycode: number, readonly metaState: number) { | ||
super(ControlEvent.TYPE_KEYCODE); | ||
this.action = action; | ||
this.keycode = keycode; | ||
this.metaState = metaState; | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
public toBuffer(): Buffer { | ||
const buffer = new Buffer(ControlEvent.KEYCODE_PAYLOAD_LENGTH + 1); | ||
buffer.writeUInt8(this.type, 0); | ||
buffer.writeUInt8(this.action, 1); | ||
buffer.writeUInt32BE(this.keycode, 2); | ||
buffer.writeUInt32BE(this.metaState, 6); | ||
return buffer; | ||
} | ||
|
||
public toString(): string { | ||
return `KeyCodeControlEvent{action=${this.action}, keycode=${this.keycode}, metaState=${this.metaState}}`; | ||
} | ||
} | ||
|
||
export class MotionControlEvent extends ControlEvent{ | ||
constructor(readonly action: number, readonly buttons: number, readonly position: Position) { | ||
super(ControlEvent.TYPE_MOUSE); | ||
this.action = action; | ||
this.buttons = buttons; | ||
this.position = position; | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
public toBuffer(): Buffer { | ||
const buffer: Buffer = new Buffer(ControlEvent.MOUSE_PAYLOAD_LENGTH + 1); | ||
buffer.writeUInt8(this.type, 0); | ||
buffer.writeUInt8(this.action, 1); | ||
buffer.writeUInt32BE(this.buttons, 2); | ||
buffer.writeUInt32BE(this.position.point.x, 6); | ||
buffer.writeUInt32BE(this.position.point.y, 10); | ||
buffer.writeUInt16BE(this.position.screenSize.width, 14); | ||
buffer.writeUInt16BE(this.position.screenSize.height, 16); | ||
return buffer; | ||
} | ||
|
||
public toString(): string { | ||
return `MotionControlEvent{action=${this.action}, buttons=${this.buttons}, position=${this.position}}`; | ||
} | ||
} | ||
|
||
export class ScrollControlEvent extends ControlEvent{ | ||
constructor(readonly position: Position, readonly hScroll: number, readonly vScroll: number) { | ||
super(ControlEvent.TYPE_SCROLL); | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
public toBuffer(): Buffer { | ||
const buffer = new Buffer(ControlEvent.SCROLL_PAYLOAD_LENGTH + 1); | ||
buffer.writeUInt8(this.type, 0); | ||
buffer.writeUInt32BE(this.position.point.x, 1); | ||
buffer.writeUInt32BE(this.position.point.y, 5); | ||
buffer.writeUInt16BE(this.position.screenSize.width, 9); | ||
buffer.writeUInt16BE(this.position.screenSize.height, 11); | ||
buffer.writeUInt32BE(this.hScroll, 13); | ||
buffer.writeUInt32BE(this.vScroll, 17); | ||
return buffer; | ||
} | ||
|
||
public toString(): string { | ||
return `ScrollControlEvent{hScroll=${this.hScroll}, vScroll=${this.vScroll}, position=${this.position}}`; | ||
} | ||
} | ||
|
||
export class TextControlEvent extends ControlEvent{ | ||
constructor(readonly text: string) { | ||
super(ControlEvent.TYPE_TEXT); | ||
this.text = text; | ||
} | ||
|
||
public getText(): string { | ||
return this.text; | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
public toBuffer(): Buffer { | ||
const length = this.text.length; | ||
const buffer = new Buffer(length + 1 + 2); | ||
buffer.writeUInt8(this.type, 0); | ||
buffer.writeUInt16BE(length, 1); | ||
buffer.write(this.text, 3); | ||
return buffer; | ||
} | ||
|
||
public toString(): string { | ||
return `TextControlEvent{text=${this.text}}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default class MotionEvent { | ||
public static ACTION_DOWN = 0; | ||
public static ACTION_UP = 1; | ||
public static ACTION_MOVE = 2; | ||
/** | ||
* Button constant: Primary button (left mouse button). | ||
*/ | ||
public static BUTTON_PRIMARY = 1 << 0; | ||
|
||
/** | ||
* Button constant: Secondary button (right mouse button). | ||
*/ | ||
public static BUTTON_SECONDARY = 1 << 1; | ||
|
||
/** | ||
* Button constant: Tertiary button (middle mouse button). | ||
*/ | ||
public static BUTTON_TERTIARY = 1 << 2 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export default class Point { | ||
constructor(readonly x: number, readonly y: number) { | ||
this.x = Math.round(x); | ||
this.y = Math.round(y); | ||
} | ||
|
||
public equals(o: Point): boolean { | ||
if (this === o) { | ||
return true; | ||
} | ||
if (o == null) { | ||
return false; | ||
} | ||
return this.x === o.x && this.y === o.y; | ||
} | ||
|
||
public toString(): string { | ||
return `Point{x=${this.x}, y=${this.y}}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Point from "./Point"; | ||
import Size from "./Size"; | ||
|
||
export default class Position { | ||
public constructor(readonly point: Point, readonly screenSize: Size) { | ||
this.point = point; | ||
this.screenSize = screenSize; | ||
} | ||
|
||
public equals(o: Position): boolean { | ||
if (this === o) { | ||
return true; | ||
} | ||
if (o == null) { | ||
return false; | ||
} | ||
|
||
return this.point.equals(o.point) && this.screenSize.equals(o.screenSize); | ||
} | ||
|
||
public toString(): string { | ||
return `Position{point=${this.point}, screenSize=${this.screenSize}}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default class Rect { | ||
constructor(readonly left: number, readonly top: number, readonly right: number, readonly bottom: number) { | ||
this.left = left; | ||
this.top = top; | ||
this.right = right; | ||
this.bottom = bottom; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Rect from "./Rect"; | ||
|
||
export default class Size { | ||
constructor(readonly width: number, readonly height: number) { | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
public rotate(): Size { | ||
return new Size(this.height, this.width); | ||
} | ||
|
||
public toRect(): Rect { | ||
return new Rect(0, 0, this.width, this.height); | ||
} | ||
|
||
public equals(o: Size): boolean { | ||
if (this === o) { | ||
return true; | ||
} | ||
if (o == null) { | ||
return false; | ||
} | ||
return this.width == o.width && this.height == o.height; | ||
} | ||
|
||
public toString(): string { | ||
return `Size{width=${this.width}, height=${this.height}}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
interface StreamInfoInterface { | ||
"width": number | ||
"height": number | ||
"frameRate": number | ||
"bitRate": number | ||
"type": string | ||
} | ||
|
||
export class StreamInfo { | ||
readonly width: number; | ||
readonly height: number; | ||
readonly frameRate: number; | ||
readonly bitRate: number; | ||
constructor(data: StreamInfoInterface) { | ||
if (typeof data.width !== 'number') { | ||
throw TypeError('Wrong width type'); | ||
} | ||
if (typeof data.height !== 'number') { | ||
throw TypeError('Wrong height type'); | ||
} | ||
if (typeof data.frameRate !== 'number') { | ||
throw TypeError('Wrong frameRate type'); | ||
} | ||
if (typeof data.bitRate !== 'number') { | ||
throw TypeError('Wrong bitRate type'); | ||
} | ||
this.width = data.width; | ||
this.height = data.height; | ||
this.frameRate = data.frameRate; | ||
this.bitRate = data.bitRate; | ||
} | ||
|
||
public equals(streamInfo: StreamInfo): boolean { | ||
if (streamInfo === null) { | ||
return false; | ||
} | ||
return this.width === streamInfo.width && | ||
this.height === streamInfo.height && | ||
this.frameRate === streamInfo.frameRate && | ||
this.bitRate === streamInfo.bitRate; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.