@@ -20,6 +20,60 @@ subscription.onObjects = (objectsEvent) => { console.log("Objects event: ", obje
20
20
subscription . onMessageAction = ( messageActionEvent ) => { console . log ( "Message Reaction event: " , messageActionEvent ) ; } ;
21
21
subscription . onFile = ( fileEvent ) => { console . log ( "File event: " , fileEvent ) ; } ;
22
22
23
+ // Generic listeners
24
+ subscription . addListener ( {
25
+ // Messages
26
+ message : function ( m ) {
27
+ const channelName = m . channel ; // Channel on which the message was published
28
+ const channelGroup = m . subscription ; // Channel group or wildcard subscription match (if exists)
29
+ const pubTT = m . timetoken ; // Publish timetoken
30
+ const msg = m . message ; // Message payload
31
+ const publisher = m . publisher ; // Message publisher
32
+ } ,
33
+ // Presence
34
+ // requires a subscription with presence
35
+ presence : function ( p ) {
36
+ const action = p . action ; // Can be join, leave, timeout, state-change, or interval
37
+ const channelName = p . channel ; // Channel to which the message belongs
38
+ const channelGroup = p . subscription ; // Channel group or wildcard subscription match, if any
39
+ const publishTime = p . timestamp ; // Publish timetoken
40
+ const timetoken = p . timetoken ; // Current timetoken
41
+ } ,
42
+ // Signals
43
+ signal : function ( s ) {
44
+ const channelName = s . channel ; // Channel to which the signal belongs
45
+ const channelGroup = s . subscription ; // Channel group or wildcard subscription match, if any
46
+ const pubTT = s . timetoken ; // Publish timetoken
47
+ const msg = s . message ; // Payload
48
+ const publisher = s . publisher ; // Message publisher
49
+ } ,
50
+ // App Context
51
+ objects : ( objectEvent ) => {
52
+ const channel = objectEvent . channel ; // Channel to which the event belongs
53
+ const channelGroup = objectEvent . subscription ; // Channel group
54
+ const timetoken = objectEvent . timetoken ; // Event timetoken
55
+ const event = objectEvent . message . data . type ; // Event name
56
+ } ,
57
+ // Message Actions
58
+ messageAction : function ( ma ) {
59
+ const channelName = ma . channel ; // Channel to which the message belongs
60
+ const publisher = ma . data . uuid ; // Message publisher
61
+ const event = ma . event ; // Message action added or removed
62
+ const type = ma . data . type ; // Message action type
63
+ const value = ma . data . value ; // Message action value
64
+ const messageTimetoken = ma . data . messageTimetoken ; // Timetoken of the original message
65
+ const actionTimetoken = ma . data . actionTimetoken ; // Timetoken of the message action
66
+ } ,
67
+ // File Sharing
68
+ file : function ( event ) {
69
+ const channelName = event . channel ; // Channel to which the file belongs
70
+ const channelGroup = event . subscription ; // Channel group or wildcard subscription match (if exists)
71
+ const publisher = event . publisher ; // File publisher
72
+ const timetoken = event . timetoken ; // Event timetoken
73
+ const message = event . message ; // Optional message attached to the file
74
+ }
75
+ } ) ;
76
+
23
77
// snippet.end
24
78
25
79
// snippet.AddConnectionStatusListener
0 commit comments