Exemple #1
0
        private void MessageListener(object sender, EventArgs e)
        {
            SubscribeEventEventArgs mea = e as SubscribeEventEventArgs;

            if (mea.Status != null)
            {
                if (debug)
                {
                    PubnubStatusCategoryLogger(mea.Status.Category);
                }

                if (mea.Status.Error)
                {
                    log(mea.Status.ErrorData.Info, true);
                    RaiseHandleMessage(true, null, handleMessageCallback, mea.Status.ErrorData.Ex);
                }
            }
            if (mea.MessageResult != null)
            {
                Dictionary <string, object> msg = mea.MessageResult.Payload as Dictionary <string, object>;

                log("New message!");

                lastMessageTimestamp = mea.MessageResult.Timetoken + 1;
                RaiseHandleMessage(false, msg, handleMessageCallback);
            }
        }
    void Start()
    {
        PNConfiguration pnConfiguration = new PNConfiguration();

        pnConfiguration.SubscribeKey = subKey;
        pnConfiguration.PublishKey   = pubKey;
        pnConfiguration.UUID         = myID;

        dataServer = new PubNub(pnConfiguration);


        dataServer.Subscribe()
        .Channels(new List <string> ()
        {
            subscribeChannel
        })
        .Execute();

        dataServer.SubscribeCallback += (sender, e) =>

        {
            SubscribeEventEventArgs inMessage = e as SubscribeEventEventArgs;

            if (inMessage.MessageResult != null) //error check to insure the message has contents
            {
                //save the UUID of the last sender
                lastSender = inMessage.MessageResult.IssuingClientId;

                Debug.Log(lastSender);

                //save the message into a Dictionary
                Dictionary <string, object> msg = inMessage.MessageResult.Payload as Dictionary <string, object>;

                //retrieve and convert the value you need using the key name

                /*
                 * convert to integer -  (int)msg["keyName"]
                 * convert to float -  (float)msg["keyName"]
                 * convert to string -  (float)msg["keyName"]
                 *
                 */

                /*list all keys
                 * foreach (string key in msg.Keys)
                 * {
                 * Debug.Log(key);
                 * }
                 */
                xVal = (int)msg["x"];
                yVal = (int)msg["y"];

                transform.position = new Vector3(xVal * 2, 0, yVal * -2);
            }
        };
    }
Exemple #3
0
        void SubscribeCallbackHandler(object sender, EventArgs e)
        {
            Debug.Log("SubscribeCallbackHandler Event handler");
            SubscribeEventEventArgs mea = e as SubscribeEventEventArgs;

            if (mea.Status != null)
            {
                switch (mea.Status.Category)
                {
                case PNStatusCategory.PNConnectedCategory:
                    PrintStatus(mea.Status);
                    pubnub.Publish().Channel("my_channel").Message("Hello from the PubNub Unity SDK").Ttl(10).UsePost(true).Async((result, status) => {
                        if (!status.Error)
                        {
                            Debug.Log(string.Format("DateTime {0}, In Publish Example, Timetoken: {1}", DateTime.UtcNow, result.Timetoken));
                        }
                        else
                        {
                            Debug.Log(status.Error);
                            Debug.Log(status.ErrorData.Info);
                        }
                    });

                    break;

                case PNStatusCategory.PNUnexpectedDisconnectCategory:
                case PNStatusCategory.PNTimeoutCategory:
                    pubnub.Reconnect();
                    pubnub.CleanUp();
                    break;
                }
            }
            else
            {
                Debug.Log("mea.Status null" + e.GetType().ToString() + mea.GetType().ToString());
            }
            if (mea.MessageResult != null)
            {
                Debug.Log("In Example, SubscribeCallback in message" + mea.MessageResult.Channel + mea.MessageResult.Payload);
                //var a = mea.MessageResult.Payload as Dictionary<string, string>;
                //var b = a["a"];
                Display(string.Format("SubscribeCallback Result: {0}", pubnub.JsonLibrary.SerializeToJsonString(mea.MessageResult.Payload)));
            }
            if (mea.PresenceEventResult != null)
            {
                Debug.Log("In Example, SubscribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event + mea.PresenceEventResult.State);
            }
            if (mea.SignalEventResult != null)
            {
                Debug.Log("In Example, SubscribeCallback in SignalEventResult" + mea.SignalEventResult.Channel + mea.SignalEventResult.Payload);
                Display(string.Format("SubscribeCallback SignalEventResult: {0}", pubnub.JsonLibrary.SerializeToJsonString(mea.SignalEventResult.Payload)));
            }
        }
Exemple #4
0
    void Start()
    {
        PNConfiguration pnConfiguration = new PNConfiguration();

        pnConfiguration.SubscribeKey = subKey;
        pnConfiguration.PublishKey   = pubKey;
        pnConfiguration.UUID         = myID;

        dataServer = new PubNub(pnConfiguration);


        dataServer.Subscribe()
        .Channels(new List <string> ()
        {
            channelName
        })
        .Execute();

        dataServer.SubscribeCallback += (sender, e) =>

        {
            SubscribeEventEventArgs inMessage = e as SubscribeEventEventArgs;

            if (inMessage.MessageResult != null) //error check to insure the message has contents
            {
                //save the UUID of the last sender
                lastSender = inMessage.MessageResult.IssuingClientId;

                //save the message into a Dictionary
                Dictionary <string, object> msg = inMessage.MessageResult.Payload as Dictionary <string, object>;

                //retrieve and convert the value you need using the key name

                /*
                 * convert to integer -  (int)msg["keyName"]
                 * convert to float -  (float)msg["keyName"]
                 * convert to string -  (float)msg["keyName"]
                 *
                 */
                xVal = (int)msg["x"];
                yVal = (int)msg["y"];

                Instantiate(clickDrop, new Vector3(xVal * 2, 800, yVal * -2), Quaternion.identity);
            }
        };
    }
Exemple #5
0
        void SubscribeCallbackHandler2(object sender, EventArgs e)
        {
            SubscribeEventEventArgs mea = e as SubscribeEventEventArgs;

            if (mea.Status != null)
            {
                Debug.Log("mea.Status: " + mea.Status);
                switch (mea.Status.Category)
                {
                case PNStatusCategory.PNUnexpectedDisconnectCategory:
                case PNStatusCategory.PNTimeoutCategory:

                    break;
                }
            }
            if (mea.MessageResult != null)
            {
                Debug.Log("SubscribeCallback in message" + mea.MessageResult.Channel + mea.MessageResult.Payload);
            }
            if (mea.PresenceEventResult != null)
            {
                Debug.Log("SubscribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event);
            }
        }
Exemple #6
0
    void Start()
    {
        //Brings up Team Selectoin Menue
        Team_Selector.SetActive(true);
        Blue_HUD.SetActive(false);
        Red_HUD.SetActive(false);

        while (TeamSelectStatus == true)
        {
        }

        //Brings up HUD for coresponding team
        if (BlueTeamSelect == false)
        {
            Blue_HUD.SetActive(false);
            Red_HUD.SetActive(true);
        }
        else
        {
            Blue_HUD.SetActive(true);
            Red_HUD.SetActive(false);
        }

        //Changes Controller Material to match team
        if (BlueTeamSelect == false)
        {
            controllerRend.material = controllerRed;
        }
        else
        {
            controllerRend.material = controllerBlue;
        }

        _mlSpatialMapper.gameObject.transform.position   = _camera.gameObject.transform.position;
        _mlSpatialMapper.gameObject.transform.localScale = _bounded ? _boundedExtentsSize : _boundlessExtentsSize;

        // Initializing a new pubnub Connection
        PNConfiguration pnConfiguration = new PNConfiguration();

        pnConfiguration.PublishKey         = "pub-c-86694f64-f8a5-4dea-a382-d99cef5f71e9";
        pnConfiguration.SubscribeKey       = "sub-c-ef60f02c-80b8-11e9-bc4f-82f4a771f4c5";
        pnConfiguration.LogVerbosity       = PNLogVerbosity.BODY;
        pnConfiguration.UUID               = "GameMNGR";
        pnConfiguration.ReconnectionPolicy = PNReconnectionPolicy.LINEAR;

        PubNub pubnub = new PubNub(pnConfiguration);

        //Sets up Subscriber Callback which handles received messages
        pubnub.SubscribeCallback += (sender, e) => {
            SubscribeEventEventArgs mea = e as SubscribeEventEventArgs;

            if (mea.MessageResult != null)
            {
                if (mea.MessageResult.Payload == "BumperPress")
                {
                    CubeRenderer.enabled = false;
                }
                else
                {
                    CubeRenderer.enabled = true;
                }
            }
        };

        //Subscribes to channels in list
        pubnub.Subscribe()
        .Channels(new List <string>()
        {
            "cube"
        })
        .Execute();
    }
    void Start()
    {
        // Use this for initialization
        PNConfiguration pnConfiguration = new PNConfiguration();

        pnConfiguration.PublishKey   = "demo";
        pnConfiguration.SubscribeKey = "demo";
        pnConfiguration.LogVerbosity = PNLogVerbosity.BODY;
        pnConfiguration.UUID         = "user-1";
        pubnub = new PubNub(pnConfiguration);

        // Add Listener to Submit button to send messages
        Button btn = SubmitButton.GetComponent <Button>();

        btn.onClick.AddListener(TaskOnClick);

        // Fetch the maxMessagesToDisplay messages sent on the given PubNub channel
        pubnub.FetchMessages()
        .Channels(new List <string> {
            channel
        })
        .Count(maxMessagesToDisplay)
        .Async((result, status) =>
        {
            if (status.Error)
            {
                Debug.Log(string.Format(
                              " FetchMessages Error: {0} {1} {2}",
                              status.StatusCode, status.ErrorData, status.Category
                              ));
            }
            else
            {
                foreach (KeyValuePair <string, List <PNMessageResult> > kvp in result.Channels)
                {
                    foreach (PNMessageResult pnMessageResult in kvp.Value)
                    {
                        // Format data into readable format
                        JSONInformation chatmessage = JsonUtility.FromJson <JSONInformation>(pnMessageResult.Payload.ToString());

                        // Call the function to display the message in plain text
                        CreateChat(chatmessage);
                    }
                }
            }
        });

        // This is the subscribe callback function where data is recieved that is sent on the channel
        pubnub.SubscribeCallback += (sender, e) =>
        {
            SubscribeEventEventArgs message = e as SubscribeEventEventArgs;
            if (message.MessageResult != null)
            {
                // Format data into a readable format
                JSONInformation chatmessage = JsonUtility.FromJson <JSONInformation>(message.MessageResult.Payload.ToString());

                // Call the function to display the message in plain text
                CreateChat(chatmessage);

                // When a new chat is created, remove the first chat and transform all the messages on the page up
                SyncChat();
            }
        };

        // Subscribe to a PubNub channel to receive messages when they are sent on that channel
        pubnub.Subscribe()
        .Channels(new List <string>()
        {
            channel
        })
        .WithPresence()
        .Execute();
    }
    void Start()
    {
        PNConfiguration pnConfiguration = new PNConfiguration();

        pnConfiguration.SubscribeKey = subKey;
        pnConfiguration.PublishKey   = pubKey;
        pnConfiguration.UUID         = myID;
        pnConfiguration.Secure       = true;

        dataServer = new PubNub(pnConfiguration);

        if (myID == "player1")
        {
            ListenForPlayers2 script1 = Player1.GetComponent <ListenForPlayers2>();
            script1.enabled = true;

            ListenForPlayers script2 = this.GetComponent <ListenForPlayers>();
            script2.enabled = false;
        }
        else if (myID == "player2")
        {
            ListenForPlayers2 script1 = Player1.GetComponent <ListenForPlayers2>();
            script1.enabled = true;

            ListenForPlayers script2 = this.GetComponent <ListenForPlayers>();
            script2.enabled = false;
        }
        else
        {
            ListenForPlayers script2 = this.GetComponent <ListenForPlayers>();
            script2.enabled = true;

            ListenForPlayers2 script1 = Player1.GetComponent <ListenForPlayers2>();
            script1.enabled = false;
        }
        rb2.MovePosition(startpos);

        dataServer.Subscribe()
        .Channels(new List <string>()
        {
            subscribeChannel
        })
        .Execute();

        dataServer.SubscribeCallback += (sender, e) =>

        {
            SubscribeEventEventArgs inMessage = e as SubscribeEventEventArgs;
            if (inMessage.MessageResult != null)    //error check to insure the message has contents
            {
                //save the UUID of the last sender
                lastSender = inMessage.MessageResult.IssuingClientId;
                //save the message into a Dictionary
                Dictionary <string, object> msg = inMessage.MessageResult.Payload as Dictionary <string, object>;
                //retrieve and convert the value you need using the key name

                /*
                 * convert to integer -  (int)msg["keyName"]
                 * convert to float -  (float)msg["keyName"]
                 * convert to string -  (string)msg["keyName"]
                 *
                 */
                xVal = (float)(double)msg["x"];
                yVal = (float)(double)msg["y"];

                Debug.Log($"x:{msg["x"]} y:{msg["y"]}");
            }
        };
    }
    void Start()
    {
        // Use this for initialization
        PNConfiguration pn_configuration = new PNConfiguration();

        pn_configuration.PublishKey   = "pub-c-c9fedf8b-6c91-46cf-b6d9-14b5ec353a21";
        pn_configuration.SubscribeKey = "sub-c-5b8e3a72-8796-11ea-b883-d2d532c9a1bf";
        pn_configuration.LogVerbosity = PNLogVerbosity.BODY;
        pn_configuration.UUID         = System.Guid.NewGuid().ToString();
        pubnub = new PubNub(pn_configuration);

        // Add listener to submit button to send messages
        Button btn = submit_button.GetComponent <Button>();

        btn.onClick.AddListener(task_on_click);

        // Fetch the last 13 messages sent on the given PubNub channel
        pubnub.FetchMessages().Channels(new List <string> {
            "chatchannel13"
        }).Count(10).Async((result, status) =>
        {
            if (status.Error)
            {
                Debug.Log(string.Format("Fetch Messages Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
            }
            else
            {
                foreach (KeyValuePair <string, List <PNMessageResult> > kvp in result.Channels)
                {
                    foreach (PNMessageResult pn_message_result in kvp.Value)
                    {
                        // Format Data into readable format
                        JSONInformation chatmessage = JsonUtility.FromJson <JSONInformation>(pn_message_result.Payload.ToString());
                        // Call the function to display the message in plaintext
                        create_chat(chatmessage);
                        // Counter used for positioning the text UI
                        if (counter != 200)
                        {
                            counter += 20;
                        }
                    }
                }
            }
        });

        // Subscribe to a PubNub Channel to receive messages when they are sent on that channel
        pubnub.Subscribe().Channels(new List <string>()
        {
            "chatchannel13"
        }).WithPresence().Execute();

        // This is the subscribe callback function where data is received that is received on the channel
        pubnub.SubscribeCallback += (sender, e) =>
        {
            SubscribeEventEventArgs message = e as SubscribeEventEventArgs;
            if (message.MessageResult != null)
            {
                // Format data into readable format
                JSONInformation chatmessage = JsonUtility.FromJson <JSONInformation>(message.MessageResult.Payload.ToString());
                // Call the function to display the message in plaintext
                create_chat(chatmessage);
                // When a new Chat is created, remove the first chat and transform all the messages on the page up
                sync_chat();
                // Counter used for positioning the text UI
                if (counter != 200)
                {
                    counter += 20;
                }
            }
        };
    }