2016-07-28 2 views
0

WebSocket 또는 폴링을 사용하는 경우 현재 프로토콜을 식별하는 방법을 궁금해했습니다.유성 연결의 프로토콜을 식별하는 방법

- 클라이언트. (확실하게 첨부 됨)

디버그 콘솔에서 유효한 정보를 찾았습니다.

Meteor.connection._stream.socket.protocol

하고 중 하나 개의 값을 갖고있는 것 같아요 ...

['websocket', 
'xdr-streaming', 
'xhr-streaming', 
'iframe-eventsource', 
'iframe-htmlfile', 
'xdr-polling', 
'xhr-polling', 
'iframe-xhr-polling', 
'jsonp-polling']; 

는 현재의 프로토콜을 식별하기 위해 더 유예 방법은 무엇입니까? 언제 프로토콜을 검색하는 것이 가장 빠른 타이밍일까요?

AWS ELB가 끈적 세션과 websocket을 동시에 지원하지 않기 때문에 필요한 끈적 세션이있을 때 다른 DDP 서버를 사용해야합니다.

답변

0

Meteor는 DDP 프로토콜을 사용합니다. 다른 Meteor 서버에 연결하여 메소드를 호출하려면 다음과 같이 DDP.connect를 사용하십시오.

import { DDP } from 'meteor/ddp-client' 
DDP.connect(url) 

불행히도, 프로토콜을 얻는 것은 아무런 유익이 없습니다. onConnection은 몇 가지 정보가있는 객체를 반환합니다.

Meteor.onConnection(obj => 
    { console.log(obj.httpHeaders.x-forwarded-proto); }); 

그러면 websocket에 'ws'가 반환됩니다. 이 프로토콜을 얻는 방법은 우아하지 않습니다!

+0

아마도 제 질문이 잘못되었습니다. SockJS 연결 프로토콜을 알고 싶었습니다. [ '웹 소켓', 'XDR-스트리밍', 'XHR 스트리밍', '은 iframe-eventsource', '은 iframe-htmlfile', 'XDR-폴링', 'XHR 폴링'사이, ' iframe-xhr-polling ', 'jsonp-polling ']; – Kennyhyun

+0

원본 답변에 추가 정보가 업데이트되었습니다. – vijayst

0

Meteor.status()은 반응적인 데이터 소스를 제공합니다. 그런 (https://docs.meteor.com/api/connections.html#DDP-connect)

if (Meteor.isClient) { 
    Tracker.autorun(() => { 
    const stat = Meteor.status(); 
    if (stat.status === 'connected') { 
     console.log(Meteor.connection._stream.socket.protocol); 
    } 
    }); 
} 

무언가는 클라이언트 측에서 현재 프로토콜을 제공 할 것입니다.