2013-09-04 11 views
6

Sto eseguendo questo esempio di chat https://github.com/btford/angular-socket-io-im che utilizza socket.io/angular/node per creare un im client di base.AngularJS: app di chat con socket.io su https

Tuttavia, si verifica un problema quando provo a farlo funzionare su https.

Nessun evento di socket viene catturato sul server, quindi nessun messaggio di chat viene inviato ai client e gli utenti non possono accedere alle room. Inoltre ottengo questo errore sul client in socket.io.js:

Uncaught TypeError: Cannot call method 'onClose' of null 

Ho creato un server expresshttps in ascolto sulla porta 8000 e modificato la definizione presa a:

var socket = io.connect('https://localhost:8000',{secure: true, port:8000}); 

sia in js/services.js e in /bower_components/angular-socket-io/socket.js

Non sono sicuro di come risolvere il problema. Grazie in anticipo!

+0

Riesci a guardare a questo URL: http: // StackOverflow .com/questions/15295672/uncaught-typeerror-can not-call-method-onclose-of-null –

+0

Interessante, hai ancora trovato una soluzione? –

+0

Sto avendo lo stesso problema. – chovy

risposta

0

Ho un app che fa questo stessa cosa esatta :) utilizza presa io e usa: 8080 è necessario assicurarsi che il CERT di sicurezza è la registrazione che sia https://localhost e https://localhost:8000 ed è stato aggiunto al tuo portachiavi in ​​caso contrario la pagina sarà caricare ma le connessioni socket falliranno.

0

Solo erano tenuti alcune modifiche per renderlo disponibile tramite https, anche se questo è un vecchio Application Express 2.5 si dovrebbe prendere in considerazione esaminando: https://github.com/guille/chat-example.git

/** 
* Module dependencies. 
*/ 

var fs = require('fs'); 
var options = { 
    key:fs.readFileSync('key.pem'), 
    cert:fs.readFileSync('cert.pem') 
}; 
var express = require('express'), 
    routes = require('./routes'), 
    socket = require('./routes/socket.js'); 

var app = module.exports = express.createServer(options); 



// Hook Socket.io into Express 
var io = require('socket.io').listen(app); 

// Configuration 

app.configure(function(){ 
    app.set('views', __dirname + '/views'); 
    app.set('view engine', 'jade'); 
    app.set('view options', { 
    layout: false 
    }); 
    app.use(express.bodyParser()); 
    app.use(express.methodOverride()); 
    app.use(express.static(__dirname + '/public')); 
    app.use(app.router); 
}); 

app.configure('development', function(){ 
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); 
}); 

app.configure('production', function(){ 
    app.use(express.errorHandler()); 
}); 

// Routes 

app.get('/', routes.index); 
app.get('/partials/:name', routes.partials); 

// redirect all others to the index (HTML5 history) 
app.get('*', routes.index); 

// Socket.io Communication 

io.sockets.on('connection', socket); 

// Start server 

app.listen(8080, function(){ 
    console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); 
}); 
Problemi correlati