@@ -31,6 +31,10 @@ of this software and associated documentation files (the "Software"), to deal
3131import java .net .ConnectException ;
3232import java .net .Proxy ;
3333import java .net .URI ;
34+ import java .util .Base64 ;
35+ import java .util .HashMap ;
36+ import java .util .Map ;
37+
3438import org .java_websocket .client .WebSocketClient ;
3539import org .java_websocket .drafts .Draft ;
3640import org .java_websocket .exceptions .WebsocketNotConnectedException ;
@@ -63,8 +67,17 @@ public WebSocketTransmitter(Draft draft) {
6367 public void connect (String uri , RadioEvents events ) {
6468 final URI resource = URI .create (uri );
6569
70+ Map <String ,String > httpHeaders = new HashMap <>();
71+ String username = configuration .getParameter (JSONConfiguration .USERNAME_PARAMETER );
72+ String password = configuration .getParameter (JSONConfiguration .PASSWORD_PARAMETER );
73+ if (username != null && password != null ) {
74+ String credentials = username + ":" + password ;
75+ byte [] base64Credentials = Base64 .getEncoder ().encode (credentials .getBytes ());
76+ httpHeaders .put ("Authorization" , "Basic " + new String (base64Credentials ));
77+ }
78+
6679 client =
67- new WebSocketClient (resource , draft ) {
80+ new WebSocketClient (resource , draft , httpHeaders ) {
6881 @ Override
6982 public void onOpen (ServerHandshake serverHandshake ) {
7083 logger .debug ("On connection open (HTTP status: {})" , serverHandshake .getHttpStatus ());
0 commit comments