Beispiel #1
0
        public WebSocketRailsChannel(String channelName, WebSocketRailsDispatcher dispatcher, bool isPrivate)
        {
            String eventName = null;

            if (isPrivate)
            {
                eventName = "websocket_rails.subscribe_private";
            }
            else
            {
                eventName = "websocket_rails.subscribe";
            }

            this.channelName = channelName;
            this.dispatcher  = dispatcher;

            JSONObject frame = new JSONObject(JSONObject.Type.ARRAY);

            frame.Add(eventName);

            JSONObject dataJSON = new JSONObject();
            JSONObject infoJSON = new JSONObject();

            infoJSON.AddField("channel", channelName);
            dataJSON.AddField("data", infoJSON);

            frame.Add(dataJSON);
            frame.Add(dispatcher.ConnectionId);
//            UnityEngine.Debug.LogWarning(frame);
            WebSocketRailsEvent _event = new WebSocketRailsEvent(frame, null, null);

            callbacks = new Dictionary <String, List <EventHandler <WebSocketRailsDataEventArgs> > >();

            dispatcher.TriggerEvent(_event);
        }
Beispiel #2
0
        public void Trigger(String eventName, JSONObject message)
        {
            JSONObject frame = new JSONObject();

            frame.Add(eventName);

            JSONObject infoJSON = new JSONObject();

            infoJSON.AddField("channel", channelName);
            infoJSON.AddField("data", message);
            infoJSON.AddField("token", token);

            frame.Add(infoJSON);
            frame.Add(dispatcher.ConnectionId);

//            UnityEngine.Debug.LogError(frame);
            WebSocketRailsEvent _event = new WebSocketRailsEvent(frame, null, null);

            dispatcher.TriggerEvent(_event);
        }
        public void Trigger(String eventName, Object message)
        {
            List <Object> frame = new List <Object>();

            frame.Add(eventName);

            Dictionary <String, Dictionary <String, Object> > data = new Dictionary <String, Dictionary <String, Object> >();

            Dictionary <String, Object> info = new Dictionary <String, Object>();

            info["channel"] = channelName;
            info["data"]    = message;
            info["token"]   = token;

            frame.Add(info);
            frame.Add(dispatcher.ConnectionId);

            WebSocketRailsEvent _event = new WebSocketRailsEvent(frame, null, null);

            dispatcher.TriggerEvent(_event);
        }
        public WebSocketRailsChannel(String channelName, WebSocketRailsDispatcher dispatcher, bool isPrivate)
        {
            String eventName = null;

            if (isPrivate)
            {
                eventName = "websocket_rails.subscribe_private";
            }
            else
            {
                eventName = "websocket_rails.subscribe";
            }

            this.channelName = channelName;
            this.dispatcher  = dispatcher;

            List <Object> frame = new List <Object>();

            frame.Add(eventName);

            Dictionary <String, Object> data = new Dictionary <String, Object>();

            Dictionary <String, Object> info = new Dictionary <String, Object>();

            info["channel"] = channelName;

            data["data"] = info;

            frame.Add(data);
            frame.Add(dispatcher.ConnectionId);

            WebSocketRailsEvent _event = new WebSocketRailsEvent(frame, null, null);

            callbacks = new Dictionary <String, List <EventHandler <WebSocketRailsDataEventArgs> > >();

            dispatcher.TriggerEvent(_event);
        }