SignalR: Get clients list for PersistentConnection - vb.net

I searched google, SignalR wiki and SignalR code itself (for example, Broadcast function, Signaler and more), and found nothing.
I wrote ClientIDFactory and successfuly set ClientID to UserID.
It works, but now user cannot connect from more than one browser/tab.
I modified the function and added random string to the UserID. It works.
Now I need to find a way to get all connections for user(s), to send specific message to specific UserID.
I think about looping around client list, and find the UserID by string.split(), but other ways may be usefull.
I am not using Hub. only PersistentConnection.
Thanks,

I think your approach is not right hence this has surfaced. You have connect and disconnect method on server side to hook into. On Connection you need to persist connection with some meta data and then even if server restarts you can check meta data for unique user or unique client and reconnect them with new ID.
For example
If you are buying an item from mobile and you are not logged in (no meta data to relate to user) and you place 2 items in your basket. When you go on your desktop you wont see those two items in basket because server cannot relate to you as same user coming from same machine.
If you are logged in (meta data like email or username attached to current connection ID) and you browse from mobile and add 2 items in basket. When you login to your desktop (the new Connection ID can then be linked with same meta data email or userid) and then you can tell that its same user. If you then need to send a message to that user you have to send it to two client IDs which you can do by grouping them or sending it to two IDs.
If client lost connection ID it should be disconnected and on new connection it will have new connection ID so you should be thinking about mapping them.
If I connect with 7 IDs from 7 different mobiles notification would be sent to all 7 as long as your system knows that they are all intended recipient of this notifications. Implementation of persisting this knowledge is not part of signalR and so you have to implement it yourself.

Related

XERO api remove tenant connections after login

We use XERO to authenticate and sign in to our app on firebase, however, we dont want a user to connect with multiple organisations, we just want a user to sign in and choose a single organisation.
If we remove all tenant connections from our app once a user have finished signing in, this will solve our problem, and we already do this upon logout for the same reason.
I just wanted to find out, is there any implications of doing this ? Will our logged in user still be able to make api calls and get new access tokens ?
I could not find any info of this in the XERO docs.
Thanks
The list of connected tenants represents the orgs the user has authorized your app to interact with their Xero data on their behalf. Deleting the connections by making a DELETE call to the connections endpoint with a specified connection ID will effectively un-authorize your app to interact with that orgs Xero data until the user reauthorizes your app to do so.
So, the shorter answer is - no, you won't be able to make api calls after disconnecting.
What I think you are after is limiting the XeroAPI access_token to only be able to write to a single org at a time. This can be achieved through your UX by simply deleting all connections if they try to go through your authorize flow a second time.
That way you are limiting their API connection to a single org, and if they want to change the org they are connecting to they can use your UI to disconnect/reconnect to another one.
XeroAPI Documentation
https://developer.xero.com/documentation/oauth2/auth-flow
Removing connections
If you would like to remove an individual tenant connection from your app (e.g. a user wants to disconnect one of their orgs) you can make a DELETE request on the Connections endpoint:
DELETE https://api.xero.com/connections/{connectionId}

How to implement chat on deepstream.io?

I'm trying to implement a real chat using deepstream.io.
Online many tutorials do deal with one single chat room that's shared between users, but the problem with this is, if one user deletes a message then its deleted on all users. In normal chat apps, every user has their own inbox, when a user posts a message its duplicated in the sender and receiver's inbox.
So I came up with this.
Use one global listener that listens to all messages being sent, then write those messages to database. Here it means I'm using event listeners. The problem with this method is scaling, because only one server keeps listening and handling all messages, an even bigger problem is if the server listening is down that means the messages don't get persisted.
Use deepstream list and records.
This one becomes complicated very fast, I have to use two lists? my list and the recipient list, subscribe to mine for any changes, and when I write a message it means I have to write to two lists the same message. This also means, I have to access two inboxes all on the client side, if the last message is changed I have to update two records as well. So I allow only writing on the recipient list but not delete because that list isn't mine. I don't know about this but can it fail?
Maybe there's something I'm missing. Has anyone successfully implemented a complete chat app with inboxes, and private messaging using deepstream.io?
The delete requirement definitely makes this a bit trickier because you're now talking about mirroring different data sets between users, however there are a few solutions.
(Using Lists and Records) If your chats are only ever 1 to 1, when a user deletes a message you set a flag on that record indicating the user has deleted it. Then with your valve permissions you don't allow users to see a message if they have deleted it. This will require a bit of application logic, however it's quite a clean approach. Your Valve permissions may look like something as follows
chat/$userA-$userB:
read: data.deletedBy !== user.id && (user.id === userA || user.id === userB)
You could also delete the record from the list, however you then end up with the situation you described before.

vb.net sending datagridview content to client side

I'm creating a chat system for my company and what i have now is a functional chat with (on the server) a list that contains all logged in users and their nickname.
What i want to do is to send this datagridview to every client when a new employee enters the chat.
How can i do this?
i tried to convert my gridview into a dataset.writexml but that doesn't work.
the only thing i use now are some commands to send the messages:
Send("#MSG#Hello everyone")
Send("#LOGIN# #1#Username#2#Employeename")
Send("#LOGOUT# #1#Username#2#Employeename")
...
I'm using a multi threaded socket server/client system.
Thanks for helping out

Reclaiming a lost Facebook app

I am a new member of a team at my company reviving a legacy product that had Facebook integration, and we wish to continue developing the Facebook side of things, but we can't seem to find the credentials for logging into the app, or even who has access to it.
The app we are trying to recover is "HaloMobile". One thing to note though is the app name on posts is no longer a link. Does this mean the app has been disabled somehow?
I'm obviously not asking for credentials. At this point I'm just trying to "find" the app and possibly determine who is currently assigned as the administrator role, or what my options are. If there is an email address associated with the app, perhaps we can send a transfer request to that email?
If you could get retrieve two piece of information from your code-base, which are App ID and App Secret then you can retrieve the list of roles assigned in app using the following end point,
https://graph.facebook.com/<App_ID>/roles?access_token=<App_ID>|<App_Secret>
And once you know the role, along with the user Ids of the user assigned to it, you can move forward to recover the App by contacting him.
Also, you might want to give this documentation about Application a look, which lists out various fields you can retrieve for getting the required information to get access to your application back, like user_support_email
https://graph.facebook.com/<App_ID>?
fields=name,description,creator_uid,user_support_email
&access_token=<App_ID>|<App_Secret>

AppEngine Channel API - Best way to check if a channel is still open (server side)

I have built a social network/dating type application on the AppEngine and am currently in the process of adding a chat built on top of the Channel API. However, the problem that I have is that users may reload or navigate to new pages while the chat is going on (as they can in Facebook). This means that the server doesn't easily know if it should generate a new channel ID token for a given client, or if a given client has already been assigned a channel token.
It would be extremely useful if there were a way to check (server side) if a particular client already has a channel open. For example, if I assign a client "Jack" a channel ID of "Jack-Jan-21-2010", then I would like to be able to check on the server side if there is already a channel open associated with the ID "Jack-Jan-21-2010". This can be (sort of) tracked on the client side by watching for an onerror() and onclose() callback, but I can't see anything server-side that allows me to just check if a channel associated with a given ID is already open.
Does anyone know an intelligent way to check (server side) if a channel has already been opened, while using the AppEngine Channel API?
Part 1: Solving your problem
See Part 2 below if you really need to track client connections, but I'm not sure from your question if what you're asking for will solve your problem.
Let me see if I can echo your problem back: you're writing a chat app, but it's for a site which isn't fully AJAX (in the way that, say, gmail is); the site contains page navigation where you may need to re-set up your channel after the user clicks on a link to another page. When the user navigates, the new page is rendered, and you want to avoid getting a new token at that point; you want to reuse the existing token and channel with the same client-id.
If that's correct, I have two alternate solutions, one easy but with not-great user experience, one trickier but with a much smoother end result.
Preserve the token in a cookie. When you re-render your page, just use the token from the cookie instead of calling channel.create_channel again. When the token expires you'll get an onerror callback just like if the user had stayed on the original page; at this point, call channel.create_channel again. The problem with this is that re-connection can be slow (up to 10 seconds or more in bad cases) because of the nature of Comet connections.
Wrap your entire site that's not chat-related in an iframe. Put your channel creation code and UI in the outer iframe. This way you don't have to re-connect every time the user navigates. This avoids the downtime on navigation. Note that orkut uses this technique, with floating divs, as a small amount of Firebug investigation will reveal.
Part 2: Your feature request
If it turns out I'm misunderstanding and you really do need to track client connections:
There's not a built-in way to check if a client is connected to a channel identified by a client-id now.
However, I am working right now on adding "presence" (in the chat sense) so that your app can register to get a post when a client connects to or disconnects from a channel created with a given client id. You also might be able to "probe" presence, to query whether a given client id is connected or not (still working on the details of this part).
Note that this won't be token-based, but rather client-id based.
I don't have a definite release date for this yet but as I said I'm actively working on it right now.
In the meantime, you could use a heartbeat HTTP request from your client back to your app that says, "hey, I'm still here" every minute or so. You'll need to have some sort of task that runs every, say, 2 minutes and marks any clients that haven't checked in as inactive, and you'll need to store this data someplace.