Closed nhouse closed 8 years ago
I found the following article on your blog which is very helpful: http://voryx.net/creating-a-custom-php-wamp-client-for-thruway/
Maybe link to it from the readme?
@nhouse we do plan to improve our documentation over the next couple of weeks/months. Right now, it's just a couple of blog posts and the examples. The plan is to move everything over to the wiki.
In addition to that blog post, you can use the Autobhan.js documentation for a reference when using the Connection
class and just make the necessary language translations.
For example in Authbahn.js this is how you would create a new connection:
var connection = new autobahn.Connection(
{
url: 'ws://127.0.0.1:9000/',
realm: 'realm1'
//other connection options
}
);
connection.onopen = function (session) {
// Do stuff with session here
};
connection.open();
In Thruway with the Connection
class:
$connection = new Connection(
[
"url" => 'ws://127.0.0.1:9000',
"realm" => 'realm1'
//other connection options
]
);
$connection->on('open', function (ClientSession $session) {
//Do stuff with $session here
});
$connection->open();
In Thruway with the Client
class:
$client = new \Thruway\Peer\Client("realm1");
$client->on( 'open', function (ClientSession $session) {
//Do stuff with $session here
});
$client->addTransportProvider(new \Thruway\Transport\PawlTransportProvider( 'ws://127.0.0.1:9000'));
$client->start();
And here's a subscribe example:
In Autobahn.js:
function on_event1(args, kwargs, details) {
// event received, do something ..
}
session.subscribe('com.myapp.topic1', on_event1).then(
function (subscription) {
// subscription succeeded, subscription is an instance of autobahn.Subscription
},
function (error) {
// subscription failed, error is an instance of autobahn.Error
}
);
And in Thruway with both the Connection
and Client
classes:
$onevent = function ($args, $argskw, $details) {
// event received, do something ..
};
$session->subscribe('com.myapp.topic1', $onevent) ->then(
function($subscription){
// subscription succeeded, $subscription is an instance of SubscribedMessage
},
function($error){
// subscription failed, $error is an instance of ErrorMessage
}
);
Let me know if you have any other question. We're more than happy to help.
Hope its for me to post a quick question in here as well!
Is the Manager just a more specific type of internal client? Why should I choose which?
@commercial-hippie The Manager is a specific type of client that adds management RPCs to the router. It's completely optional and should only be used if you need to access things like the current list of sessions or registrations.
Thruway basically has four components, the Router, Clients, Modules and the Manager.
The router is a generic WAMPv2 router, which does not have any business logic in it.
The clients are regular WAMPv2 clients that have all the business logic and run in a separate process.
Modules and the Manager are sort of a combination of both, they're clients that also have direct access to the router instance. They're used to add additional features to the router and run within the same process. If you take a look at TestServer.php
in tests, you can see a list of the currently supported (optional) modules. https://github.com/voryx/Thruway/blob/master/tests/TestServer.php
The main difference between modules and the manager is how they're instantiated. In the future we may rework the manager to be a module to simplify things.
There are almost non doumentation for this project
Thanks for your work developing this library. Thruway looks like a big improvement over Ratchet and as far as I can tell is the only PHP library which supports WAMP V2.
I'm struggling to port my code over because there doesn't seem to be any documentation aside from the readme. There are examples in the
Examples
folder, but there's no documentation on (or in) them, either.For example, I'm trying to understand the difference between
ClientExample.php
andSimpleClient.php
and am just totally confused. There's no explanation given at all and I'm struggling to learn how to use the library due to it's size.Are there any plans on writing documentation for Thruway? Something like the Ratchet documentation, which gives a high level overview of all of the components along with examples, would be really helpful.