@@ -22,9 +22,25 @@ class RealtimeApi implements Traceable, Value {
2222 private $ ws , $ marshalling ;
2323 private $ cat = null ;
2424
25- /** @param string|util.URI|websocket.WebSocket $endpoint */
26- public function __construct ($ endpoint ) {
27- $ this ->ws = $ endpoint instanceof WebSocket ? $ endpoint : new WebSocket ((string )$ endpoint );
25+ /**
26+ * Creates a new realtime API instance
27+ *
28+ * @param string|util.URI|websocket.WebSocket $endpoint
29+ * @param [:string] $parameters
30+ */
31+ public function __construct ($ endpoint , array $ parameters = []) {
32+ if ($ endpoint instanceof WebSocket) {
33+ $ this ->ws = $ endpoint ;
34+ } else if ($ parameters ) {
35+ $ uri = $ endpoint instanceof URI ? $ endpoint ->using () : (new URI ($ endpoint ))->using ();
36+ foreach ($ parameters as $ name => $ value ) {
37+ $ uri ->param ($ name , $ value );
38+ }
39+ $ this ->ws = new WebSocket ($ uri ->create ());
40+ } else {
41+ $ this ->ws = new WebSocket ($ endpoint );
42+ }
43+
2844 $ this ->marshalling = (new Marshalling ())->mapping (Tools::class, function ($ tools ) {
2945 foreach ($ tools ->selection as $ select ) {
3046 if ($ select instanceof Functions) {
@@ -43,6 +59,9 @@ public function __construct($endpoint) {
4359 });
4460 }
4561
62+ /** @return string */
63+ public function path () { return $ this ->ws ->path (); }
64+
4665 /** @return peer.Socket */
4766 public function socket () { return $ this ->ws ->socket (); }
4867
0 commit comments