如何使用socket.io在没有关闭或断开连接的情况下停止对套接字的请求?

时间:2015-12-21 15:15:07

标签: javascript php node.js socket.io

我有一个应用程序,其中显示所有在线驱动程序。现在我有一个出租车请求列表,这是任何在线驾驶员都不接受的。此处还有重新发送待处理请求的功能。该请求将逐个发送给所有驱动程序。现在我想要的功能就像当我向所有驱动程序重新发送请求时@我希望取消将该请求从1跳转到其他驱动程序。我用过socket.io。现在我想要这个功能而不关闭套接字连接。我怎么能这样做?

这是我的代码: -

CabRequest.prototype.makeRequest = function (again) {
    //alert(again);
var self = this;
        if (++this.requestStack > size(taxis)) {
this.failure();
        self.myIntervalClear(this.makeRequestInterval);
        return;
        }

var lat1 = self.position.lat();
        var lon1 = self.position.lng();
        if (!again){
self.pending = $.map(taxis, function(value, index) {
return [value]; });
        for (var i = 0; i < self.pending.length; i++) {
console.log(haversine(lat1, lon1, self.pending[i].loc.position.lat(), self.pending[i].loc.position.lng()));
        self.pending[i].distance = haversine(lat1, lon1, self.pending[i].loc.position.lat(), self.pending[i].loc.position.lng());
        }
self.pending.sort(function(a, b) {
return parseFloat(a.distance) - parseFloat(b.distance);
        });
        }

if (!lat1 || !lon1 || !self.phonenumber || !self.vehicle || !self.fullname) return;
        // console.log(self.pending);
        if (self.pending.length == 0) {
console.log("NO DRIVERS");
        $("#alert").text("No Drivers");
        console.log(self);
        }
else {
self.currentDriverSending = 1;
        }
this.sendNextRequest();
};

//below code is use to send next request

CabRequest.prototype.sendNextRequest = function () {
//    alert(len);
    if (this.pending.length > 0 ) {
        var taxi = this.pending.shift();
            if (taxi == null) {
                console.log("NO TAXI FOUND");
                return;
            }
        nextDriver(this.uniqueId, taxis[taxi.id].fullname);
        AddDispatchLog(this.uniqueId, this.phonenumber, taxis[taxi.id].fullname, 'Dispatch');
        socket.emit(7,
        {
        id: taxi.id,
                lat: this.position.lat(),
                lon: this.position.lng(),
                fullname: this.fullname,
                dest: this.destination.lat().toString() + "," + this.destination.lng().toString(),
                vehicle: this.vehicle,
                date: this.date,
                additional: (this.info + '_' + price),
                minutesBefore: "5",
                phonenumber: this.phonenumber,
                uniqueId: this.uniqueId
        });
        currentDriver = taxi.id;
    }
    else {`enter code here`
    //myIntervalClear(makeRequestInterval);
    this.makeRequest(false);
    }
};

现在我想在用户点击前端的取消按钮时停止请求。我怎么能这样做?

0 个答案:

没有答案