Exemplo n.º 1
0
    private Matchmore SetupMatchmore()
    {
        var config = new Matchmore.Config
        {
            ApiKey                  = API_KEY,
            Environment             = ENVIRONMENT,
            UseSecuredCommunication = false,
            ServicePort             = servicePort,
            PusherPort              = pusherPort,
            PersistenceFile         = "integrationstate.dat",
            LoggingEnabled          = true
        };

        return(new Matchmore(config));
    }
Exemplo n.º 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();
    }