Beispiel #1
0
    void ProcessSpacebrewMessage(SpacebrewMessage _cMsg)
    {
//		foreach (SpacebrewEvent element in spacebrewEvents)
//		{
//			//This will now work because you've constrained the generic type V
//			print(element.sbEvent);
//			if (_cMsg.name == element.sbEvent) {
//
//				// if this element subscribes to this event then call it's callback
//				//element.eventCallback
//				//element.sbGo.OnSpacebrewEvent(_cMsg);
//				element.sbGo.SendMessage("OnSpacebrewEvent", _cMsg);
//				//this.GetComponent<SpacebrewEvents>().OnSpacebrewEvent(_cMsg);
//				//this.GetComponent<MyScript>().MyFunction();
//				//print(element.sbGo);
//				//element.sbGo.gameObject.SpacebrewEvent(_cMsg);
//				//element.sbGo.
////				MethodInfo mi = element.sbGo.GetType().GetMethod(element.eventCallback);
//				//mi.Invoke(element.sbGo, null);
//			}
//		}
        if (_cMsg.name == "hits")
        {
            if (_cMsg.value == "true")
            {
                print("do something");
                //pillVisible = !pillVisible;
            }
        }
    }
Beispiel #2
0
    void Awake()
    {
        conn         = new WebSocket(serverAddress);  // removed WebSocket on begin
        conn.OnOpen += (sender, e) => {
            print("Attempting to open socket");
        };

        conn.OnMessage += (sender, e) => {
            print(e.Data);

            // parse the incoming json message from spacebrew
            var N    = JSON.Parse(e.Data);
            var cMsg = new SpacebrewMessage();
            cMsg.name       = N["message"]["name"];
            cMsg.type       = N["message"]["type"];
            cMsg.value      = N["message"]["value"];
            cMsg.clientName = N["message"]["clientName"];

            print(cMsg);
            spacebrewMsgs.Add(cMsg);
            //ProcessSpacebrewMessage(cMsg);

//			if (e.Type == Opcode.Text) {
//				// Do something with e.Data
//				print (e);
//				print (e.Data);
//				return;
//			}
//
//			if (e.Type == Opcode.Binary) {
//				// Do something with e.RawData
//				return;
//			}
        };

        conn.OnError += (sender, e) => {
            print("THERE WAS AN ERROR CONNECTING");
            print(e.Message);
        };

        conn.OnClose += (sender, e) => {
            print("Connection closed");
        };

        print("Attemping to connect to " + serverAddress);
        conn.Connect();

        //addPublisher ("power", "boolean", "0");
        //addSubscriber ("hits", "boolean");

        // Connect and send the configuration for the app to Spacebrew
        conn.Send(makeConfig().ToString());
    }
Beispiel #3
0
    private void HandleMessage(JSONNode message)
    {
        var sbMsg = new SpacebrewMessage {
            name       = message["name"],
            type       = message["type"],
            value      = message["value"],
            clientName = message["clientName"]
        };

//TODO: REMOVE THIS PRINT - DEBUG PURPOSE
//print(sbMsg);
//        spacebrewMsgs.Add(sbMsg);
        spacebrewNewMsgs.Add(sbMsg);
//TODO: might be better to handle message directly instead of putting in messages queue?
        //ProcessSpacebrewMessage(cMsg);
    }