@@ -93,57 +93,49 @@ std::shared_future<void> Cleanup() { return impl::Init::Instance().cleanup(); }
93
93
94
94
void SetSctpSettings (SctpSettings s) { impl::Init::Instance ().setSctpSettings (std::move (s)); }
95
95
96
- std::map<int , UnhandledStunRequestHandler *> unboundStunCallbacks;
97
-
98
96
#if !USE_NICE
99
97
100
- void InvokeUnhandledStunRequestCallback (const juice_mux_binding_request *info, void *user_ptr) {
101
- PLOG_DEBUG << " Invoking unhandled STUN request callback" ;
98
+ void InvokeIceUdpMuxCallback (const juice_mux_binding_request *info, void *user_ptr) {
99
+ PLOG_DEBUG << " Invoking ICE UDP mux callback" ;
102
100
103
- UnhandledStunRequestHandler *handler = (struct UnhandledStunRequestHandler *)user_ptr;
101
+ IceUdpMuxCallback *callback = (IceUdpMuxCallback *)user_ptr;
104
102
105
- if (handler-> callback ) {
106
- handler-> callback ({
103
+ if (callback) {
104
+ (* callback) ({
107
105
std::string (info->local_ufrag ),
108
106
std::string (info->remote_ufrag ),
109
107
std::string (info->address ),
110
108
info->port
111
- }, handler-> userPtr );
109
+ });
112
110
} else {
113
- PLOG_DEBUG << " No unhandled STUN request callback configured for port " << info->port ;
111
+ PLOG_DEBUG << " No ICE UDP mux callback configured for port " << info->port ;
114
112
}
115
113
}
116
114
117
115
#endif
118
116
119
- void OnUnhandledStunRequest ([[maybe_unused]] std::string host, [[maybe_unused]] int port, [[maybe_unused]] UnhandledStunRequestCallback callback, [[maybe_unused]] void *userPtr ) {
117
+ void ListenIceUdpMux ([[maybe_unused]] int port, [[maybe_unused]] IceUdpMuxCallback * callback, [[maybe_unused]] std::optional<std::string> bindAddress ) {
120
118
#if USE_NICE
121
- PLOG_WARNING << " BindStunListener is not supported with libnice, please use libjuice" ;
119
+ PLOG_WARNING << " ListenIceUdpMux is not supported with libnice, please use libjuice" ;
122
120
#else
123
- if (callback == NULL ) {
124
- PLOG_DEBUG << " Removing unhandled STUN request listener " ;
121
+ // NULL host binds to all available addresses
122
+ const char *host = bindAddress. has_value () ? bindAddress. value (). c_str () : NULL ;
125
123
126
- free (unboundStunCallbacks. at (port));
127
- unboundStunCallbacks. erase ( port) ;
124
+ if (callback == NULL ) {
125
+ PLOG_DEBUG << " Removing ICE UDP mux callback for port " << port ;
128
126
129
- // call with NULL callback to unbind
130
- if (juice_mux_listen (host. c_str () , port, NULL , NULL ) < 0 ) {
131
- throw std::runtime_error (" Could not unbind STUN listener " );
127
+ // call with NULL callback to remove the listener for the host/port
128
+ if (juice_mux_listen (host, port, NULL , NULL ) < 0 ) {
129
+ throw std::runtime_error (" Could not remove ICE UDP mux callback " );
132
130
}
133
131
134
132
return ;
135
133
}
136
134
137
- PLOG_DEBUG << " Adding listener for unhandled STUN requests" ;
138
-
139
- UnhandledStunRequestHandler *handler = (UnhandledStunRequestHandler*)calloc (1 , sizeof (UnhandledStunRequestHandler));
140
- handler->callback = std::move (callback);
141
- handler->userPtr = userPtr;
142
-
143
- unboundStunCallbacks[port] = handler;
135
+ PLOG_DEBUG << " Adding ICE UDP mux callback for port " << port;
144
136
145
- if (juice_mux_listen (host. c_str () , port, &InvokeUnhandledStunRequestCallback, handler ) < 0 ) {
146
- throw std::invalid_argument (" Could not add listener for unhandled STUN requests " );
137
+ if (juice_mux_listen (host, port, &InvokeIceUdpMuxCallback, callback ) < 0 ) {
138
+ throw std::invalid_argument (" Could not add ICE UDP mux callback " );
147
139
}
148
140
#endif
149
141
}
0 commit comments