Exemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            StreetHawk.Instance.SetAppKey("MyFirstApp");
            Push.GetInstance(this).RegisterForPushMessaging("491295755890");
            StreetHawk.Instance.Init(Application);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button>(Resource.Id.myButton);

            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
        }
    public Push Leave(int timeout)
    {
        Action <Response> onClose = (nop) => {
            Debug.Log("leave topic: " + Topic);
            Trigger(CHANNEL_EVENTS.CLOSE, new PayloadResp("leave"));
        };
        Push leavePush = Push.GetInstance(this, CHANNEL_EVENTS.LEAVE, new PayloadReq(), timeout);

        leavePush.Receive("ok", onClose)
        .Receive("timeout", onClose);
        leavePush.Send();
        if (!CanPush())
        {
            leavePush.Trigger("ok", new PayloadResp());
        }
        return(leavePush);
    }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());

            // Set this to your own APP KEY   <APP KEY>
            StreetHawk.Instance.SetAppKey("SHPushPing_bison");
            // Set this to your own Project Key             <Project Key>
            Push.GetInstance(this).RegisterForPushMessaging("1058940905943");
            StreetHawk.Instance.Init(Application);
            Push.GetInstance(this).RegisterSHObserver(this);
        }
    Push PushEvent(string _event, PayloadReq _payloadReq, int timeout)
    {
        if (!joinedOnce)
        {
            throw new InvalidOperationException("tried to push '" + _event + "' to '" + Topic + "' before joining. Use Channel.Join() before pushing events");
        }
        Push pushEvent = Push.GetInstance(this, _event, _payloadReq, timeout);

        if (CanPush())
        {
            pushEvent.Send();
        }
        else
        {
            pushEvent.SetResponseListener();
            pushBuffer.Add(pushEvent);
        }
        return(pushEvent);
    }
    void Config(string _topic, Socket _socket, PayloadReq _payload)
    {
        state = CHANNEL_STATES.CLOSED;

        Topic      = _topic;
        Socket     = _socket;
        payloadReq = _payload;
        timeout    = _socket.Timeout;
        joinedOnce = false;
        joinPush   = Push.GetInstance(this, CHANNEL_EVENTS.JOIN, payloadReq, timeout);

        joinPush.Receive("ok", (nop) => {
            state = CHANNEL_STATES.JOINED;
            pushBuffer.ForEach(events => events.Send());
        });

        joinPush.Receive("timeout", (nop) => {
            if (state != CHANNEL_STATES.JOINING)
            {
                return;
            }
            Debug.Log("Timeout on topic: " + Topic + " " + joinPush.Timeout);
            state            = CHANNEL_STATES.ERRORED;
            startRejoinTimer = true;
        });

        OnClose((payloadResp, refResp) => {
            Debug.Log("Close channel: " + Topic);
            state = CHANNEL_STATES.CLOSED;
            Socket.Remove(this);
        });

        OnError((payloadResp, refResp) => {
            Debug.Log("Error on topic: " + Topic + " reason: " + payloadResp.status);
            state            = CHANNEL_STATES.ERRORED;
            startRejoinTimer = true;
        });
        OnReply((payloadResp, refResp) => {
            Trigger(ReplyEventName(refResp), payloadResp);
        });
    }
Exemplo n.º 6
0
 public void OnInstallRegistered(string installId)
 {
     Push.GetInstance(this).AddPushModule();
 }