SocketInterface createSocket ( @ NonNull final String token , @ NonNull final WeakReference < SocketStateListener > stateListenerWeakReference ) { WebSocket socket = null ; WebSocketFactory factory = new WebSocketFactory ( ) ; // Configure proxy if provided if ( proxyAddress != null ) { ProxySettings settings = factory . getProxySettings ( ) ; settings . setServer ( proxyAddress ) ; } try { socket = factory . createSocket ( uri , TIMEOUT ) ; } catch ( IOException e ) { log . f ( "Creating socket failed" , e ) ; } if ( socket != null ) { String header = AuthManager . AUTH_PREFIX + token ; socket . addHeader ( "Authorization" , header ) ; socket . addListener ( createWebSocketAdapter ( stateListenerWeakReference ) ) ; socket . setPingInterval ( PING_INTERVAL ) ; return new SocketWrapperImpl ( socket ) ; } return null ; }
Creates and configures web socket instance .