StringObject() 공개 정적인 메소드

public static StringObject ( string val ) : JSONObject,
val string
리턴 JSONObject,
예제 #1
0
    public void OnOpen(SocketIOEvent e)
    {
        Debug.Log("[SocketIO] Open(): " + e.data);

        socket.Emit("joinRoom", JSONObject.StringObject(roomNumber));         //방번호
        // sendConnect();
    }
예제 #2
0
    IEnumerator UploadPNG()
    {
        // We should only read the screen after all rendering is complete
        yield return(new WaitForEndOfFrame());

        // Create a texture the size of the screen, RGB24 format
        int width  = Screen.width;
        int height = Screen.height;
        var tex    = new Texture2D(width, height, TextureFormat.RGB24, false);

        // Read screen contents into the texture
        tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        tex.Apply();

        // Encode texture into PNG & apply it to cube
        byte[] bytes      = tex.EncodeToPNG();
        var    cubeRender = GameObject.Find("Cube").GetComponent <Renderer>();

        cubeRender.material.mainTexture = tex;

        // Prefefix is necessary to draw image on canvas.
        // Convert || img -> Byte Array -> String -> JSON obj
        string prefix       = "data:image/png;base64,";
        string tempInBase64 = Convert.ToBase64String(bytes);
        string payload      = prefix + tempInBase64;
        var    jsonPayload  = JSONObject.StringObject(payload);

        Debug.Log("jsonPayload:" + jsonPayload);
        _socket.Emit("msgFromUnity", jsonPayload);

        //TODO: May not need to destroy this....
        // Destroy(tex);
    }
예제 #3
0
        private static UserProfile UserProfileFromFBJson(JSONObject fbJsonObject, FacebookProvider provider)
        {
            JSONObject soomlaJsonObject = new JSONObject();

            soomlaJsonObject.AddField(PJSONConsts.UP_PROVIDER, Provider.FACEBOOK.ToString());
            soomlaJsonObject.AddField(PJSONConsts.UP_PROFILEID, fbJsonObject["id"].str);
            string name = fbJsonObject ["name"].str;

            soomlaJsonObject.AddField(PJSONConsts.UP_USERNAME, name);
            string email = fbJsonObject ["email"] != null ? fbJsonObject ["email"].str : null;

            if (email == null)
            {
                email = Regex.Replace(name, @"\s+", ".") + "@facebook.com";
            }
            soomlaJsonObject.AddField(PJSONConsts.UP_EMAIL, email);
            soomlaJsonObject.AddField(PJSONConsts.UP_FIRSTNAME, fbJsonObject["first_name"].str);
            soomlaJsonObject.AddField(PJSONConsts.UP_LASTNAME, fbJsonObject["last_name"].str);
            soomlaJsonObject.AddField(PJSONConsts.UP_AVATAR, fbJsonObject["picture"]["data"]["url"].str);
            if (fbJsonObject["gender"] != null)
            {
                soomlaJsonObject.AddField(PJSONConsts.UP_GENDER, fbJsonObject["gender"].str);
            }
            if (fbJsonObject["languages"] != null && fbJsonObject["languages"].Count > 0 &&
                fbJsonObject["languages"][0] != null && fbJsonObject["languages"][0]["name"] != null)
            {
                soomlaJsonObject.AddField(PJSONConsts.UP_LANGUAGE, fbJsonObject["languages"][0]["name"].str);
            }
            if (fbJsonObject["location"] != null && fbJsonObject["location"]["name"] != null)
            {
                soomlaJsonObject.AddField(PJSONConsts.UP_LOCATION, fbJsonObject["location"]["name"].str);
            }
            if (fbJsonObject["birthday"] != null)
            {
                soomlaJsonObject.AddField(PJSONConsts.UP_BIRTHDAY, fbJsonObject["birthday"].str);
            }

            if (provider != null)               //let us to know if method called during own profile receiving
            {
                Dictionary <String, JSONObject> extraDict = new Dictionary <String, JSONObject>();
                extraDict.Add("access_token", JSONObject.StringObject(AccessToken.CurrentAccessToken.TokenString));
                JSONObject permissionsObject = JSONObject.Create(JSONObject.Type.ARRAY);
                foreach (String permission in provider.permissions)
                {
                    permissionsObject.Add(permission);
                }
                extraDict.Add("permissions", permissionsObject);
                extraDict.Add("expiration_date", new JSONObject((AccessToken.CurrentAccessToken.ExpirationTime - new DateTime(1970, 1, 1)).TotalSeconds));
                soomlaJsonObject.AddField(PJSONConsts.UP_EXTRA, new JSONObject(extraDict));
            }

            UserProfile userProfile = new UserProfile(soomlaJsonObject);

            return(userProfile);
        }
        protected override void _pushEventInviteFinished(Provider provider, string requestId, List <string> invitedIds, string payload)
        {
            if (SoomlaProfile.IsProviderNativelyImplemented(provider))
            {
                return;
            }
            List <JSONObject> invited = new List <JSONObject>();

            foreach (var id in invitedIds)
            {
                invited.Add(JSONObject.StringObject(id));
            }
            JSONObject jsonInvited = new JSONObject(invited.ToArray());

            soomlaProfile_PushEventInviteFinished(provider.ToString(), SocialActionType.INVITE.ToString(), requestId, jsonInvited.ToString(), payload);
        }
        protected override void _pushEventGetFeedFinished(Provider provider, SocialPageData <String> feedPage, string payload)
        {
            if (SoomlaProfile.IsProviderNativelyImplemented(provider))
            {
                return;
            }
            List <JSONObject> feeds = new List <JSONObject>();

            foreach (var feed in feedPage.PageData)
            {
                feeds.Add(JSONObject.StringObject(feed));
            }
            JSONObject jsonFeeds = new JSONObject(feeds.ToArray());

            soomlaProfile_PushEventGetFeedFinished(provider.ToString(), jsonFeeds.ToString(), payload, feedPage.HasMore);
        }
예제 #6
0
 protected override void _pushEventInviteFinished(Provider provider, string requestId, List <string> invitedIds, string payload)
 {
     if (SoomlaProfile.IsProviderNativelyImplemented(provider))
     {
         return;
     }
     AndroidJNI.PushLocalFrame(100);
     using (AndroidJavaClass jniSoomlaProfile = new AndroidJavaClass("com.soomla.profile.unity.ProfileEventHandler")) {
         List <JSONObject> invited = new List <JSONObject>();
         foreach (var id in invitedIds)
         {
             invited.Add(JSONObject.StringObject(id));
         }
         JSONObject jsonInvited = new JSONObject(invited.ToArray());
         ProfileJNIHandler.CallStaticVoid(jniSoomlaProfile, "pushEventInviteFinished",
                                          provider.ToString(), SocialActionType.INVITE.ToString(), requestId, jsonInvited.ToString(), payload);
     }
     AndroidJNI.PopLocalFrame(IntPtr.Zero);
 }
예제 #7
0
        protected override void _pushEventGetFeedFinished(Provider provider, SocialPageData <String> feedPage, string payload)
        {
            if (SoomlaProfile.IsProviderNativelyImplemented(provider))
            {
                return;
            }
            List <JSONObject> feeds = new List <JSONObject>();

            foreach (var feed in feedPage.PageData)
            {
                feeds.Add(JSONObject.StringObject(feed));
            }
            JSONObject feedJson = new JSONObject(feeds.ToArray());

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniSoomlaProfile = new AndroidJavaClass("com.soomla.profile.unity.ProfileEventHandler")) {
                ProfileJNIHandler.CallStaticVoid(jniSoomlaProfile, "pushEventGetFeedFinished",
                                                 provider.ToString(), feedJson.ToString(), payload, feedPage.HasMore);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
        }
예제 #8
0
    private void foundBeat(double t)
    {
        double avg = (t + startBeat) / 2;
        //print(avg + "    " + lastBeatTime);
        double bpm = 60000 / (avg - lastBeatTime);

        if (bpm > 200 || bpm < 72)
        {
            //print("Not actually " + bpm + " bpm");
            //print("Trace: ")
            lastBeatTime = avg;
            return;
        }
        if (lastBeatTime != 0)
        {
            print("Beat found: " + bpm + " BPM");
            bpms[beatcount % 5] = (int)bpm;
            beatcount++;
            print("Average bpm: " + avgbpm((int)bpm));
            socket.Emit("kinect", JSONObject.StringObject("" + avgbpm((int)bpm)));
        }
        lastBeatTime = avg;
    }
예제 #9
0
    public void Update()
    {
        if (Input.GetKeyDown(KeyCode.C))
        {
            Debug.Log("Connecting ...");
            ddpConnection.Connect();
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            ddpConnection.Close();
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            friendSub         = ddpConnection.Subscribe("friends");
            friendSub.OnReady = (Subscription obj) => {
                Debug.Log("Ready subscription: " + obj.id);
            };
        }

        if (Input.GetKeyDown(KeyCode.U))
        {
            ddpConnection.Unsubscribe(friendSub);
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            ddpConnection.Call("friends.removeAll");
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            ddpConnection.Call("friends.create", JSONObject.CreateStringObject("Coco"));
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            foreach (var entry in friendCollection.documents)
            {
                Debug.Log(entry.Key + " " + entry.Value);
            }
        }

        if (Input.GetKeyDown(KeyCode.O))
        {
            JSONObject parents = new JSONObject();
            parents.AddField("mother", "wonder woman");
            parents.AddField("father", "batman");
            JSONObject attr = new JSONObject();
            attr.AddField("age", 24);
            attr.AddField("height", 180);
            attr.AddField("parents", parents);
            ddpConnection.Call("friends.addAttributes", JSONObject.StringObject("Coco"), attr);
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            JSONObject attr = new JSONObject();
            attr.AddField("age", 1);
            attr.AddField("height", 1);
            attr.AddField("parents.mother", 1);
            ddpConnection.Call("friends.removeAttributes", JSONObject.StringObject("Coco"), attr);
        }
    }
예제 #10
0
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }
        if (socket == null)
        {
            print("Null socket");
            socket = BodySourceManager.AddComponent <SocketIOComponent>();
            //socket.Awake();
            socket.Start();
            socket.Emit("kinect", JSONObject.StringObject("60"));
        }
        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        //foreach(ulong trackingId in knownIds)
        //{
        //    if(!trackedIds.Contains(trackingId))
        //    {
        //        Destroy(_Bodies[trackingId]);
        //        _Bodies.Remove(trackingId);
        //    }
        //}

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
예제 #11
0
    public void OnOpen(SocketIOEvent e)
    {
        Debug.Log("[SocketIO] Open(): " + e.data);

        socket.Emit("joinRoom", JSONObject.StringObject("music"));
    }
예제 #12
0
        static JSONObject ExportToJsonObject(JsonNode jsonNode)
        {
            switch (jsonNode.JsonType)
            {
            case JsonNode.JsonNodeType.Object:

                var objData = new JSONObject
                {
                    type = JSONObject.Type.OBJECT,
                    keys = new List <string>(),
                    list = new List <JSONObject>(),
                };
                if (jsonNode.Keys.Count > 0)
                {
                    var ch = jsonNode.GetChildren().ToArray();
                    for (int i = 0; i < jsonNode.Keys.Count; i++)
                    {
                        string     key   = jsonNode.Keys[i];
                        JSONObject value = ExportToJsonObject(ch[i] as JsonNode);
                        objData.AddField(key, value);
                    }
                }
                return(objData);


            case JsonNode.JsonNodeType.Array:

                var arrayData = new JSONObject
                {
                    type = JSONObject.Type.ARRAY,
                    list = new List <JSONObject>(),
                };
                if (jsonNode.ChildCount > 0)
                {
                    var ch = jsonNode.GetChildren().ToArray();
                    for (int i = 0; i < jsonNode.ChildCount; i++)
                    {
                        JSONObject value = ExportToJsonObject(ch[i] as JsonNode);
                        arrayData.Add(value);
                    }
                }
                return(arrayData);


            case JsonNode.JsonNodeType.String:
                return(JSONObject.StringObject(jsonNode.str));

            case JsonNode.JsonNodeType.Number:
                return(new JSONObject(jsonNode.f));

            case JsonNode.JsonNodeType.Bool:
                return(new JSONObject(jsonNode.b));

            case JsonNode.JsonNodeType.Null:
                return(JSONObject.nullJO);


            default:
                throw new Exception($"Unknown json data type in {jsonNode.displayName}");
            }
        }