Skip to content

Commit

Permalink
Добавил в вебсокет проверку на socket_id
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikMix committed May 15, 2024
1 parent dbe2d36 commit b09b620
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions public/src/components/TagsFilter/TagsFilter.sass
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@
z-index: 1000
width: 130px
display: none
animation: closeAnim 0.3s
border: 1px solid hsl(217.2 32.6% 25%)
border-radius: 12px
overflow: hidden

&.open
display: flex
animation: showAnim 0.3s

&__option
width: 100%
Expand Down
18 changes: 17 additions & 1 deletion public/src/modules/stores/NotesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class NotesStore extends BaseStore<NotesStoreState> {
};

private ws
private socket_id

constructor() {
super();
Expand Down Expand Up @@ -226,6 +227,7 @@ class NotesStore extends BaseStore<NotesStoreState> {

this.ws.close()
this.ws = null
this.socket_id = null
}
}

Expand Down Expand Up @@ -266,7 +268,13 @@ class NotesStore extends BaseStore<NotesStoreState> {

// TODO: синхронизация между девайсами (сверять id девайса / вебсокета)
// А нужна ли вообще проверка ? // Нужна, иначе курсор скачет // С кем ты разговариваешь?
if (data.username == AppUserStore.state.username) {
console.log("onMessage")
console.log(data)
console.log(data.socket_id)
console.log(this.socket_id)
console.log(data.socket_id == this.socket_id)
if (data.socket_id == this.socket_id) {
console.log("return")
return
}

Expand All @@ -284,6 +292,8 @@ class NotesStore extends BaseStore<NotesStoreState> {
}))
}

} else if (data.type == "info") {
this.socket_id = data.socket_id
} else if (data.type == "closed") {
const collaborator = {
id: data.user_id,
Expand Down Expand Up @@ -419,6 +429,12 @@ class NotesStore extends BaseStore<NotesStoreState> {

AppDispatcher.dispatch(UserActions.UPDATE_CSRF, csrf);

this.ws.sendMessage(JSON.stringify({
type: "edit",
data: data,
socket_id: this.socket_id
}))

} catch {
AppToasts.error('Что-то пошло не так');
}
Expand Down

0 comments on commit b09b620

Please sign in to comment.