mirror of https://github.com/waku-org/js-waku.git
Implement /nick command
This commit is contained in:
parent
5ebceecf92
commit
f5edd09fa9
|
@ -15,6 +15,7 @@ export const ChatContentTopic = 'dingpu';
|
||||||
export default function App() {
|
export default function App() {
|
||||||
let [stateMessages, setMessages] = useState<ChatMessage[]>([]);
|
let [stateMessages, setMessages] = useState<ChatMessage[]>([]);
|
||||||
let [stateWaku, setWaku] = useState<Waku | undefined>(undefined);
|
let [stateWaku, setWaku] = useState<Waku | undefined>(undefined);
|
||||||
|
let [nick, setNick] = useState<string>('web-chat');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function initWaku() {
|
async function initWaku() {
|
||||||
|
@ -80,11 +81,21 @@ export default function App() {
|
||||||
} else {
|
} else {
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case '/help':
|
case '/help':
|
||||||
|
commandResponses.push('/nick <nickname>: set a new nickname');
|
||||||
commandResponses.push(
|
commandResponses.push(
|
||||||
'/connect <Multiaddr>: connect to the given peer'
|
'/connect <Multiaddr>: connect to the given peer'
|
||||||
);
|
);
|
||||||
commandResponses.push('/help: Display this help');
|
commandResponses.push('/help: Display this help');
|
||||||
break;
|
break;
|
||||||
|
case '/nick':
|
||||||
|
const arg = args.shift();
|
||||||
|
if (!arg) {
|
||||||
|
commandResponses.push('No nick provided');
|
||||||
|
} else {
|
||||||
|
setNick(arg);
|
||||||
|
commandResponses.push(`New nick: ${arg}`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case '/connect':
|
case '/connect':
|
||||||
const peer = args.shift();
|
const peer = args.shift();
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
|
@ -138,7 +149,11 @@ export default function App() {
|
||||||
<div className="chat-room">
|
<div className="chat-room">
|
||||||
<WakuContext.Provider value={{ waku: stateWaku }}>
|
<WakuContext.Provider value={{ waku: stateWaku }}>
|
||||||
<Paper>
|
<Paper>
|
||||||
<Room lines={stateMessages} commandHandler={commandHandler} />
|
<Room
|
||||||
|
nick={nick}
|
||||||
|
lines={stateMessages}
|
||||||
|
commandHandler={commandHandler}
|
||||||
|
/>
|
||||||
</Paper>
|
</Paper>
|
||||||
</WakuContext.Provider>
|
</WakuContext.Provider>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { useWaku } from './WakuContext';
|
||||||
interface Props {
|
interface Props {
|
||||||
lines: ChatMessage[];
|
lines: ChatMessage[];
|
||||||
commandHandler: (cmd: string) => void;
|
commandHandler: (cmd: string) => void;
|
||||||
|
nick: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Room(props: Props) {
|
export default function Room(props: Props) {
|
||||||
|
@ -25,7 +26,7 @@ export default function Room(props: Props) {
|
||||||
} else {
|
} else {
|
||||||
const chatMessage = new ChatMessage(
|
const chatMessage = new ChatMessage(
|
||||||
new Date(),
|
new Date(),
|
||||||
'web-chat',
|
props.nick,
|
||||||
messageToSend
|
messageToSend
|
||||||
);
|
);
|
||||||
const wakuMsg = WakuMessage.fromBytes(
|
const wakuMsg = WakuMessage.fromBytes(
|
||||||
|
|
Loading…
Reference in New Issue