2016-08-03 2 views
0

첫 크롬 확장을 개발 중입니다. 그리고 신호 R2를 구현하여 크롬 알림을 표시했습니다. 문제는 확장 프로그램이 일정 시간 동안 idol 인 경우 알림 표시를 중단하고 그동안 background.js를 디버깅 (확장의 배경 페이지 열기)하면 알림 표시가 시작된다는 것입니다. 여기 알림을 표시하기 위해 크롬 확장을 다시로드해야합니다.

은 한 번 실행 된 후

$(function() { 

var connection = $.hubConnection(); 
connection.url = 'http://localhost:8089/signalr'; 
var notificationHubProxy = connection.createHubProxy('notificationHub'); 
notificationHubProxy.on('addNotificationToExtension', function (callFrom, phoneNumber) { 

    var firstRun = 
     { 
      type: "basic", 
      title: callFrom, 
      message: phoneNumber, 
      iconUrl: "icon.png" 
     } 
    chrome.notifications.create(firstRun); 
}); 

connection.start().done(function() { 
    console.log('Connection established.'); 
}); 
}) 
+0

배경 페이지에' "persistent": false'를 사용하고 있습니까? 제거해보십시오. – wOxxOm

+0

아니요, 이미 삭제했습니다. –

+0

래퍼 ('$ (function() {...})를 제거해보십시오. 확장 기능의 백그라운드 페이지 내에서 0을 목적으로합니다. – wOxxOm

답변

0

는 분명, 폐쇄 내부의 변수가 notificationHubProxy와 함께, 파괴 내 신호 R 구현

[HttpGet] 
    public void SendNotificationYealink(string mac, string ip, string model, string active_url, string active_user, string active_host, string local, string remote, string display_local, string display_remote, string call_id, string action) 
    { 
     var context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>(); 
     context.Clients.All.addNotificationToExtension("Arslan", "Active_User =" + active_user + 
      ", Local =" + local + ", Remote =" + remote + ", Display_Local =" + display_local + ", Display_Remote =" + display_remote + ", Call Id=" + call_id); 
    } 

그리고 내 background.js 자사의 이벤트 리스너.

코드 주위로 ($(function() { ... })() 래퍼를 제거하면 확장 된 배경 환경에서 실행되기 때문에 확장 프로그램의 배경 페이지에서 아무런 역할을하지 않으므로 다른 사람에게 변수를 숨길 필요가 없습니다. 이 오프 기회에

가 초기화됩니다 배경 페이지의 DOM을 보장하는 방법입니다 당신은 실제로 단순히 닫는 </body> 태그 전에 <script src="background.js"></script> background.html의 끝으로 이동, 그 안에 DOM 요소를 가지고있다.

+0

저에게 효과적이었습니다. –

관련 문제