mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +02:00
46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
JavaScript
module.exports = function GroupServiceFactory(
|
|
socket
|
|
, TransactionService
|
|
) {
|
|
var groupService = {
|
|
}
|
|
|
|
groupService.invite = function (device) {
|
|
var tx = TransactionService.create(device)
|
|
socket.emit('group.invite', device.channel, tx.channel, {
|
|
requirements: {
|
|
serial: {
|
|
value: device.serial
|
|
, match: 'exact'
|
|
}
|
|
}
|
|
})
|
|
return tx.promise.then(function(result) {
|
|
if (!result.success) {
|
|
throw new Error('Device refused to join the group')
|
|
}
|
|
return result.device
|
|
})
|
|
}
|
|
|
|
groupService.kick = function (device) {
|
|
var tx = TransactionService.create(device)
|
|
socket.emit('group.kick', device.channel, tx.channel, {
|
|
requirements: {
|
|
serial: {
|
|
value: device.serial
|
|
, match: 'exact'
|
|
}
|
|
}
|
|
})
|
|
return tx.promise.then(function(result) {
|
|
if (!result.success) {
|
|
throw new Error('Device refused to be kicked from the group')
|
|
}
|
|
return result.device
|
|
})
|
|
}
|
|
|
|
return groupService
|
|
}
|