xamarin - How to get list of login users-pubnub -
i trying chat application through pubnub in xamarin.forms,i can able login channel understood keeping break points.now trying list of people had logged in channel.
<contentpage.content> <stacklayout horizontaloptions="fillandexpand" verticaloptions="fillandexpand"> <label text="welcome" textcolor="blue" horizontaloptions="center" verticaloptions="center"> <label.fontsize> <onidiom x:typearguments="x:double"> <onidiom.phone> <onplatform x:typearguments="x:double" ios="20" android="20" winphone="20" /> </onidiom.phone> <onidiom.tablet> <onplatform x:typearguments="x:double" ios="30" android="30" winphone="30" /> </onidiom.tablet> </onidiom> </label.fontsize> </label> <listview x:name="loginuserlist" itemssource="{binding loginuserlist}"itemselected="loginuserlist_onitemselected"> <listview.itemtemplate> <datatemplate> <viewcell> <stacklayout orientation="horizontal"> <label text="{binding username}" textcolor="skyblue" fontsize="20" horizontaloptions="center" verticaloptions="center"></label> </stacklayout> </viewcell> </datatemplate> </listview.itemtemplate> </listview> </stacklayout> </contentpage.content>
here how can display list of logged in users.
public class chatlistviewmodel : inotifypropertychanged { private list<userdto> _loginuserlist; private string _offlineimagesource; private bool _offlinevisibility; private string _username; public chatlistviewmodel() { initializedata(); getallusersfromserver(); } public event propertychangedeventhandler propertychanged; public list<userdto> loginuserlist { { return _loginuserlist; } set { _loginuserlist = value; onpropertychanged(); } } public string offlineimagesource { { return _offlineimagesource; } set { _offlineimagesource = value; onpropertychanged(); } } public string username { { return _username; } set { _username = value; onpropertychanged(); } } public bool offlinevisibility { { return _offlinevisibility; } set { _offlinevisibility = value; onpropertychanged(); } } private async void getallusersfromserver() { loginuserlist = await userservice.instance.getallusers(); } protected virtual void onpropertychanged([callermembername] string propertyname = null) { propertychanged?.invoke(this, new propertychangedeventargs(propertyname)); } private void initializedata() { offlineimagesource = "blackcircle.png"; } }
here viewmodel list displaying purpose.
you can list of active subscribers/users on pubnub channel using on "connect" callback. supply on "connect" function called when new or existing user connects. when occurs, relay information needed on end.
i show example code:
pubnub.subscribe({ channel : "hello_world", // connect channel. callback : function(message){} // received message. connect : function() { // connection established. // new user or existing user has // connected. send details server. // --------------------------------------- // psudo-code example function: // --------------------------------------- psudo_post_url( "http://www.mywebsite.com/pubnub-user-connected", { "user_id" : 123456789, "channel" : "hello_word" } ); } })
wiki
Comments
Post a Comment