// Use this for initialization void Start() { var sc = GameObject.FindObjectOfType <MyWebSocketClient>(); var config = new AVRealtime.Configuration() { ApplicationId = "uay57kigwe0b6f5n0e1d4z4xhydsml3dor24bzwvzr57wdap", ApplicationKey = "kfgz7jjfsk55r5a8a3y4ttd3je1ko11bkibcikonk32oozww", WebSocketClient = sc // 使用已经初始化的 WebSocketClient 实例作为 AVRealtime 初始化的配置参数 }; AVRealtime.WebSocketLog(UnityEngine.Debug.Log); RealtimeInstance = new AVRealtime(config); RealtimeInstance.RegisterMessageType <Emoji>(); RealtimeInstance.RegisterMessageType <NikkiMessage>(); }
private async void Window_Loaded(object sender, RoutedEventArgs e) { //初始化登录用户信息 usernameheader.Text = AVUser.CurrentUser.Username[0].ToString(); username.Text = AVUser.CurrentUser.Username; useremail.Text = AVUser.CurrentUser.Email; //初始化即时通讯服务 try { Websockets.Net.WebsocketConnection.Link(); Realtime = new AVRealtime(new AVRealtime.Configuration { ApplicationId = "EthsHELtLfXL9XBqcFfzMrPO-gzGzoHsz", ApplicationKey = "xODJ808fAD8hpLHlblQhk0t1", //可以有 RTMRouter = new Uri("https://ethshelt.lc-cn-n1-shared.com"), OfflineMessageStrategy = AVRealtime.OfflineMessageStrategy.Default }); //注册自定义消息 Realtime.RegisterMessageType <NoticeMessage>(); //注册离线消息监听 Realtime.OnOfflineMessageReceived += OnOfflineMessageReceived; //登录Client User = await Realtime.CreateClientAsync(AVUser.CurrentUser); if (AVUser.CurrentUser.Get <string>("Friends") == "null") { //如果是第一次登录给用户添加Friends的ConversationId AVIMConversation Myfriends = await User.CreateConversationAsync(member : null, name : AVUser.CurrentUser.Username + "的小伙伴们", isUnique : false); AVUser.CurrentUser["Friends"] = Myfriends.ConversationId; await AVUser.CurrentUser.SaveAsync(); } //获取FriendsConversation FriendsConversation = await User.GetConversationAsync(AVUser.CurrentUser.Get <string>("Friends")); //上线后给所有的好友发送“我上线了”的notice NoticeMessage notice = new NoticeMessage { Notice = "我上线啦" }; await FriendsConversation.SendMessageAsync(notice); //绑定listbox数据 BindingFriendListSrouce(); //添加好友事件监听(好友邀请事件:同意,拒绝,好友邀请反馈事件:同意) User.OnInvited += OnInvited; //被删除事件监听 User.OnKicked += OnKicked; //好友操作事件监听(删除好友,好友邀请反馈事件:拒绝)==》TODO:未完成 //User.OnMembersLeft += OnMembersLeft; //User.OnMembersJoined += OnMembersJoined; User.OnMessageReceived += OnMessageReceived; } catch (Exception err) { MessageBox.Show(err.ToString()); } }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel() { Websockets.Net.WebsocketConnection.Link(); //var config = new AVRealtime.Configuration() //{ // ApplicationId = "021h1hbtd5shlz38pegnpkmq9d3qf8os1vt0nef4f2lxjru8", // ApplicationKey = "3suek8gdtfk3j3dgb42p9o8jhfjkbnmtefk3z9500balmf2e", // SignatureFactory = new LeanEngineSignatureFactory() //}; string appId = "021h1hbtd5shlz38pegnpkmq9d3qf8os1vt0nef4f2lxjru8"; string appKey = "3suek8gdtfk3j3dgb42p9o8jhfjkbnmtefk3z9500balmf2e"; var config = new AVRealtime.Configuration() { ApplicationId = appId, ApplicationKey = appKey, //SignatureFactory = new LeanEngineSignatureFactory() }; realtime = new AVRealtime(config); realtime.RegisterMessageType <Emoji>(); realtime.RegisterMessageType <EmojiV2>(); realtime.RegisterMessageType <BinaryMessage>(); this.CenterContent = new LogIn(); var logInVM = ServiceLocator.Current.GetInstance <LogInViewModel>(); logInVM.realtime = realtime; logInVM.client = CurrentClient; logInVM.PropertyChanged += LogInVM_PropertyChanged; this.LogContent = new WebSocketLog(); var logVM = ServiceLocator.Current.GetInstance <WebSocketLogViewModel>(); var teamVM = ServiceLocator.Current.GetInstance <TeamViewModel>(); teamVM.PropertyChanged += TeamVM_PropertyChanged; }