2014-10-01 55 views
1

過程中的錯誤,我想要實現使用DurandalJS我的SPA項目autobahn 0.9.5高速公路0.9.5(AMD) - WebSocket的握手

 var ab = require('autobahn'); 

     live = new ab.Connection(
     { 
      url: 'ws://localhost:8080', 
      realm: 'realm1' 
     }); 

     live.onopen = function(session, details) 
     { 
      console.log('Autobahn open successfully!', session); 
     }; 

     live.onclose = function(reason, details) 
     { 
      console.log('Autobahn connection lost', reason + ' - ' + details); 
     }; 

     live.open(); 

我在Firefox和Chrome瀏覽器收到錯誤

火狐:

InvalidAccessError: A parameter or an operation is not supported by the underlying object 
websocket.close(code, reason); 

鉻:

WebSocket connection to 'ws://localhost:8080/' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received 

我不知道發生了什麼事..

之前我入門 - 高速公路0.9.5

我有的test.html寫簡單的測試,看看是否在後臺的一切設置正確。
但在這個測試我目前使用的高速公路0.8.2

的test.html

<script src="http://autobahn.s3.amazonaws.com/js/autobahn.min.js"></script> 
<script> 
    var conn = new ab.Session(

     // Websocket host 
     'ws://localhost:8080', 

     // Callback on connection established 
     function() { 
      // Once connect, subscribe to channel 
      conn.subscribe('3', function(topic, data) { 
       console.log(topic, data);    
      }); 
     }, 

     // Callback on connection close 
     function() { 
      console.warn('WebSocket connection closed'); 
     }, 

     // Additional AB parameters 
     {'skipSubprotocolCheck': true} 
    ); 
</script> 

該測試爲我所需要的完美的工作,但之後,我嘗試實現這裏面真正的項目,我無法使用requireJS加載高速公路0.8.2,它總是給我一個錯誤ab沒有定義。

我不是很瞭解發生了什麼,根據autobahn getting started,它應該工作。

,這裏是我如何定義它的main.js(requirejs路徑和墊片配置)

requirejs.config({ 
    paths: { 
     'autobahn'   : 'https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min', 
     'when'    : 'https://cdnjs.cloudflare.com/ajax/libs/when/2.7.1/when' 
    }, 
    shim: { 
    'autobahn': { 
     deps: ['when'] 
    } 
    } 
}); 

希望有人能幫助我,我真的很喜歡,使其工作!

任何幫助將不勝感激! 謝謝

+0

嘿,那是什麼造成此問題的連接這兩個錯誤?我正在用RatchetPHP編寫一個應用程序,並且在使用最新的高速公路和玩'sarted'時顯示相同的兩個錯誤,但該應用程序似乎在0.8.2工作正常:( – StrayObject 2015-10-12 00:23:03

回答

1

可能晚了,但供進一步參考。

這可能不是SO問題的完整答案。首先,應該爲AutobahnJS v0.8.2(支持WAMPv1)或AutobahnJS v0.9.5(WAMPv2)編寫所有內容。

檢查API文檔。

WAMP V1

連接

WAMP V2

+0

Thanks @MrW,我已經成功地使它工作!事情導致我無法連接(錯誤返回)是我們錯過了後端的東西。所以,我投你一個很好的參考! – 2014-12-16 03:35:38

+0

謝謝!這有助於很多明確對於我自己來說也是這樣,經過大量的閱讀。 – 2014-12-16 10:36:29

+0

0.9.5的鏈接是錯誤的 - 給出0.8.2? – andig 2015-01-09 14:15:27