2 * @file Messaging module providing capability for files to communicate with each other
3 * @author Jordan Lavatai and Ken Grimes
9 /** Remote Peer States:
13 /* SPC default object */
14 class StrappPeerConnection
extends File
{
29 strappPeerConnection
.defaults
= Object
.assign({}, File
.defaults
, {
32 messageHandler
: new Map(), /* TODO: seperate handling? */
34 bestConnectionType
: '',
36 peerID
: '' /* clientID of Peer* /
40 /* GET - gets the data (queued messages) from a spc */
41 /* POST - sends a msg through a spc to the remote peer */
42 /* CONNECT - Tries to establish a connection with an spc */
43 /* local or remote peer of the spc? */
44 /* Local is part of uri, make it remote*/
47 /* Convert entire file system into json objects that can be read into memory */
52 /* Reconnect WebRTC */
54 /* Determine remote peers bestConnectionType */
55 /* Restablish connection */
58 /** @func Send a message to the remote peer
61 * @arg {Object} message - message in LMKID format, except no message ID yet
62 * @this {Object} - Refers to the SPC that is calling send
63 * @return {Object} - Promise for the response from the send message
65 function send(message
) {
66 /* Determine if 'this' is a SPC object */
69 /* 'send data' means to create a strapp protocol message and send it over whichever
70 transmission channel is available */
74 if (this.establishConnection(clientKey
, data
)) {
78 storeMessage(this, message
)
83 this.reestablishConnection(clientKey
, data
)
84 /* Store the message */
85 /* Fail if reconnection attempt fails */
88 /* does remote peer have the ability to upgrade? */
89 /* If so, attempt to upgrade */
90 /* If upgrade fails, retry the send method else send via polling */
94 /* does remote peer have the ability to upgrade? */
95 /* If so, attempt to upgrade */
96 /* If upgrade fails, retry the send method else send via polling */
100 /* If remote peer is connected, send data */
101 /* Else Attemp to fix connection, if connection is dead, set this.state and try this again. Will
102 Enter the 'disconnected' state */
111 /** @func Attempts to connect the local peer to the remote peer
114 * @ret {boolean} True if successful, false if not
116 function establishSPC() {
120 /** @func Attempts to reconnect the local peer to the remote peer
121 * @desc This function assumes that the remotePeer property for the SPC object has
122 * been elevated to a status higher than uninitialized.
124 * @ret {boolean} True if successful, false if not
126 function reestablishSPC() {
127 /* If successful, send all the cached messages that were saved when connection was down */
131 /** @func Stores the message
135 function storeMessage() {
138 /** @func Determines the multimedia signaling protocol for the given session description
139 * @desc Does some basic duck typing to determine the type of Session Description
140 * @arg {Object} Session Description Object
141 * @return {String} Returns 'planB' if Session Description is planB, 'Unified' if
142 * Session Description is Unified
144 function determineSessionDescription(sessionDescription
) {
147 /** @func Converts a planB session description to Unified session description
148 * @arg {Object} Session Description Object
149 * @return {Object} PlanB Session Description
151 function toUnified(sessionDescription
) {
154 /** @func Converts a Unified session description to planB session description
155 * @arg {Object} Session Description Object
156 * @return {Object} PlanB Session Description
158 function toPlanB(sessionDescription
) {