示例#1
0
 public override void Start()
 {
     if (MockLocation != null)
     {
         _running = true;
         base.Start();
     }
     else
     {
         _coroutine.RunOnce("location_service_start", LocationServiceStarter.Start(() =>
         {
             //setup a coroutine which will just copy data to this object so the thread actually can take it and send to matchmore
             _coroutine.SetupContinuousRoutine("data_update", () =>
             {
                 _status       = Input.location.status;
                 _locationInfo = Input.location.lastData;
             });
             _running = true;
             base.Start();
         }));
     }
 }
示例#2
0
    public WebsocketMatchMonitor(Device device, Matchmore.Config config, DeviceApi deviceApi, CoroutineWrapper coroutine, Action<string> closedCallback)
    {
        if (device == null || string.IsNullOrEmpty(device.Id))
        {
            throw new ArgumentException("Device null or invalid id");
        }

        _device = device;
        _deviceApi = deviceApi;
        _coroutine = coroutine;
        _closedCallback = closedCallback;
        var worldId = Utils.ExtractWorldId(config.ApiKey);

        MatchmoreLogger.Debug("Starting websocket for device {0}", device.Id);

        var protocol = config.UseSecuredCommunication ? "wss" : "ws";
        var port = config.PusherPort == null ? "" : ":" + config.PusherPort;
        var url = string.Format("{3}://{0}{4}/pusher/{1}/ws/{2}", config.Environment, Matchmore.API_VERSION, _device.Id, protocol, port);
        _ws = new WebSocket(url, "api-key", worldId);

        _ws.OnOpen += (sender, e) => MatchmoreLogger.Debug("WS opened for device {0}", device.Id);
        _ws.OnClose += (sender, e) => MatchmoreLogger.Debug("WS closing {0} for device {1}", e.Code, device.Id);
        _ws.OnError += (sender, e) => MatchmoreLogger.Debug("Error in WS {0} for device {1}", e.Message, device.Id);
        _ws.OnMessage += (sender, e) =>
        {
            var data = e.Data;
            if (data == "ping")
            {
                _ws.Send("pong");
            }
            else
            {
                _coroutine.RunOnce(Id, GetMatch(data));
            }
        };
        _ws.Connect();
    }
示例#3
0
 public void Start()
 {
     _coroutine.RunOnce("location_service_start", StartLocationServiceCoroutine());
 }