@@ -6,15 +6,15 @@ var Room = Matrix.Room;
66var USER_PREFIX = "fs_" ;
77var DOMAIN = "matrix.org" ;
88
9- function ConferenceHandler ( matrixClient , groupChatRoomId ) {
9+ function ConferenceCall ( matrixClient , groupChatRoomId ) {
1010 this . client = matrixClient ;
1111 this . groupRoomId = groupChatRoomId ;
1212 // abuse browserify's core node Buffer support (strip padding ='s)
13- this . base64RoomId = new Buffer ( this . groupRoomId ) . toString ( "base64" ) . replace ( / = / g, "" ) ;
14- this . confUserId = "@" + USER_PREFIX + this . base64RoomId + ":" + DOMAIN ;
13+ var base64RoomId = new Buffer ( groupChatRoomId ) . toString ( "base64" ) . replace ( / = / g, "" ) ;
14+ this . confUserId = "@" + USER_PREFIX + base64RoomId + ":" + DOMAIN ;
1515}
1616
17- ConferenceHandler . prototype . setup = function ( ) {
17+ ConferenceCall . prototype . setup = function ( ) {
1818 var self = this ;
1919 return this . _joinConferenceUser ( ) . then ( function ( ) {
2020 return self . _getConferenceUserRoom ( ) ;
@@ -24,7 +24,7 @@ ConferenceHandler.prototype.setup = function() {
2424 } ) ;
2525} ;
2626
27- ConferenceHandler . prototype . _joinConferenceUser = function ( ) {
27+ ConferenceCall . prototype . _joinConferenceUser = function ( ) {
2828 // Make sure the conference user is in the group chat room
2929 var groupRoom = this . client . getRoom ( this . groupRoomId ) ;
3030 if ( ! groupRoom ) {
@@ -37,7 +37,7 @@ ConferenceHandler.prototype._joinConferenceUser = function() {
3737 return this . client . invite ( this . groupRoomId , this . confUserId ) ;
3838} ;
3939
40- ConferenceHandler . prototype . _getConferenceUserRoom = function ( ) {
40+ ConferenceCall . prototype . _getConferenceUserRoom = function ( ) {
4141 // Use an existing 1:1 with the conference user; else make one
4242 var rooms = this . client . getRooms ( ) ;
4343 var confRoom = null ;
@@ -60,5 +60,23 @@ ConferenceHandler.prototype._getConferenceUserRoom = function() {
6060 } ) ;
6161} ;
6262
63- module . exports = ConferenceHandler ;
63+ /**
64+ * Check if this room member is in fact a conference bot.
65+ * @param {RoomMember } The room member to check
66+ * @return {boolean } True if it is a conference bot.
67+ */
68+ module . exports . isConferenceUser = function ( roomMember ) {
69+ if ( roomMember . userId . indexOf ( "@" + USER_PREFIX ) !== 0 ) {
70+ return false ;
71+ }
72+ var base64part = roomMember . userId . split ( ":" ) [ 0 ] . substring ( 1 + USER_PREFIX . length ) ;
73+ if ( base64part ) {
74+ var decoded = new Buffer ( base64part , "base64" ) . toString ( ) ;
75+ // ! $STUFF : $STUFF
76+ return / ^ ! .+ : .+ / . test ( decoded ) ;
77+ }
78+ return false ;
79+ } ;
80+
81+ module . exports . ConferenceCall = ConferenceCall ;
6482
0 commit comments