Skip to content
Snippets Groups Projects
Commit 4bef26e6 authored by Léopold Chappuis's avatar Léopold Chappuis
Browse files

presence: add signals and API functions

Change-Id: I7e43234ebf1ebe3f831e6b886f333b8a53e5c3a2
parent 7618e648
Branches
No related tags found
No related merge requests found
...@@ -231,3 +231,33 @@ export interface MessageFound { ...@@ -231,3 +231,33 @@ export interface MessageFound {
conversationId: string conversationId: string
messages: Message[] messages: Message[]
} }
export interface ISubscriptionStateChanged {
accountId: string
buddyUri: string
state: number
}
export interface INearbyPeerNotification {
accountId: string
buddyUri: string
state: number
displayName: string
}
export interface INewBuddyNotification {
accountId: string
buddyUri: string
status: number
lineStatus: string
}
export interface INewServerSubscriptionRequest {
remote: string
}
export interface IServerError {
accountId: string
error: string
msg: string
}
...@@ -67,4 +67,11 @@ export enum JamiSignal { ...@@ -67,4 +67,11 @@ export enum JamiSignal {
// libjami::DataTransferSignal // libjami::DataTransferSignal
DataTransferEvent = 'DataTransferEvent', DataTransferEvent = 'DataTransferEvent',
// libjami::PresenceSignal
SubscriptionStateChanged = 'SubscriptionStateChanged',
NearbyPeerNotification = 'NearbyPeerNotification',
NewBuddyNotification = 'NewBuddyNotification',
NewServerSubscriptionRequest = 'NewServerSubscriptionRequest',
ServerError = 'ServerError',
} }
...@@ -172,6 +172,13 @@ export interface JamiSwig { ...@@ -172,6 +172,13 @@ export interface JamiSwig {
progress_out: number, progress_out: number,
): DataTransferError ): DataTransferError
// Presence
publish(accountId: string, status: boolean, note: string): void
answerServerRequest(uri: string, flag: boolean): void
subscribeBuddy(accountId: string, uri: string, flag: boolean): void
getSubscriptions(accountId: string): VectMap
setSubscriptions(accountId: string, uris: string[]): void
// IntVect: Constructable<IntVect>; // IntVect: Constructable<IntVect>;
// UintVect: Constructable<UintVect>; // UintVect: Constructable<UintVect>;
// FloatVect: Constructable<FloatVect>; // FloatVect: Constructable<FloatVect>;
......
...@@ -65,6 +65,11 @@ import { ...@@ -65,6 +65,11 @@ import {
DataTransferEvent, DataTransferEvent,
DeviceRevocationEnded, DeviceRevocationEnded,
IncomingAccountMessage, IncomingAccountMessage,
INearbyPeerNotification,
INewBuddyNotification,
INewServerSubscriptionRequest,
IServerError,
ISubscriptionStateChanged,
KnownDevicesChanged, KnownDevicesChanged,
MessageFound, MessageFound,
NameRegistrationEnded, NameRegistrationEnded,
...@@ -284,6 +289,25 @@ export class Jamid { ...@@ -284,6 +289,25 @@ export class Jamid {
handlers.DeviceRevocationEnded = (accountId: string, device: string, state: DeviceRevocationState) => handlers.DeviceRevocationEnded = (accountId: string, device: string, state: DeviceRevocationState) =>
onDeviceRevocationEnded.next({ accountId, device, state }) onDeviceRevocationEnded.next({ accountId, device, state })
const onSubscriptionStateChanged = new Subject<ISubscriptionStateChanged>()
handlers.SubscriptionStateChanged = (accountId: string, buddyUri: string, state: number) =>
onSubscriptionStateChanged.next({ accountId, buddyUri, state })
const onNearbyPeerNotification = new Subject<INearbyPeerNotification>()
handlers.NearbyPeerNotification = (accountId: string, buddyUri: string, state: number, displayName: string) =>
onNearbyPeerNotification.next({ accountId, buddyUri, state, displayName })
const onNewBuddyNotification = new Subject<INewBuddyNotification>()
handlers.NewBuddyNotification = (accountId: string, buddyUri: string, status: number, lineStatus: string) =>
onNewBuddyNotification.next({ accountId, buddyUri, status, lineStatus })
const onNewServerSubscriptionRequest = new Subject<INewServerSubscriptionRequest>()
handlers.NewServerSubscriptionRequest = (remote: string) => onNewServerSubscriptionRequest.next({ remote })
const onServerError = new Subject<IServerError>()
handlers.ServerError = (accountId: string, error: string, msg: string) =>
onServerError.next({ accountId, error, msg })
// Expose all signals in an events object to allow other handlers to subscribe after jamiSwig.init() // Expose all signals in an events object to allow other handlers to subscribe after jamiSwig.init()
this.events = { this.events = {
onAccountsChanged: onAccountsChanged.asObservable(), onAccountsChanged: onAccountsChanged.asObservable(),
...@@ -315,6 +339,11 @@ export class Jamid { ...@@ -315,6 +339,11 @@ export class Jamid {
onUserSearchEnded: onUserSearchEnded.asObservable(), onUserSearchEnded: onUserSearchEnded.asObservable(),
onDeviceRevocationEnded: onDeviceRevocationEnded.asObservable(), onDeviceRevocationEnded: onDeviceRevocationEnded.asObservable(),
onMessageFound: onMessageFound.asObservable(), onMessageFound: onMessageFound.asObservable(),
onSubscriptionStateChanged: onSubscriptionStateChanged.asObservable(),
onNearbyPeerNotification: onNearbyPeerNotification.asObservable(),
onNewBuddyNotification: onNewBuddyNotification.asObservable(),
onNewServerSubscriptionRequest: onNewServerSubscriptionRequest.asObservable(),
onServerError: onServerError.asObservable(),
} }
this.setupSignalHandlers() this.setupSignalHandlers()
...@@ -735,7 +764,47 @@ export class Jamid { ...@@ -735,7 +764,47 @@ export class Jamid {
) )
} }
publish(accountId: string, status: boolean, note: string): void {
this.jamiSwig.publish(accountId, status, note)
}
answerServerRequest(uri: string, flag: boolean) {
this.jamiSwig.answerServerRequest(uri, flag)
}
subscribeBuddy(accountId: string, uri: string, flag: boolean): void {
this.jamiSwig.subscribeBuddy(accountId, uri, flag)
}
getSubscriptions(accountId: string) {
return vectMapToRecordArray(this.jamiSwig.getSubscriptions(accountId))
}
setSubscriptions(accountId: string, uris: string[]): void {
this.jamiSwig.setSubscriptions(accountId, uris)
}
private setupSignalHandlers(): void { private setupSignalHandlers(): void {
this.events.onSubscriptionStateChanged.subscribe((signal) => {
log.debug('Received SubscriptionStateChanged:', JSON.stringify(signal))
})
this.events.onNearbyPeerNotification.subscribe((signal) => {
log.debug('Received NearbyPeerNotification:', JSON.stringify(signal))
})
this.events.onNewBuddyNotification.subscribe((signal) => {
log.debug('Received NewBuddyNotification:', JSON.stringify(signal))
})
this.events.onNewServerSubscriptionRequest.subscribe((signal) => {
log.debug('Received NewServerSubscriptionRequest:', JSON.stringify(signal))
})
this.events.onServerError.subscribe((signal) => {
log.debug('Received ServerError:', JSON.stringify(signal))
})
this.events.onDataTransferEvent.subscribe((signal) => { this.events.onDataTransferEvent.subscribe((signal) => {
log.debug('Received DataTransferEvent:', JSON.stringify(signal)) log.debug('Received DataTransferEvent:', JSON.stringify(signal))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment