call notification test
This commit is contained in:
parent
c3508e47b7
commit
0247eb118d
7 changed files with 37 additions and 13 deletions
|
@ -3,6 +3,7 @@ const User = use('App/Models/User');
|
|||
const UserChildUtils = use('App/Utils/UserChildUtils');
|
||||
const Call = use('App/Models/Call');
|
||||
const IceServer = use('App/Models/IceServer');
|
||||
const UserChannel = use('App/Controllers/Ws/UserChannelController')
|
||||
const calls = {};
|
||||
|
||||
class SignalingController {
|
||||
|
@ -14,11 +15,11 @@ class SignalingController {
|
|||
this.register(call);
|
||||
console.log(`User #${this.user.id} connected to call ${this.callId}`);
|
||||
}
|
||||
register(callModel) {
|
||||
if (!calls[this.callId])
|
||||
async register(callModel) {
|
||||
if (!calls[this.callId]) {
|
||||
calls[this.callId] =
|
||||
new CallSession(callModel, this.onCallEnded.bind(this));
|
||||
else
|
||||
} else
|
||||
console.log(`Call #${this.callId} Already Found`);
|
||||
const callSession = calls[this.callId];
|
||||
callSession.registerUser(this.user, this.socket)
|
||||
|
@ -85,15 +86,24 @@ class CallSession {
|
|||
else if (this.user_2.id === user.id)
|
||||
userIndex = 2;
|
||||
if (userIndex < 0) return false;
|
||||
const otherUser = userIndex === 1 ? 2 : 1;
|
||||
this[`user_${userIndex}`].userModel = user;
|
||||
this[`user_${userIndex}`].socket = socket;
|
||||
socket.on('wrtc:sdp:offer', this.onSdpOffer.bind(this));
|
||||
socket.on('wrtc:sdp:answer', this.onSdpAnswer.bind(this));
|
||||
socket.on('wrtc:ice', this.onIceCandidate.bind(this));
|
||||
await this.updateState();
|
||||
if (this.state === 'STARTED')
|
||||
if (this.state === 'STARTED') {
|
||||
await this.sendStandby(socket, userIndex);
|
||||
else if (this.state === 'IN_PROGRESS')
|
||||
// Send event to other user about the call
|
||||
const otherUserChannel =
|
||||
UserChannel.getUserChannel(this[`user_${otherUser}`].id);
|
||||
if (otherUserChannel)
|
||||
otherUserChannel.emit('call:incoming', {
|
||||
callId: this.callId,
|
||||
child: (await Child.find(this.callModel.child_id)).toJSON()
|
||||
});
|
||||
} else if (this.state === 'IN_PROGRESS')
|
||||
await this.sendStart(socket, userIndex);
|
||||
return true;
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -80,6 +80,10 @@ export default {
|
|||
this.ws.on(WebsocketService.Events.CONNECTION_OFFLINE, user => {
|
||||
this.notify({ message: `${user.name} disconnected`, level: "warning" });
|
||||
});
|
||||
this.ws.on(
|
||||
WebsocketService.Events.INCOMING_CALL,
|
||||
this.onIncomingCall.bind(this)
|
||||
);
|
||||
this.loading = false;
|
||||
return true;
|
||||
},
|
||||
|
@ -95,6 +99,13 @@ export default {
|
|||
...mapGetters(["notifications"])
|
||||
},
|
||||
methods: {
|
||||
onIncomingCall(payload: { callId: number; child: any }) {
|
||||
this.notify({
|
||||
message: `New call from ${payload.child.name}`,
|
||||
level: "success"
|
||||
});
|
||||
this.$router.push({ path: `/call/${payload.callId}` });
|
||||
},
|
||||
onNotificationClose(notification) {
|
||||
this.dismissNotification(notification.id);
|
||||
},
|
||||
|
|
|
@ -18,6 +18,7 @@ export default class WebSocketService {
|
|||
this.userChannelService.on('new:connection', this.onUserNewConnection.bind(this));
|
||||
this.userChannelService.on('connection:online', this.onUserConnectionOnline.bind(this));
|
||||
this.userChannelService.on('connection:offline', this.onUserConnectionOffline.bind(this));
|
||||
this.userChannelService.on('call:incoming', this.onIncomingCall.bind(this));
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,7 +33,9 @@ export default class WebSocketService {
|
|||
console.log(subscription);
|
||||
return subscription;
|
||||
}
|
||||
|
||||
private onIncomingCall(data) {
|
||||
this.emitter.emit(EEvents.INCOMING_CALL, data);
|
||||
}
|
||||
private onUserNewConnection(data) {
|
||||
this.emitter.emit(EEvents.NEW_CONNECTION, data);
|
||||
}
|
||||
|
|
Reference in a new issue