arduino-audio-tools
Loading...
Searching...
No Matches
src
AudioTools
Communication
WebSocketOutput.h
Go to the documentation of this file.
1
#pragma once
2
#include "
AudioTools/CoreAudio/AudioOutput.h
"
3
#include "WebSocketsClient.h"
// https://github.com/Links2004/arduinoWebSockets
4
#include "WebSocketsServer.h"
// https://github.com/Links2004/arduinoWebSockets
5
6
namespace
audio_tools
{
7
18
class
WebSocketOutput
:
public
AudioOutput
{
19
public
:
20
WebSocketOutput
() =
default
;
23
WebSocketOutput
(
WebSocketsClient
&
ws
) {
setWebSocket
(
ws
); }
26
WebSocketOutput
(
WebSocketsServer
&
ws
) {
setWebSocket
(
ws
); }
27
30
void
setWebSocket
(
WebSocketsClient
&
ws
) {
p_ws
= &
ws
; };
33
void
setWebSocket
(
WebSocketsServer
&
ws
) {
p_ws_server
= &
ws
; };
34
36
size_t
write
(
const
uint8_t
*data,
size_t
len)
override
{
37
bool
rc
=
false
;
38
if
(
p_ws
!=
nullptr
)
rc
=
p_ws
->sendBIN(data, len);
39
if
(
p_ws_server
!=
nullptr
) {
40
if
(
clientNo
>= 0) {
41
rc
=
p_ws_server
->sendBIN(
clientNo
, data, len);
42
}
else
{
43
// broadcast to all clients
44
rc
=
p_ws_server
->broadcastBIN(data, len);
45
}
46
rc
=
p_ws_server
->broadcastBIN(data, len);
47
}
48
return
rc
? len : 0;
49
}
50
52
void
setTargetNo
(
int
clientNo
) { this->clientNo =
clientNo
; }
53
54
protected
:
55
WebSocketsClient
*
p_ws
=
nullptr
;
56
WebSocketsServer
*
p_ws_server
=
nullptr
;
57
int
clientNo
= -1;
58
};
59
60
}
// namespace audio_tools
AudioOutput.h
audio_tools::AudioOutput
Abstract Audio Ouptut class.
Definition
AudioOutput.h:25
audio_tools::WebSocketOutput
A simple wrapper class that lets you use the standard Arduino Print class output commands to send aud...
Definition
WebSocketOutput.h:18
audio_tools::WebSocketOutput::p_ws_server
WebSocketsServer * p_ws_server
Definition
WebSocketOutput.h:56
audio_tools::WebSocketOutput::WebSocketOutput
WebSocketOutput(WebSocketsClient &ws)
Constructor which defines an alternative WebSocket object. By default we use WebSocket.
Definition
WebSocketOutput.h:23
audio_tools::WebSocketOutput::write
size_t write(const uint8_t *data, size_t len) override
Replys will be sent to the initial remote caller.
Definition
WebSocketOutput.h:36
audio_tools::WebSocketOutput::setTargetNo
void setTargetNo(int clientNo)
For WebSocketServer we can define an individual recipient!
Definition
WebSocketOutput.h:52
audio_tools::WebSocketOutput::WebSocketOutput
WebSocketOutput(WebSocketsServer &ws)
Constructor which defines an alternative WebSocket object. By default we use WebSocket.
Definition
WebSocketOutput.h:26
audio_tools::WebSocketOutput::clientNo
int clientNo
Definition
WebSocketOutput.h:57
audio_tools::WebSocketOutput::p_ws
WebSocketsClient * p_ws
Definition
WebSocketOutput.h:55
audio_tools::WebSocketOutput::setWebSocket
void setWebSocket(WebSocketsClient &ws)
Defines an alternative WebSocket object. By default we use WebSocket.
Definition
WebSocketOutput.h:30
audio_tools::WebSocketOutput::setWebSocket
void setWebSocket(WebSocketsServer &ws)
Defines an alternative WebSocket object. By default we use WebSocket.
Definition
WebSocketOutput.h:33
audio_tools::WebSocketOutput::WebSocketOutput
WebSocketOutput()=default
audio_tools
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition
AudioCodecsBase.h:10
audio_tools::writeData
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition
AudioTypes.h:512
Generated by
1.9.8