Oups above forget the name of Static/js file which is :
websocket_connected_user.js
and there is this file missing :
*# Static/js*
*# userConnection.js*
// NEED DESCRIPTION
function userCommunication() {
this.ipToranado = "";
this.userId = "";
this.adressServer = "";
this.userConnection = null;
this.initCommunication = function(ipAdress, idUser) {
if(this.userConnection != null) {
this.closeConnection();
}
this.ipTornado = ipAdress;
this.userId = idUser;
this.adressServer =
"ws://"+this.ipTornado+"/realtime/user_"+this.userId;
this.userConnection = new WebSocket(this.adressServer);
};
// Gets//
this.getUserConnection = function () {
return this.userConnection;
};
this.getIpTornado = function() {
return this.ipToranado;
};
this.getUserId = function() {
return this.userId;
};
this.getAdresseServer = function() {
return this.adressServer();
};
// Set //
this.setConnection = function(connection) {
this.userConnection = connection;
};
this.setIpTornado = function(ipTornado) {
this.ipToranado = ipTornado;
};
this.setUserId = function(userId) {
this.userId = userId;
};
this.setAdresseServer = function(adressServer) {
this.adressServer = adressServer;
};
// Utility Functions //
this.rebuildConnection = function() {
if(this.ipToranado != null && this.userId != null) {
this.initCommunication(this.ipToranado, this.userId);
return this.userConnection;
}
};
// callback sets //
/*
Function: setBehaviorOnReceiveJsonMessage
Goal: this fhis function set the beheavior of the OnMessage callback
for the websocket
Parameter: fucntionOfReturn: anonymous JS function that contain the
logic of the treatment of the
callback. This function need to take in
parameter the server answer's
*/
this.setBehaviorOnReceiveJsonMessage = function(functionOfReturn) {
if(this.userConnection != null) {
this.getUserConnection().onmessage = function (e) {
functionOfReturn(e);
};
}
else {
alert("No connection has been establish yet...");
}
};
this.send = function(content) {
this.userConnection.send(content);
};
// Closing Function //
this.closeConnection = function() {
this.userConnection.close();
this.userConnection = null;
};
this.clearConnection = function() {
this.setIpTornado("");
this.setUserId("");
this.setAdresseServer("");
this.closeConnection();
};
}
On Fri, Jul 10, 2015 at 3:26 PM, Samuel Sowah <[email protected]>
wrote:
> By 'online user' i mean clients that have a websocket connection.
>
>
> On Friday, July 10, 2015 at 7:12:50 PM UTC, JorgeH wrote:
>>
>> Hah
>>
>> Be patient.. Don't expect other people to answer right away. Rest assured
>> your question is being read. That doesn't mean that everyone have the
>> answer at hand.
>>
>>
>> I have never done what you need but I am guessing you have to define
>> what an 'online user is'
>> Does it mean users logged in? In that case
>>
>> I suppose you create a controller to query the user_cas table to see how
>> many are online, and via ajax, create a view that shows the number of users
>> online.
>>
>>
>>
>>
>>
>>
>> On Friday, July 10, 2015 at 1:32:06 PM UTC-5, Samuel Sowah wrote:
>>>
>>> I need help please... anyone?
>>>
>>> This thread keeps going down the list and I'm afraid it might get
>>> missing and go unanswered :/
>>>
>>> On Friday, July 10, 2015 at 12:20:39 PM UTC, Samuel Sowah wrote:
>>>>
>>>> I checked out the web2py.js file and it looks like what i'm looking for
>>>> is right in there but i really do not know how to implement this. I
>>>> realized I can take advantage of the web2py_websocket function's onopen
>>>> argument and write a function to tell that that user is online, and when
>>>> the browser tab or window is closed, I'd write a function to execute for
>>>> onclose.
>>>>
>>>> The problem I have now is what function to write. I want to store the
>>>> ids of all the connected users somewhere so i can refer to it and use it to
>>>> get whatever information i want (i.e. a count of all users online, urls to
>>>> their profile pages, etc), and then when they close the page, their ids are
>>>> removed from wherever i'm storing it.
>>>>
>>>> Is it possible to keep that list of ids in a database, or a list, and
>>>> still update the page in real time when more users connect and disconnect?
>>>>
>>>> Scenario.
>>>> There are 0 users online right now. When I visit the website, I want to
>>>> see the number automatically say 1 users online. and when my friend also
>>>> goes to the page on his computer, I want to see in my browser 2 users
>>>> online. When he leaves the page/closes the page, I want to see in my
>>>> browser 1 users online without having to refresh the page.
>>>>
>>>> I don't know if I'm thinking about this correctly so I need some help
>>>> and guidance here, thanks.
>>>>
>>> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.