Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma-fe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Matrix-Sasuke
pleroma-fe
Commits
43197c42
Commit
43197c42
authored
5 years ago
by
HJ
Browse files
Options
Downloads
Patches
Plain Diff
Some error handling
parent
b6194775
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/settings/settings.js
+4
-0
4 additions, 0 deletions
src/components/settings/settings.js
src/modules/api.js
+47
-40
47 additions, 40 deletions
src/modules/api.js
with
51 additions
and
40 deletions
src/components/settings/settings.js
+
4
−
0
View file @
43197c42
...
...
@@ -103,6 +103,10 @@ const settings = {
promise
.
then
(()
=>
{
this
.
$store
.
dispatch
(
'
setOption
'
,
{
name
:
'
useStreamingApi
'
,
value
})
}).
catch
((
e
)
=>
{
console
.
error
(
'
Failed starting MastoAPI Streaming socket
'
,
e
)
this
.
$store
.
dispatch
(
'
disableMastoSockets
'
)
this
.
$store
.
dispatch
(
'
setOption
'
,
{
name
:
'
useStreamingApi
'
,
value
:
false
})
})
}
}
...
...
This diff is collapsed.
Click to expand it.
src/modules/api.js
+
47
−
40
View file @
43197c42
...
...
@@ -35,60 +35,67 @@ const api = {
enableMastoSockets
(
store
)
{
const
{
state
,
dispatch
}
=
store
if
(
state
.
mastoUserSocket
)
return
dispatch
(
'
startMastoUserSocket
'
)
return
dispatch
(
'
startMastoUserSocket
'
)
},
disableMastoSockets
(
store
)
{
const
{
state
,
dispatch
}
=
store
if
(
!
state
.
mastoUserSocket
)
return
dispatch
(
'
stopMastoUserSocket
'
)
return
dispatch
(
'
stopMastoUserSocket
'
)
},
// MastoAPI 'User' sockets
startMastoUserSocket
(
store
)
{
const
{
state
,
dispatch
}
=
store
state
.
mastoUserSocket
=
state
.
backendInteractor
.
startUserSocket
({
store
})
state
.
mastoUserSocket
.
addEventListener
(
'
message
'
,
({
detail
:
message
})
=>
{
if
(
!
message
)
return
// pings
if
(
message
.
event
===
'
notification
'
)
{
dispatch
(
'
addNewNotifications
'
,
{
notifications
:
[
message
.
notification
],
older
:
false
})
}
else
if
(
message
.
event
===
'
update
'
)
{
dispatch
(
'
addNewStatuses
'
,
{
statuses
:
[
message
.
status
],
userId
:
false
,
showImmediately
:
false
,
timeline
:
'
friends
'
})
}
}
)
state
.
mastoUserSocket
.
addEventListener
(
'
error
'
,
({
detail
:
error
})
=>
{
console
.
error
(
'
Error in MastoAPI websocket:
'
,
error
)
})
state
.
mastoUserSocket
.
addEventListener
(
'
close
'
,
({
detail
:
closeEvent
})
=>
{
const
ignoreCodes
=
new
Set
([
1000
,
// Normal (intended) closure
1001
// Going away
])
const
{
code
}
=
closeEvent
if
(
ignoreCodes
.
has
(
code
))
{
console
.
debug
(
`Not restarting socket becasue of closure code
${
code
}
is in ignore list`
)
}
else
{
console
.
warn
(
`MastoAPI websocket disconnected, restarting. CloseEvent code:
${
code
}
`
)
dispatch
(
'
startFetchingTimeline
'
,
{
timeline
:
'
friends
'
})
dispatch
(
'
startFetchingNotifications
'
)
dispatch
(
'
restartMastoUserSocket
'
)
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
const
{
state
,
dispatch
}
=
store
state
.
mastoUserSocket
=
state
.
backendInteractor
.
startUserSocket
({
store
})
state
.
mastoUserSocket
.
addEventListener
(
'
message
'
,
({
detail
:
message
})
=>
{
if
(
!
message
)
return
// pings
if
(
message
.
event
===
'
notification
'
)
{
dispatch
(
'
addNewNotifications
'
,
{
notifications
:
[
message
.
notification
],
older
:
false
})
}
else
if
(
message
.
event
===
'
update
'
)
{
dispatch
(
'
addNewStatuses
'
,
{
statuses
:
[
message
.
status
],
userId
:
false
,
showImmediately
:
false
,
timeline
:
'
friends
'
})
}
}
)
state
.
mastoUserSocket
.
addEventListener
(
'
error
'
,
({
detail
:
error
})
=>
{
console
.
error
(
'
Error in MastoAPI websocket:
'
,
error
)
})
state
.
mastoUserSocket
.
addEventListener
(
'
close
'
,
({
detail
:
closeEvent
})
=>
{
const
ignoreCodes
=
new
Set
([
1000
,
// Normal (intended) closure
1001
// Going away
])
const
{
code
}
=
closeEvent
if
(
ignoreCodes
.
has
(
code
))
{
console
.
debug
(
`Not restarting socket becasue of closure code
${
code
}
is in ignore list`
)
}
else
{
console
.
warn
(
`MastoAPI websocket disconnected, restarting. CloseEvent code:
${
code
}
`
)
dispatch
(
'
startFetchingTimeline
'
,
{
timeline
:
'
friends
'
})
dispatch
(
'
startFetchingNotifications
'
)
dispatch
(
'
restartMastoUserSocket
'
)
}
})
resolve
()
}
catch
(
e
)
{
reject
(
e
)
}
})
},
restartMastoUserSocket
({
dispatch
})
{
// This basically starts MastoAPI user socket and stops conventional
// fetchers when connection reestablished
dispatch
(
'
startMastoUserSocket
'
).
then
(()
=>
{
return
dispatch
(
'
startMastoUserSocket
'
).
then
(()
=>
{
dispatch
(
'
stopFetchingTimeline
'
,
{
timeline
:
'
friends
'
})
dispatch
(
'
stopFetchingNotifications
'
)
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment