@@ -32,24 +32,28 @@ function connector(?Connector $connector = null): Connector
3232}
3333
3434/**
35- * @param string|Handshake $handshake
36- * @param ConnectContext|null $connectContext
37- * @param CancellationToken|null $cancellationToken
35+ * @param string|WebsocketUri| Handshake $handshake
36+ * @param ConnectContext|null $connectContext
37+ * @param CancellationToken|null $cancellationToken
3838 *
3939 * @return Promise<Connection>
4040 *
41- * @throws \TypeError If $handshake is not a string or instance of \Amp\WebSocket\ Handshake.
41+ * @throws \TypeError If $handshake is not a string, instance of WebsocketUri, or instance of Handshake.
4242 * @throws ConnectionException If the connection could not be established.
4343 */
4444function connect (
4545 $ handshake ,
4646 ?ConnectContext $ connectContext = null ,
4747 ?CancellationToken $ cancellationToken = null
4848): Promise {
49- if (\is_string ($ handshake )) {
49+ if (\is_string ($ handshake ) || $ handshake instanceof WebsocketUri ) {
5050 $ handshake = new Handshake ($ handshake );
5151 } elseif (!$ handshake instanceof Handshake) {
52- throw new \TypeError (\sprintf ('Must provide an instance of %s or a websocket URL as a string ' , Handshake::class));
52+ throw new \TypeError (\sprintf (
53+ 'Must provide an instance of %s or a websocket URL as a string or instance of %s ' ,
54+ Handshake::class,
55+ WebsocketUri::class
56+ ));
5357 }
5458
5559 return connector ()->connect ($ handshake , $ connectContext , $ cancellationToken );
0 commit comments