Exemplo n.º 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);
        }
        public WebSocketRailsConnection(Uri uri, WebSocketRailsDispatcher dispatcher)
        {
            this.uri           = uri;
            this.dispatcher    = dispatcher;
            this.message_queue = new List <WebSocketRailsEvent>();

            webSocket                  = new WebSocket(uri.ToString(), "", "");
            webSocket.Closed          += webSocket_Closed;
            webSocket.MessageReceived += webSocket_MessageReceived;
        }
	    public WebSocketRailsConnection(Uri uri, WebSocketRailsDispatcher dispatcher) 
        {
            this.uri = uri;
            this.dispatcher = dispatcher;
            this.message_queue = new List<WebSocketRailsEvent>();

	        _webSocket = new WebSocket(uri.ToString());
            _webSocket.Closed += webSocket_Closed;
            _webSocket.MessageReceived += webSocket_MessageReceived;

	        _webSocket.Error += (sender, args) => OnError(args);
	        _webSocket.Opened += (sender, args) => OnOpened();
	        _webSocket.Closed += (sender, args) => OnClosed();
        }
        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);
        }