arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
WebSocketOutput.h
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
6namespace audio_tools {
7
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
Abstract Audio Ouptut class.
Definition AudioOutput.h:22
A simple wrapper class that lets you use the standard Arduino Print class output commands to send aud...
Definition WebSocketOutput.h:18
WebSocketOutput(WebSocketsClient &ws)
Constructor which defines an alternative WebSocket object. By default we use WebSocket.
Definition WebSocketOutput.h:23
size_t write(const uint8_t *data, size_t len) override
Replys will be sent to the initial remote caller.
Definition WebSocketOutput.h:36
void setTargetNo(int clientNo)
For WebSocketServer we can define an individual recipient!
Definition WebSocketOutput.h:52
WebSocketOutput(WebSocketsServer &ws)
Constructor which defines an alternative WebSocket object. By default we use WebSocket.
Definition WebSocketOutput.h:26
void setWebSocket(WebSocketsClient &ws)
Defines an alternative WebSocket object. By default we use WebSocket.
Definition WebSocketOutput.h:30
void setWebSocket(WebSocketsServer &ws)
Defines an alternative WebSocket object. By default we use WebSocket.
Definition WebSocketOutput.h:33
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10