| 126 | } |
| 127 | |
| 128 | async resetWSInfos () { |
| 129 | this.wsInfos = { |
| 130 | inited: false, |
| 131 | friends: {} // role: friends | teacher | student |
| 132 | } |
| 133 | |
| 134 | if (me.isAnonymous()) { |
| 135 | this.wsInfos.inited = true // anonymous user do not have friends feature |
| 136 | } else { |
| 137 | console.log('publish user online', me.id) |
| 138 | this.ws.publish(this.ws.topicName('user', me.id.toString()), { online: true }) // tell others you're online |
| 139 | const friends = me.get('friends') || [] // TODO: to setup true friends feature |
| 140 | const friendTopics = [] |
| 141 | friends.forEach(f => { |
| 142 | this.addFriend(f.userId.toString(), { role: f.role }) |
| 143 | friendTopics.push(`user-${f.userId.toString()}`) |
| 144 | }) |
| 145 | this.ws.subscribe(friendTopics) |
| 146 | // const onlineFriends = await me.fetchOnlineFriends() // fetch online friends |
| 147 | // this.updateOnlineFriends(onlineFriends) |
| 148 | this.wsInfos.inited = true |
| 149 | } |
| 150 | // console.log('wsInfos reset success') |
| 151 | } |
| 152 | |
| 153 | async onMeSynced () { |
| 154 | console.log('me synced') |