Esempio n. 1
0
        public Broadcaster()
        {
            // 获取Hub上下文以方便向连接的客户端发送消息
            _hubContext = GlobalHost.ConnectionManager.GetHubContext<TestHub>();

            _model = new ShapeModel();
            _modelUpdated = false;

            // 开始间隔广播循环
            _broadcastLoop = new Timer(BroadcastShape, null, BroadcastInterval, BroadcastInterval);
        }
Esempio n. 2
0
 /// <summary>
 /// 更新位置数据
 /// </summary>
 public void UpdateShape(ShapeModel clientModel)
 {
     _model = clientModel;
     _modelUpdated = true;
 }
Esempio n. 3
0
        /// <summary>
        /// 更新模型数据
        /// </summary>
        /// <param name="clientModel">模型数据</param>
        public void UpdateModel(ShapeModel clientModel)
        {
            // 获取发送数据的连接Id
            clientModel.LastUpdatedBy = Context.ConnectionId;
            // 使用循环广播器广播数据
            _broadcaster.UpdateShape(clientModel);

            // [否决的]根据连接Id更新除发送者以外的所有浏览器客户端
            // Clients.AllExcept(clientModel.LastUpdatedBy).updateShape(clientModel);
        }