开发者

Would it be viable to make a portable online chat application with Node.js?

开发者 https://www.devze.com 2023-04-06 03:39 出处:网络
I am wondering if it is possible to make a portable chat application with Node.js. What I mean by portable is that, if there is a central website which provides chat service with Node.js, users can f

I am wondering if it is possible to make a portable chat application with Node.js.

What I mean by portable is that, if there is a central website which provides chat service with Node.js, users can fetch the script codes (whether it is based on JavaScript or iframe) and post the chat program on their website.

Assume this application is hosted on chatServer.com

  1. For example, if user has a div with its ID chatScreen adequate form input and has linked one of scripts from the chatServer.com

Or

  1. user can just iframe the chat page. (ex: chatServer.com/chat/room/roomName)

Or

  1. using the flash swf to port it in to the page.

If I remember correctly, JSON data are not tradable across different domains.

Do you think it is possible to make this application?

I just want to know whether it is possible to build it or not.

I have seen some similar web chat application that was implemented with 'Pytho开发者_如何学JAVAn twisted'+'swf'


If you use socket.io it'll simply use jsonp for cross domain communication.

<script src="//chatServer.com/socket.io.js"></script>
<script>
  var socket = io.connect('//chatServer.com');
  socket.on('chat', function (data) {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });
</script>


i Have faced issue in cross domain my code for app.js is

 var express = require('express'),
 app = express();
 var port = process.env.PORT || 8080;

// Initialize a new socket.io object. It is bound to 
// the express app, which allows them to coexist.

var io = require('socket.io').listen(app.listen(port));

// Require the configuration and the routes files, and pass
// the app and io as arguments to the returned functions.
  io.use(function(socket, next) {
   var handshakeData = socket.request;
    //console.log(handshakeData);
    next();

                });

    // Require the configuration and the routes files, and pass
     // the app and io as arguments to the returned functions.

   app.use(function(req, res, next) {
      res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "X-Requested-With");
      res.header("Access-Control-Allow-Methods", "GET,POST");
      next();
     });
    require('./config')(app, io);
    require('./routes')(app, io);

    console.log('Your application is running on http://localhost:' + port);
0

精彩评论

暂无评论...
验证码 换一张
取 消