CanChat









How do I use Can Chat
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: ChatClient.cs Copy
53         public bool CanChat { get { return this.State == ChatState.ConnectedToFrontEnd && this.HasPeer; } }
File name: ChatClient.cs Copy
217         public bool Subscribe(string[] channels, int messagesFromHistory)
218         {
219             if (!this.CanChat)
220             {
221                 // TODO: log error
222                 return false;
223             }
224
225             if (channels == null || channels.Length == 0)
226             {
227                 this.LogWarning("Subscribe can't be called for empty or null cannels-list.");
228                 return false;
229             }
230
231             return this.SendChannelOperation(channels, (byte)ChatOperationCode.Subscribe, messagesFromHistory);
232         }
File name: ChatClient.cs Copy
245         public bool Unsubscribe(string[] channels)
246         {
247             if (!this.CanChat)
248             {
249                 // TODO: log error
250                 return false;
251             }
252
253             if (channels == null || channels.Length == 0)
254             {
255                 this.LogWarning("Unsubscribe can't be called for empty or null cannels-list.");
256                 return false;
257             }
258
259             return SendChannelOperation(channels, ChatOperationCode.Unsubscribe, 0);
260         }
File name: ChatClient.cs Copy
270         public bool PublishMessage(string channelName, object message)
271         {
272             if (!this.CanChat)
273             {
274                 // TODO: log error
275                 return false;
276             }
277
278             if (string.IsNullOrEmpty(channelName) || message == null)
279             {
280                 this.LogWarning("PublishMessage parameters must be non-null and not empty.");
281                 return false;
282             }
283
284             Dictionary parameters = new Dictionary
285                 {
286                     { (byte)ChatParameterCode.Channel, channelName },
287                     { (byte)ChatParameterCode.Message, message }
288                 };
289
290             return this.chatPeer.OpCustom((byte)ChatOperationCode.Publish, parameters, true);
291         }
File name: ChatClient.cs Copy
311         public bool SendPrivateMessage(string target, object message, bool encrypt)
312         {
313             if (!this.CanChat)
314             {
315                 // TODO: log error
316                 return false;
317             }
318
319             if (string.IsNullOrEmpty(target) || message == null)
320             {
321                 this.LogWarning("SendPrivateMessage parameters must be non-null and not empty.");
322                 return false;
323             }
324
325             Dictionary parameters = new Dictionary
326                 {
327                     { ChatParameterCode.UserId, target },
328                     { ChatParameterCode.Message, message }
329                 };
330
331             bool sent = this.chatPeer.OpCustom((byte)ChatOperationCode.SendPrivate, parameters, true, 0, encrypt);
332             return sent;
333         }
File name: ChatClient.cs Copy
343         /// The message object can be anything that Photon can serialize, including (but not limited to)
350         private bool SetOnlineStatus(int status, object message, bool skipMessage)
351         {
352             if (!this.CanChat)
353             {
354                 // TODO: log error
355                 return false;
356             }
357
358             Dictionary parameters = new Dictionary
359                 {
360                     { ChatParameterCode.Status, status },
361                 };
362
363             if (skipMessage)
364             {
365                 parameters[ChatParameterCode.SkipMessage] = true;
366             }
367             else
368             {
369                 parameters[ChatParameterCode.Message] = message;
370             }
371             return this.chatPeer.OpCustom(ChatOperationCode.UpdateStatus, parameters, true);
372         }
File name: ChatClient.cs Copy
433         public bool AddFriends(string[] friends)
434         {
435             if (!this.CanChat)
436             {
437                 // TODO: log error
438                 return false;
439             }
440
441             if (friends == null || friends.Length == 0)
442             {
443                 this.LogWarning("AddFriends can't be called for empty or null list.");
444                 return false;
445             }
446
447             Dictionary parameters = new Dictionary
448                 {
449                     { ChatParameterCode.Friends, friends },
450                 };
451             return this.chatPeer.OpCustom(ChatOperationCode.AddFriends, parameters, true);
452         }
File name: ChatClient.cs Copy
496         public bool RemoveFriends(string[] friends)
497         {
498             if (!this.CanChat)
499             {
500                 // TODO: log error
501                 return false;
502             }
503
504             if (friends == null || friends.Length == 0)
505             {
506                 this.LogWarning("RemoveFriends can't be called for empty or null list.");
507                 return false;
508             }
509
510             Dictionary parameters = new Dictionary
511                 {
512                     { ChatParameterCode.Friends, friends },
513                 };
514             return this.chatPeer.OpCustom(ChatOperationCode.RemoveFriends, parameters, true);
515         }

CanChat 137 lượt xem

Gõ tìm kiếm nhanh...