Angularjs应用程序的多个实例
Angularjs multiple instances of app
我想知道是否有可能在两个独立的浏览器上运行同一个应用程序,并从一个浏览器更新到另一个浏览器?
假设我的应用程序运行在chrome上:http://127.0.0.1:8000/#当任何打开的会话更新了我想在其他会话上获得的更新/警报时,在Firefox或其他隐姓埋名的chrome选项卡中也会打开。任何指示都将不胜感激。
感谢
我为此创建了两个Web服务器:
其中一个运行websocket。其他应用程序。
websocket示例nodejs:
#!/usr/bin/env node
var WebSocketServer = require("ws").Server;
var http = require("http");
var express = require("express");
var port = process.env.PORT || 5000;
var app = express();
app.use(express.static(__dirname+ "/../"));
app.get('/test', function(req, res, next) {
console.log('receiving get request');
});
app.post('/test', function(req, res, next) {
console.log('receiving post request');
});
app.listen(80);
//console.log("app listening on %d ", 80);
var server = http.createServer(app);
server.listen(port);
console.log("http server listening on %d", port);
var userId;
var wss = new WebSocketServer({server: server});
wss.on("connection", function (ws) {
console.info("websocket connection open");
var timestamp = new Date().getTime();
userId = timestamp;
ws.send(JSON.stringify({msgType:"onOpenConnection", msg:{connectionId:timestamp}}));
ws.on("message", function (data, flags) {
console.log("websocket received a message");
var clientMsg = data;
wss.clients.forEach(function each(client) {
client.send(clientMsg);
});
});
ws.on("close", function () {
console.log("websocket connection close");
});
});
console.log("websocket server created");
angularjs部件:
.run(function ($rootScope) {
if ("WebSocket" in window)
{
console.log("WebSocket is supported by your Browser!");
$rootScope.updated = false;
// Let us open a web socket
socket = new WebSocket("ws://localhost:5000", "echo-protocol");
socket.addEventListener("open", function(event) {
console.log( "Connected" );
});
// Display messages received from the server
socket.addEventListener("message", function(event) {
console.log( "Server Says: " + event.data );
if (!$rootScope.updated)
if (event.data == "updated list") {
//here can passdata or update data
alert("Please refresh the page, new data should be available!");
}
});
// Display any errors that occur
socket.addEventListener("error", function(event) {
console.log( "Error: " + event );
});
socket.addEventListener("close", function(event) {
console.log("Not Connected");
});
}
else
{
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
}
})
然后运行"node-websocket.js"和应用程序"http server-o"
相关文章:
- 如何通过osascript处理同一应用程序的两个实例
- Angularjs应用程序的多个实例
- 在两台不同的服务器上运行同一node.js应用程序的两个实例
- 使用AsyncStorage实例化持久应用程序状态
- 在单页应用程序上重用谷歌地图API实例
- 适用于 Android 应用程序的 Java 代码中的实例化异常
- 在 Angular.js 中跨应用程序使用相同的对象实例
- 创建 JavaScript 自定义应用程序的新实例
- 使用主干.js中的路由管理单页应用程序中的多个视图实例
- 在应用程序中获取多个 ID 实例
- 如何拥有具有单独LocalStorage的单独Electron应用程序实例
- 对 Ember 应用程序进行反射/自省,以查找特定模型的实例
- Amazon EC2 实例上的负载测试节点.js应用程序
- 如何在视图中呈现部分 js 或访问在应用程序/资产中的 js.erb 文件中的控制器操作中初始化的实例变量/方法
- 区分浏览器选项卡关闭和刷新(以检测应用程序的多个实例)
- 从应用程序类函数访问控制器实例
- 如何将apache2.2配置为负载均衡器来管理运行javascript应用程序的tomcat实例
- Meteor应用程序-如何实现多实例部署的编排/配置
- 登录到其他选项卡上的一个Web浏览器实例中的应用程序
- 创建在单个服务器上运行的metro.js应用程序的多个实例需要哪些主要步骤