Giter Site home page Giter Site logo

Comments (21)

yong2khoo88 avatar yong2khoo88 commented on May 18, 2024 1

Hi Phantom,

I think you are almost right (with those parameters). I have tested with the local machine and it seems working. The conclusion is, it is feasible. (a bit of trouble but still it works) I have to thank you for your insights provided. I can rest in peace now. lol

[you may close this post :)]

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

Hi,

You can implement this on several ways. For example in AIR mobile I detect when the user leaves the chat screen, when that happens I close and dispose the URLStream.

You only need to do something like:

myURLStream.removeEventListener(ProgressEvent.PROGRESS, myFunction);

myFunction is the same function that receives the messages.

You can see a full implementation in the following file:

https://github.com/PhantomAppDevelopment/pizza-app/blob/master/src/chatScreens/ChatScreen.as#L239

In the previous example on the dispose() function I can do anything I want, such as cleaning up objects or sending a request to the server.

from firebase-as3.

yong2khoo88 avatar yong2khoo88 commented on May 18, 2024

Hi agentphantom, sorry i don't quite get it. The onDisconnect is "used to manage operations that will be run on the server when the clients disconnect". Here, what i mean is when the user suddenly loses the internet connection. The onDisconnect is used to 'pre-define' what actions to be executed on the database (such as removes the user ID) when the server detects that the user has been disconnected.

When you mention 'dispose()' function, how does it 'send a request to the server' when it is already disconnected (say he loses internet connection)?
Or, How can other users tell when one of the users has lost the internet connection?

In javascript, the code is something like this:

var userRef = new Firebase('https://<demo>.firebaseio.com/presence/' + userid);
amOnline.on('value', function(snapshot) {
  if (snapshot.val()) {
    userRef.onDisconnect().remove(); //this line is able to remove his own node as soon as he is disconnected
    userRef.set(true);
  }
});

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

Hi,

Now I fully understand what you mean. Right now the REST API and by extension the AS3 API officially don't support this feature (unless you use an ANE).

I took a look at the JavaScript SDK and found out that the onDisconnect function sends a small request to the server with specific strings "cancel", "remove", "set".

Problem is, the JavaScript SDK is minified, and that's just an educated guess from what I could understand.

Maybe it can be ported for AS3, but I don't know enough JavaScript to debug it. If you wish you can give it a try with JavaScript, debug all the requests that are sent, paste them here and then I can port it to AS3.

from firebase-as3.

yong2khoo88 avatar yong2khoo88 commented on May 18, 2024

Thanks for your reply. To be honest, i have no idea how to debug this. The network tab on the browser shows nothing even though i debug through the codes line by line. Anyway, i will continue looking into this.

from firebase-as3.

yong2khoo88 avatar yong2khoo88 commented on May 18, 2024

I posted the question in stackoverflow. Meanwhile, i found an un-minified version of the firebase at here. Still in the attempts of understanding the magic behind...

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

Thanks!

I read the question and they have the right idea. Monitoring the outgoing traffic will do the trick.
I believe that a network analyzer like Wireshark can do the job.

Meanwhile I will keep reading the JS file to see if I can find the answer there.

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

This block looks interesting:

onDisconnectPut:function(pathString, data, opt_onComplete) { if (this.connected_) { this.sendOnDisconnect_("o", pathString, data, opt_onComplete); } else { this.onDisconnectRequestQueue_.push({pathString:pathString, action:"o", data:data, onComplete:opt_onComplete}); } }, onDisconnectMerge:function(pathString, data, opt_onComplete) { if (this.connected_) { this.sendOnDisconnect_("om", pathString, data, opt_onComplete); } else { this.onDisconnectRequestQueue_.push({pathString:pathString, action:"om", data:data, onComplete:opt_onComplete}); } }, onDisconnectCancel:function(pathString, opt_onComplete) { if (this.connected_) { this.sendOnDisconnect_("oc", pathString, null, opt_onComplete); } else { this.onDisconnectRequestQueue_.push({pathString:pathString, action:"oc", data:null, onComplete:opt_onComplete}); }

from firebase-as3.

yong2khoo88 avatar yong2khoo88 commented on May 18, 2024

I finally saw something like this at the network tab:
fb

it seems like web socket or sth.

And when i click on that, it shows:
fb2

(the 'ns' is my firebase namespace).

I am not sure if the normal REST API through urlrequest is able to achieve this, as mentioned by one guy in the stackoverflow....

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

Thanks for sharing those pictures!

Maybe the 'v' parameter does something special.

URLStream behaves almost the same as a websocket, the difference is that all the headers and responses are abstracted so you have an easier time sending and receiving them.

Disregard the commend about URLRequest, that guy doesn't know what he's talking about. URLRequest just describes what you want to do, it doesn't do any net connection by itself.

My recommendation is to find a way to read the outgoing traffic, there lies the answer.

from firebase-as3.

yong2khoo88 avatar yong2khoo88 commented on May 18, 2024

Thank you for your reply. Allow me to spend more time on this before making a conclusion.

from firebase-as3.

yong2khoo88 avatar yong2khoo88 commented on May 18, 2024

wireshark

Sorry for the long delay. Finally i am trying to use wireshark to capture something... However, i don't i think i understand what is being captured, as attached.

The only recognize-able letters are .....firebaseio.com.....
Did i miss out something in the wireshark?

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

Hi,

My bad! I did some research and Wireshark is to analyze traffic after it has been processed, that's why the output is encrypted.

I recommend to use Fiddler: http://www.telerik.com/fiddler

This one analyzes the HTTP and HTTPS requests before they are sent (similar to the ones you added here some days ago), but it says its more complete.

If you wish you can give it another go with Fiddler and report back your findings.

from firebase-as3.

yong2khoo88 avatar yong2khoo88 commented on May 18, 2024

Hi,
I managed to install and try the Fiddler. But I have no idea which part of the tabs show the 'data transferred' over the network. For example, if i perform login to facebook, i expect my username and password to be captured through the fiddler right? But i see nothing meaningful... Correct me if i am wrong.

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

You can try these tutorials, they look very useful:

https://www.ibm.com/developerworks/community/blogs/f37f6f3c-d39f-49c9-884b-a1665b7e2ca3/entry/tutorial_how_to_capture_http_traffic_using_the_fiddler_web_debugging_proxy?lang=en

http://www.infragistics.com/community/blogs/anton_staykov/archive/2010/08/24/how-to-debug-your-application-http-protocol-using-fiddler.aspx

from firebase-as3.

yong2khoo88 avatar yong2khoo88 commented on May 18, 2024

Hi Phantom,
I think i saw something. But before anything, could you please tell me how to connect to 'websocket' in AS3?

Say the end point is sth like:
..wss://s-usc1c-nss-129.firebaseio.com/.ws?...
i don't think URLLoader or URLRequest would work.

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

HI,

I haven't tried this but it looks very complete and useful:
https://github.com/theturtle32/AS3WebSocket

Seeing at the examples it is very similar to setup like an URLStream.

from firebase-as3.

yong2khoo88 avatar yong2khoo88 commented on May 18, 2024

Thanks for you reply. i actually tried that. but it throws some errors:
Definition com.adobe.net.URI could not be found.
Definition com.adobe.net.URIEncodingBitmap could not be found.
Definition com.adobe.utils.StringUtil could not be found.

Anyway, this is what i found. i use websocket plugin from firefox instead, that enables me to view what has been sent to the firebase
ws
However, that seems to be sent over the websocket, but not throught database REST API?

from firebase-as3.

yong2khoo88 avatar yong2khoo88 commented on May 18, 2024

My Bad, i didn't include the as3corlib. Now seems i am able to 'connect'. I will further post after more testing.

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

Ohh, interesting.

It sends a nested JSON with different parameters:

t (type maybe?) = "d" (probably refers to disconnect
d (a data object containing the payload)
r (no idea) = 4 (maybe it is a priority of some sorts)
a (action maybe) = "o" could be linked to a specific task such as on disconnected, I remember there are several onDisconnect variations.
b (a nested object containing the data, no clue what b could stand for)
p (path) = /allUser/3
d (data) = "Hey I'm disconnect"

With this new finding I can take another look at the unminified library.

I will update this comment if I find something new.

Thanks!

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

That's great!

I will experiment with it and add it to the guide in the coming weeks.

from firebase-as3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.