2017-12-19 5 views
0

게임을 만들 때 firebase의 점수를 업데이트하는 라이브 스코어링 서버가 있습니다. 현재 노드 서버에는 firebase가있는 노드 유형을 구체적으로 참조하는 코드가있는 리스너가 있습니다.firebase에있는 여러 청취자

ref.orderByChild("league").equalTo('NBA').on("value", function(snapshot) { 
refreshInterval = setInterval(function() { 
    nbafile.nbaUpdate(snapshot.val()); 

}, 5000); 

}, function(errorObject) {}); 
}; 

그것은 게임 타이머는 게임을 5 초마다 업데이트되도록 설정되어 중포 기지에서 생성하고 게임 상태를 닫은 후 갱신을 중지 할 때 현재 로선. 나는 시도하고 그것이 활성화되지 않습니다 중 하나와 같은 NCAAB 같은 다른 스포츠에 대한 추가 리스너를 추가하거나이 둘 다라고하지만 타이머가 정지하지 않는 경우

: 여기

문제입니다. 라고 어느 기능

ref.orderByChild("league").equalTo('NCAAB').on("value", function(snapshot) { 
refreshInterval = setInterval(function() { 
    cbbfile.cbbUpdate(snapshot.val()); 
}, 5000); 
}, function(errorObject) {}); 

}

먼저 선례를 가져오고 다른 스포츠는 발생하지 않습니다.

다음은 게임이 가리키는 if 문과 함께 완전한 코드입니다. 이 작동하지 않는

const startUpdate = function(db, ref) { 

    db = admin.database(); 
    exports.db = db; 
    ref = db.ref('game'); 
    exports.ref = ref; 
    console.log('-----------------------------------'); 
    ref.orderByChild("league").equalTo('NBA').on("value", function(snapshot) { 
    refreshInterval = setInterval(function() { 
     nbafile.nbaUpdate(snapshot.val()); 

    }, 5000); 

    }, function(errorObject) {}); 

}; 

const startUpdate2 = function(db, ref) { 

    db = admin.database(); 
    exports.db = db 
    ref = db.ref('game'); 
    exports.ref = ref; 
    console.log('-----------------------------------'); 
    ref.orderByChild("league").equalTo('NCAAB').on("value", function(snapshot) { 
    refreshInterval = setInterval(function() { 
     cbbfile.cbbUpdate(snapshot.val()); 
    }, 5000); 

    }, function(errorObject) {}); 
} 

nbaupdate.js

let nbaUpdate = function(games) { 
    console.log("Professional Basketball"); 
    if (games === null) { 
    console.log('Games object empty'); 
    return; 
    } 
    for (var id in games) { 
    if (games[id].league === 'NCAAB'); 
    if (ts >= games[id].scheduledTimeUnix); 
    if ((games[id].status == 'complete') || (games[id].status == 'closed')) { 
     sports.clearTimer(); 
     console.log(games[id].status) 
    } else { 

답변

0

이유는 각 I 리스터에 동일한 clearTimer() 함수를 한 것으로했다. 그래서 간격은 두 청취자 모두에서 제거되었습니다.