Skip to content

Commit c47a23f

Browse files
author
lijiahao
committed
feat: send text in stream view
1 parent 945ed28 commit c47a23f

File tree

12 files changed

+127
-16
lines changed

12 files changed

+127
-16
lines changed

app/background.js

Lines changed: 11 additions & 3 deletions
Large diffs are not rendered by default.

main/ipc/consoles.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class IpcConsoles extends IpcBase {
3333
linkedXboxId: consoleId,
3434
};
3535

36-
return new Promise((resolve, reject) => {
36+
return new Promise((resolve) => {
3737
http
3838
.post(
3939
'xccs.xboxlive.com',
@@ -87,7 +87,6 @@ export default class IpcConsoles extends IpcBase {
8787
}
8888

8989
powerOn(consoleId: string) {
90-
console.log('consoleId:', consoleId)
9190
return new Promise((resolve, reject) => {
9291
this.sendCommand(consoleId, 'Power', 'WakeUp').then(res => {
9392
resolve(res)
@@ -97,6 +96,15 @@ export default class IpcConsoles extends IpcBase {
9796
});
9897
}
9998

99+
sendText(params) {
100+
const { consoleId, text } = params
101+
return this.sendCommand(consoleId, 'Shell', 'InjectString', [
102+
{
103+
replacementString: text,
104+
},
105+
]);
106+
}
107+
100108
powerOff(consoleId: string) {
101109
return new Promise((resolve, reject) => {
102110
this.sendCommand(consoleId, 'Power', 'TurnOff').then(res => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"uplot": "^1.6.30",
4040
"uuid-1345": "^1.0.2",
4141
"xbox-webapi": "^1.4.1",
42-
"xstreaming-player": "0.2.7",
42+
"xstreaming-player": "0.2.9",
4343
"xvfb-maybe": "^0.2.1"
4444
},
4545
"devDependencies": {

renderer/components/ActionBar.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function ActionBar(props) {
7878
props.onAudio && props.onAudio();
7979
};
8080

81+
const handleText = () => {
82+
props.onText && props.onText();
83+
};
84+
8185
const handlePressNexus = () => {
8286
props.onPressNexus && props.onPressNexus();
8387
};
@@ -117,12 +121,20 @@ function ActionBar(props) {
117121

118122
{
119123
props.connectState === CONNECTED && (
120-
<DropdownItem key="display" onClick={handleAudio}>
124+
<DropdownItem key="audio" onClick={handleAudio}>
121125
{t("Audio settings")}
122126
</DropdownItem>
123127
)
124128
}
125129

130+
{
131+
(props.connectState === CONNECTED && props.type !== 'cloud') && (
132+
<DropdownItem key="text" onClick={handleText}>
133+
{t("Send text")}
134+
</DropdownItem>
135+
)
136+
}
137+
126138
{
127139
props.connectState === CONNECTED && (
128140
<DropdownItem key="pressNexus" onClick={handlePressNexus}>

renderer/components/TextModal.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { useState } from "react";
2+
import {
3+
Modal,
4+
ModalContent,
5+
ModalHeader,
6+
ModalBody,
7+
ModalFooter,
8+
Button,
9+
Input,
10+
} from "@nextui-org/react";
11+
import { useTranslation } from "next-i18next";
12+
13+
function TextModal(props) {
14+
const { t } = useTranslation('cloud');
15+
const [text, setText] = useState('')
16+
const [loading, setLoading] = useState(false)
17+
18+
const handleClose = () => {
19+
props.onClose && props.onClose();
20+
};
21+
22+
const handleConfirm = () => {
23+
props.onConfirm && props.onConfirm(text);
24+
setLoading(true)
25+
setTimeout(() => {
26+
setLoading(false)
27+
}, 1000)
28+
};
29+
30+
return (
31+
<Modal isOpen={true} className="z-100" onClose={handleClose}>
32+
<ModalContent>
33+
<>
34+
<ModalHeader className="flex flex-col gap-1">{t('Send text')}</ModalHeader>
35+
<ModalBody>
36+
<Input label="Text" placeholder="Enter text" onValueChange={value => setText(value)}/>
37+
</ModalBody>
38+
<ModalFooter>
39+
<Button color="default" onPress={handleClose}>
40+
{t("Cancel")}
41+
</Button>
42+
<Button color="primary" isLoading={loading} onPress={handleConfirm}>
43+
{t("Confirm")}
44+
</Button>
45+
</ModalFooter>
46+
</>
47+
</ModalContent>
48+
</Modal>
49+
);
50+
}
51+
52+
export default TextModal;

renderer/pages/[locale]/stream.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import FailedModal from "../../components/FailedModal";
1010
import Loading from "../../components/Loading";
1111
import Perform from "../../components/Perform";
1212
import WarningModal from "../../components/WarningModal";
13+
import TextModal from "../../components/TextModal";
1314
import { useSettings } from "../../context/userContext";
1415
import { getStaticPaths, makeStaticProperties } from "../../lib/get-static";
1516
import Ipc from "../../lib/ipc";
@@ -38,6 +39,7 @@ function Stream() {
3839
const [showWarning, setShowWarning] = useState(false);
3940
const [showDisplay, setShowDisplay] = useState(false);
4041
const [showAudio, setShowAudio] = useState(false);
42+
const [showTextModal, setShowTextModal] = useState(false);
4143
const [volume, setVolume] = useState(1);
4244
const [streamingType, setStreamingType] = useState('');
4345
const [consoleId, setConsoleId] = useState('');
@@ -484,6 +486,13 @@ function Stream() {
484486
});
485487
}
486488

489+
const handleSendText = (text: string) => {
490+
Ipc.send("consoles", "sendText", {
491+
consoleId,
492+
text
493+
});
494+
}
495+
487496
const onDisconnect = () => {
488497
setLoading(true);
489498
setShowPerformance(false);
@@ -558,6 +567,7 @@ function Stream() {
558567
}}
559568
onDisplay={() => setShowDisplay(true)}
560569
onAudio={() => setShowAudio(true)}
570+
onText={() => setShowTextModal(true)}
561571
onPressNexus={handlePressNexus}
562572
onLongPressNexus={handleLongPressNexus}
563573
/>
@@ -592,6 +602,22 @@ function Stream() {
592602
/>
593603
)}
594604

605+
{
606+
showTextModal && (
607+
<TextModal
608+
onClose={() => setShowTextModal(false)}
609+
onConfirm={value => {
610+
let text = value.trim()
611+
if (!text) return
612+
if (text.length > 150) {
613+
text = text.substring(0, 150);
614+
}
615+
handleSendText(text)
616+
}}
617+
/>
618+
)
619+
}
620+
595621
{showAudio && (
596622
<Audio
597623
volume={volume}

renderer/public/locales/en/cloud.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@
3939
"Keep waiting": "Keep waiting",
4040
"Audio": "Audio",
4141
"Volume": "Volume",
42-
"Audio settings": "Audio settings"
42+
"Audio settings": "Audio settings",
43+
"Send text": "Send text"
4344
}

renderer/public/locales/jp/cloud.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@
3939
"Keep waiting": "Keep waiting",
4040
"Audio": "Audio",
4141
"Volume": "Volume",
42-
"Audio settings": "Audio settings"
42+
"Audio settings": "Audio settings",
43+
"Send text": "Send text"
4344
}

renderer/public/locales/pt/cloud.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@
4848
"Connected": "Conectado",
4949
"Audio": "Audio",
5050
"Volume": "Volume",
51-
"Audio settings": "Audio settings"
51+
"Audio settings": "Audio settings",
52+
"Send text": "Send text"
5253
}

renderer/public/locales/zh/cloud.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@
4949
"Disconnecting...": "正在断开连接...",
5050
"Audio": "声音",
5151
"Volume": "音量",
52-
"Audio settings": "声音设置"
52+
"Audio settings": "声音设置",
53+
"Send text": "发送文字"
5354
}

0 commit comments

Comments
 (0)