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

Added a quiet mode #86

Open
wants to merge 3 commits 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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ npm install -g wscat

## Usage

### Connect
```
$ wscat -c ws://echo.websocket.org
connected (press CTRL+C to quit)
Expand All @@ -21,6 +22,39 @@ connected (press CTRL+C to quit)
< are you a happy parrot?
```

### Control Frames
To issue control frames, start wscat with `--slash`, i.e.
```
$ wscat --slash -c ws://echo.websocket.org
connected (press CTRL+C to quit)
> /ping
< Received pong
```

By default wscat will print to console when it recieves a ping, which can mess
up the users typing, i.e.
```
$ wscat -c ws://echo.websocket.org
connected (press CTRL+C to quit)
< Received ping
< Received ping
< Received ping
> w are youHello user ho # Typed Hello user how are you
< Received ping
```

By using `--quiet` pings will be recieved and a pong will be sent back in the
background, and not be printed to console. All other control frames will be
visible, i.e.
```
$ wscat --slash --quiet --ws://echo.websocket.org
> Hello
> /ping
< Received pong
> How are you?
> 'Look ma, know ping messages'
```

## License

MIT
16 changes: 11 additions & 5 deletions bin/wscat
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ program
'Enable slash commands for control frames ' +
'(/ping, /pong, /close [code [, reason]])'
)
.option(
'-q, --quiet',
'Stops incoming ping control frame being printed to console.'
)
.parse(process.argv);

if (program.listen && program.connect) {
Expand Down Expand Up @@ -323,11 +327,13 @@ if (program.listen) {
});

ws.on('ping', () => {
wsConsole.print(
Console.Types.Incoming,
'Received ping',
Console.Colors.Blue
);
if (!program.quiet){
wsConsole.print(
Console.Types.Incoming,
'Received ping',
Console.Colors.Blue
);
}
});

ws.on('pong', () => {
Expand Down