Merge pull request #2872 from nextcloud/axios

rm -rf jquery/
This commit is contained in:
marco 2020-01-31 15:07:16 +01:00 коммит произвёл GitHub
Родитель 8433778222 55d81965c8
Коммит 9afba6e995
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 72 добавлений и 113 удалений

Просмотреть файл

@ -32,6 +32,8 @@
import { fetchSignalingSettings } from '../services/signalingService' import { fetchSignalingSettings } from '../services/signalingService'
import { EventBus } from '../services/EventBus' import { EventBus } from '../services/EventBus'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
const Signaling = { const Signaling = {
Base: {}, Base: {},
@ -191,16 +193,10 @@ Signaling.Base.prototype.leaveCurrentCall = function() {
Signaling.Base.prototype.joinRoom = function(token, password) { Signaling.Base.prototype.joinRoom = function(token, password) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
$.ajax({ axios.post(generateOcsUrl('apps/spreed/api/v1/room', 2) + token + '/participants/active', {
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + token + '/participants/active', password: password,
type: 'POST', })
beforeSend: function(request) { .then(function(result) {
request.setRequestHeader('Accept', 'application/json')
},
data: {
password: password,
},
success: function(result) {
console.log('Joined', result) console.log('Joined', result)
this.currentRoomToken = token this.currentRoomToken = token
this._trigger('joinRoom', [token]) this._trigger('joinRoom', [token])
@ -213,8 +209,8 @@ Signaling.Base.prototype.joinRoom = function(token, password) {
this.currentCallFlags = null this.currentCallFlags = null
} }
this._joinRoomSuccess(token, result.ocs.data.sessionId) this._joinRoomSuccess(token, result.ocs.data.sessionId)
}.bind(this), }.bind(this))
error: function(result) { .catch(function(result) {
reject(result) reject(result)
if (result.status === 403) { if (result.status === 403) {
@ -240,8 +236,7 @@ Signaling.Base.prototype.joinRoom = function(token, password) {
$buttons.eq(1).text(t('core', 'Submit')) $buttons.eq(1).text(t('core', 'Submit'))
}) })
} }
}.bind(this), }.bind(this))
})
}) })
} }
@ -256,22 +251,18 @@ Signaling.Base.prototype.leaveRoom = function(token) {
this._doLeaveRoom(token) this._doLeaveRoom(token)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
$.ajax({ axios.delete(generateOcsUrl('apps/spreed/api/v1/room', 2) + token + '/participants/active')
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + token + '/participants/active', .then(function() {
method: 'DELETE',
async: false,
success: function() {
this._leaveRoomSuccess(token) this._leaveRoomSuccess(token)
resolve() resolve()
// We left the current room. // We left the current room.
if (token === this.currentRoomToken) { if (token === this.currentRoomToken) {
this.currentRoomToken = null this.currentRoomToken = null
} }
}.bind(this), }.bind(this))
error: function() { .catch(function() {
reject(new Error()) reject(new Error())
}, })
})
}) })
} }
@ -289,28 +280,21 @@ Signaling.Base.prototype._joinCallSuccess = function(/* token */) {
Signaling.Base.prototype.joinCall = function(token, flags) { Signaling.Base.prototype.joinCall = function(token, flags) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
$.ajax({ axios.post(generateOcsUrl('apps/spreed/api/v1/call', 2) + token, {
url: OC.linkToOCS('apps/spreed/api/v1/call', 2) + token, flags: flags,
type: 'POST', })
data: { .then(function() {
flags: flags,
},
beforeSend: function(request) {
request.setRequestHeader('Accept', 'application/json')
},
success: function() {
this.currentCallToken = token this.currentCallToken = token
this.currentCallFlags = flags this.currentCallFlags = flags
this._trigger('joinCall', [token]) this._trigger('joinCall', [token])
resolve() resolve()
this._joinCallSuccess(token) this._joinCallSuccess(token)
}.bind(this), }.bind(this))
error: function() { .catch(function() {
reject(new Error()) reject(new Error())
// Room not found or maintenance mode // Room not found or maintenance mode
OC.redirect(OC.generateUrl('apps/spreed')) OC.redirect(OC.generateUrl('apps/spreed'))
}, })
})
}) })
} }
@ -325,11 +309,8 @@ Signaling.Base.prototype.leaveCall = function(token, keepToken) {
return return
} }
$.ajax({ axios.delete(generateOcsUrl('apps/spreed/api/v1/call', 2) + token)
url: OC.linkToOCS('apps/spreed/api/v1/call', 2) + token, .then(function() {
method: 'DELETE',
async: false,
success: function() {
this._trigger('leaveCall', [token, keepToken]) this._trigger('leaveCall', [token, keepToken])
this._leaveCallSuccess(token) this._leaveCallSuccess(token)
resolve() resolve()
@ -338,11 +319,10 @@ Signaling.Base.prototype.leaveCall = function(token, keepToken) {
this.currentCallToken = null this.currentCallToken = null
this.currentCallFlags = null this.currentCallFlags = null
} }
}.bind(this), }.bind(this))
error: function() { .catch(function() {
reject(new Error()) reject(new Error())
}, })
})
}) })
} }
@ -415,22 +395,9 @@ Signaling.Internal.prototype._sendMessageWithCallback = function(ev) {
} }
Signaling.Internal.prototype._sendMessages = function(messages) { Signaling.Internal.prototype._sendMessages = function(messages) {
const defer = $.Deferred() return axios.post(generateOcsUrl('apps/spreed/api/v1/signaling', 2) + this.currentRoomToken, {
$.ajax({ messages: JSON.stringify(messages),
url: OC.linkToOCS('apps/spreed/api/v1/signaling', 2) + this.currentRoomToken,
type: 'POST',
data: { messages: JSON.stringify(messages) },
beforeSend: function(request) {
request.setRequestHeader('Accept', 'application/json')
},
success: function(result) {
defer.resolve(result)
},
error: function(xhr, textStatus, errorThrown) {
defer.reject(xhr, textStatus, errorThrown)
},
}) })
return defer
} }
Signaling.Internal.prototype._joinRoomSuccess = function(token, sessionId) { Signaling.Internal.prototype._joinRoomSuccess = function(token, sessionId) {
@ -468,60 +435,52 @@ Signaling.Internal.prototype._startPullingMessages = function() {
} }
// Connect to the messages endpoint and pull for new messages // Connect to the messages endpoint and pull for new messages
this.pullMessagesRequest this.pullMessagesRequest = axios.get(generateOcsUrl('apps/spreed/api/v1/signaling', 2) + this.currentRoomToken)
= $.ajax({ .then(function(result) {
url: OC.linkToOCS('apps/spreed/api/v1/signaling', 2) + this.currentRoomToken, this.pullMessagesFails = 0
type: 'GET', $.each(result.ocs.data, function(id, message) {
dataType: 'json', this._trigger('onBeforeReceiveMessage', [message])
beforeSend: function(request) { switch (message.type) {
request.setRequestHeader('Accept', 'application/json') case 'usersInRoom':
}, this._trigger('usersInRoom', [message.data])
success: function(result) { this._trigger('participantListChanged')
this.pullMessagesFails = 0 break
$.each(result.ocs.data, function(id, message) { case 'message':
this._trigger('onBeforeReceiveMessage', [message]) if (typeof (message.data) === 'string') {
switch (message.type) { message.data = JSON.parse(message.data)
case 'usersInRoom':
this._trigger('usersInRoom', [message.data])
this._trigger('participantListChanged')
break
case 'message':
if (typeof (message.data) === 'string') {
message.data = JSON.parse(message.data)
}
this._trigger('message', [message.data])
break
default:
console.log('Unknown Signaling Message')
break
} }
this._trigger('onAfterReceiveMessage', [message]) this._trigger('message', [message.data])
}.bind(this)) break
this._startPullingMessages() default:
}.bind(this), console.log('Unknown Signaling Message')
error: function(jqXHR, textStatus/*, errorThrown */) { break
if (jqXHR.status === 0 && textStatus === 'abort') {
// Request has been aborted. Ignore.
} else if (jqXHR.status === 404 || jqXHR.status === 403) {
console.log('Stop pulling messages because room does not exist or is not accessible')
this._trigger('pullMessagesStoppedOnFail')
} else if (this.currentRoomToken) {
if (this.pullMessagesFails >= 3) {
console.log('Stop pulling messages after repeated failures')
this._trigger('pullMessagesStoppedOnFail')
return
}
this.pullMessagesFails++
// Retry to pull messages after 5 seconds
window.setTimeout(function() {
this._startPullingMessages()
}.bind(this), 5000)
} }
}.bind(this), this._trigger('onAfterReceiveMessage', [message])
}) }.bind(this))
this._startPullingMessages()
}.bind(this))
.catch(function(jqXHR, textStatus/*, errorThrown */) {
if (jqXHR.status === 0 && textStatus === 'abort') {
// Request has been aborted. Ignore.
} else if (jqXHR.status === 404 || jqXHR.status === 403) {
console.log('Stop pulling messages because room does not exist or is not accessible')
this._trigger('pullMessagesStoppedOnFail')
} else if (this.currentRoomToken) {
if (this.pullMessagesFails >= 3) {
console.log('Stop pulling messages after repeated failures')
this._trigger('pullMessagesStoppedOnFail')
return
}
this.pullMessagesFails++
// Retry to pull messages after 5 seconds
window.setTimeout(function() {
this._startPullingMessages()
}.bind(this), 5000)
}
}.bind(this))
} }
/** /**