示例#1
0
    void LoadOpenChannels()
    {
        mChannelListQuery.Next((list, e) => {
            if (e != null)
            {
                Debug.Log(e.Code + ": " + e.Message);
                return;
            }

            foreach (OpenChannel channel in list)
            {
                GameObject btnChannel = Instantiate(channelListItemPrefab) as GameObject;
                btnChannel.GetComponent <Image>().sprite = uiTheme.channelButtonOff;

                if (channel.Url == selectedChannelUrl)
                {
                    btnChannel.GetComponent <Image>().overrideSprite = uiTheme.channelButtonOn;
                    btnChannel.GetComponentInChildren <Text>().color = uiTheme.channelButtonOnColor;
                }
                else
                {
                    btnChannel.GetComponent <Image>().overrideSprite = null;
                    btnChannel.GetComponentInChildren <Text>().color = uiTheme.channelButtonOffColor;
                }
                Text text = btnChannel.GetComponentInChildren <Text>();
                text.text = "#" + channel.Name;
                btnChannel.transform.SetParent(channelGridPannel.transform);
                btnChannel.transform.localScale = Vector3.one;
                btnChannels.Add(btnChannel);

                OpenChannel final = channel;
                btnChannel.GetComponent <Button>().onClick.AddListener(() => {
                    foreach (KeyValuePair <string, OpenChannel> entry in enteredChannels)
                    {
                        entry.Value.Exit(null);
                    }

                    final.Enter((e1) => {
                        if (e1 != null)
                        {
                            Debug.Log(e1.Code + ": " + e1.Message);
                            return;
                        }

                        currentChannel = final;
                        LoadOpenChannelChatHistory();
                        txtOpenChannelTitle.text = "#" + final.Name;

                        enteredChannels[final.Url] = final;

                        openChannelListPanel.SetActive(false);
                        openChannelPanel.SetActive(true);
                    });
                });
            }
        });
    }
        private async Task EnterChannel(OpenChannel channel)
        {
            var tcs = new TaskCompletionSource <SendBirdException>();

            await LeaveChannel();

            channel.Enter(ex => {
                Console.WriteLine($"SendBird: Entered channel \"{channel.Name}\"");
                tcs.SetResult(ex);
            });

            HandleException(await tcs.Task);

            _channel = channel;
        }
示例#3
0
        public void joinChannelHandler(object sender, EventArgs e)
        {
            OpenChannel.GetChannel("testing", (channel, sendExcep) =>
            {
                if (sendExcep != null)
                {
                    // An error has occurred while connecting.
                    System.Diagnostics.Debug.WriteLine("An error has occurred " +
                                                       "in joinChannelHandler while joining");
                    System.Diagnostics.Debug.WriteLine("error: " + sendExcep.Code);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Success in joining a channel in SendBird!");
                }

                channel.Enter((SendBirdException enterExcep) =>
                {
                    if (enterExcep != null)
                    {
                        System.Diagnostics.Debug.WriteLine("An error has occurred " +
                                                           "in joinChannelHandler while entering");
                        System.Diagnostics.Debug.WriteLine("error: " + sendExcep.Code);
                    }
                });

                channel.SendUserMessage("Test", (message, sendUserTestE) =>
                {
                    if (sendUserTestE != null)
                    {
                        System.Diagnostics.Debug.WriteLine("Error occurred when sending user message" +
                                                           " from inside joinChannelHandler");
                        System.Diagnostics.Debug.WriteLine("error: " + sendUserTestE.Code);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Successfully sent message");
                    }
                });
            });
        }
示例#4
0
 public void EnterChannel(string name, Action <OpenChannel, Exception> onChannelEntered)
 {
     GetChannelFromList(name, (channel, e) =>
     {
         if (e != null)
         {
             Debug.LogError(e);
             onChannelEntered?.Invoke(null, e);
             return;
         }
         channel.Enter(e2 =>
         {
             if (e2 != null)
             {
                 Debug.LogError(e2);
             }
             this.channel = channel;
             RoomCode     = channel.Data;
             onChannelEntered?.Invoke(channel, e2);
         });
     });
 }
示例#5
0
    public void EnterChannel(string CHANNEL_URL)
    {
        OpenChannel.GetChannel(CHANNEL_URL, (OpenChannel openChannel, SendBirdException e) =>
        {
            if (e != null)
            {
                // Error.
                return;
            }
            _openChannel = openChannel;
            _openChannel.Enter((SendBirdException e3) =>
            {
                if (e3 != null)
                {
                    // Error.
                    return;
                }

                GetPreviousOpenChannelData();
            });
        });
    }