如何将客户端数据附加到服务器连接?

Lor*_*ren 5 meteor

我想象的是这样的:

# client
Meteor.call 'attachData', localStorage.getItem 'clientData'

Meteor.connection.onReconnect ->
  Meteor.call 'attachData', localStorage.getItem 'clientData'

setTimeout ->
  Meteor.call 'logData'
, 1000

# server
Meteor.methods
  attachData: (data) ->
    this.connection.data = data

  logData: ->
    console.log this.connection.data
Run Code Online (Sandbox Code Playgroud)

这似乎有效,但我不熟悉this.connection.鉴于此设置,将this.connection.data永远存在?我应该使用Meteor.connection还是Meteor.default_connection

Lor*_*ren 0

它似乎有效。当连接中断时,无论是页面重新加载还是互联网连接中断,数据都会被删除。

https://github.com/lorensr/connection-data