Hi ,
Can you give some instruction about what happens when user click "stop using" on one specified device?
I can't see any request in the network. I tried to update the owner to null in device table, and UI seems to that device was released. But when I chose to use this device again, it can't show any device UI in control tab. I only need disconnect and reconnect this device again, it can work well again.
So it need your instruction about what happens when user click "stop using" on one specified device?
I want to release this device after use logout.
Thanks
Luis
The request goes through WebSockets. If you look at the picture here, the message flows as follows:
websocket units receives the message and translates it to Protocol Bufferswebsocket unit sends the message via PUSH to the app side triproxy's PULLtriproxy takes the message as-is and randomly forwards it via DEALER to one of the processor DEALERsprocessor doesn't do anything yet (although it could if necessary), it simply forwards the message via DEALER to the device side triproxy's DEALERtriproxy takes the message as-is and uses PUB to publish the message the the device's channel (which is included in the message)dev unit that is listening on that channel receives the message via its SUB.dev sends a GroupLeave message and sends it via PUSH to the device side triproxytriproxy takes the message as-is and randomly forwards it to one of the processor's DEALEREsprocessor receives the message, reads it, and modifies the database to remove the owner from that deviceprocessor forwards the message via DEALER to the app side triproxy's DEALERtriproxy receives the message and PUBs it to all the websocket unitswebsocket units receive information that the device no longer has an ownerwebsocket units emit a WebSocket message to all the connected browsersI'll admit that's a bit complicated, but it makes the system more scalable since you can easily increase the number of processors, websockets, and if necessary, triproxies as well. Nearly all internal communication in STF works this way.
If you remove the owner directly from the database, you skip step 8, and the device doesn't know it's no longer supposed to be in a group, since that information is also stored locally in memory. It will time out (i.e. automatically leave the group) after 15 minutes of inactivity, though, so it should eventually become usable.
Thanks for your rich answer. So if I want to logout with releasing the occupied devices, I need simulate above process? Can you share some stf code snippet which were used for 'stop using' action.
Thats a great life cycle explanation, Simo. I think, it would be great if you can write a document explaining STF architecture to speed up contribution from others.
@luisxiaomai
I tried to put the whole event cycle in diagram. If you read Simo's explanation with this image, It will be easy to understand.

@vbanthia good job. BTW, you lost stf device. stf-device should inside stf-provider.
Also we don't actually use RotationWatcher.apk in STF. It's a companion program for minicap in case you want to use it by itself :) Otherwise it's very nice.
Nice graph, perhaps we could add it to README or DEPLOYMENT.
Really great diagram, gives a good overview of how the services interact.
I'd be very interested as well in an explanation of how to claim/release devices, as well as getting the adb connection string without having a browser involved.
@sorccu, @gunta @vbanthia @codeskyblue I read the front end code. When user clicks the "stop using" on one using device, browser sends the websocket message which is triggered by pure front end code, I want to know how I can simulate this in backend because I want to release all current user using devices when user session timeout or user logout.
so this question has already been resolved? I meet the same problem now @sorccu, @gunta @vbanthia @codeskyblue
my user always close the browser directly, so the other user must wait for the device to be timeout
@LiufxLucky365 having to wait for timeout is a different issue, open a new ticket for it.
open a new ? but my problem is the same with luisxiaomai , when my user logout, the other users cannot use that device until timeout.
BTW, #152 can you cost some time to answer me ? Thanks
@LiufxLucky365 actually its a different problem.
A) luisxiaomai wants a way to stop all the devices on user logout (we don't have a sign-out UI yet).
B) You want to stop the devices being used by your users because they close the browser directly.
Adding logout support will not fix your issue because your users will still be closing the browser directly, thus not logout.
What could fix the issue for your users could be: 1) lower the timeout to something like 30 seconds, or 2) add an option to release the devices on window.close.
@gunta Thanks for your help, that's helpful.
I think if i can supply some big 'logout' button, they would like to click it. But like luisxiaomai, how I can simulate this in backend. Now what i do is that when user logout, update the device owner as 'null', then wait the device to timeout. Is there another better way to release the device ?
BTW, where can i set the timeout option ?
Thanks
provider unit has timeout option, by default it is 15mins. So device will be released automatically after 15mins if kept idle. If you are running stf local then you can set it using --group-timeout options
stf local --group-timeout 60
If you are running using docker then you will have to set this option in provider unit.
Is there another better way to release the device ?
I don't think there is any better way but there is an easter egg. Just press Konami code when you are on device list { up up down down left right left right enter }. You will see a dialogue which will make you "admin" and then you can steal anyone's device. But do remember _with great power comes great responsibility_. So use it wisely.
@LiufxLucky365 @gunta @vbanthia , my question is not to provide a logout function. My question is how I can simulate "release devices" in backend, whatever I want to do this when I logout or my trial time is over. I want to implement this similar features.
I have a similar need. The primary need of my stakeholders is to get adb connection strings as easily as possible. So getting a list of devices (and whether they are claimed or not), claiming devices and releasing devices should ideally be done purely through API.
Trying to get some node knowledge in order to dive in and figure it out myself, but any pointers would be appreciated.
@luisxiaomai Have you implemented that features now ?
There is a similar issue, https://github.com/openstf/stf/issues/38
I started implementing RESTful devices/:serial/reserve & devices/:serial/release endpoints. But found its too complex because STF uses websocket for most of the client-server communication (which is good because it makes it real time app). And also, it checks xcrf token in each request which makes it kind of more difficult to create stateless apis. So I kind of gave up in between.
If anyone wants to give it a try, I can write what approach I was using but I will suggest to get it reviewed from STF developers before any implementation.
After this you will be able to access all STF apis from any http client library using command line.
connect.start message to server and get remote debug url.Last part being implement a good stf command line client which can use these endpoints easily.
I hope this will help.
Most helpful comment
@luisxiaomai
I tried to put the whole event cycle in diagram. If you read Simo's explanation with this image, It will be easy to understand.